internal int ComputeCurrentParameter(ITextSnapshot snapshot, AstRoot ast, int position) { ParameterInfo parameterInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, snapshot, position); int index = 0; if (parameterInfo != null) { index = parameterInfo.ParameterIndex; if (parameterInfo.NamedParameter) { // A function f <- function(foo, bar) is said to have formal parameters "foo" and "bar", // and the call f(foo=3, ba=13) is said to have (actual) arguments "foo" and "ba". // R first matches all arguments that have exactly the same name as a formal parameter. // Two identical argument names cause an error. Then, R matches any argument names that // partially matches a(yet unmatched) formal parameter. But if two argument names partially // match the same formal parameter, that also causes an error. Also, it only matches // formal parameters before ... So formal parameters after ... must be specified using // their full names. Then the unnamed arguments are matched in positional order to // the remaining formal arguments. int argumentIndexInSignature = _signatureInfo.GetArgumentIndex(parameterInfo.ParameterName, REditorSettings.PartialArgumentNameMatch); if (argumentIndexInSignature >= 0) { index = argumentIndexInSignature; } } } return(index); }
/// <summary> /// Determines if current caret position is in the same function /// argument list as before or is it a different one and signature /// help session should be dismissed and re-triggered. This is helpful /// when user types nested function calls such as 'a(b(c(...), d(...)))' /// </summary> public static bool IsSameSignatureContext(ITextView textView, ITextBuffer subjectBuffer) { ISignatureHelpBroker signatureBroker = EditorShell.Current.ExportProvider.GetExportedValue <ISignatureHelpBroker>(); var sessions = signatureBroker.GetSessions(textView); Debug.Assert(sessions.Count < 2); if (sessions.Count == 1) { IFunctionInfo sessionFunctionInfo = null; sessions[0].Properties.TryGetProperty <IFunctionInfo>("functionInfo", out sessionFunctionInfo); if (sessionFunctionInfo != null) { try { IREditorDocument document = REditorDocument.FromTextBuffer(textView.TextBuffer); document.EditorTree.EnsureTreeReady(); ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer( document.EditorTree.AstRoot, subjectBuffer.CurrentSnapshot, textView.Caret.Position.BufferPosition); return(parametersInfo != null && parametersInfo.FunctionName == sessionFunctionInfo.Name); } catch (Exception) { } } } return(false); }
public bool AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures, AstRoot ast, Action <object> triggerSession) { ITextSnapshot snapshot = _textBuffer.CurrentSnapshot; int position = session.GetTriggerPoint(_textBuffer).GetPosition(snapshot); // Retrieve parameter positions from the current text buffer snapshot ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, snapshot, position); if (parametersInfo != null) { position = Math.Min(parametersInfo.SignatureEnd, position); int start = Math.Min(position, snapshot.Length); int end = Math.Min(parametersInfo.SignatureEnd, snapshot.Length); ITrackingSpan applicableToSpan = snapshot.CreateTrackingSpan(Span.FromBounds(start, end), SpanTrackingMode.EdgeInclusive); // Get collection of function signatures from documentation (parsed RD file) IFunctionInfo functionInfo = FunctionIndex.GetFunctionInfo(parametersInfo.FunctionName, triggerSession, session.TextView); if (functionInfo != null && functionInfo.Signatures != null) { foreach (ISignatureInfo signatureInfo in functionInfo.Signatures) { ISignature signature = CreateSignature(session, functionInfo, signatureInfo, applicableToSpan, ast, position); signatures.Add(signature); } session.Properties["functionInfo"] = functionInfo; return(true); } } return(false); }
public bool AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures, AstRoot ast, Action <object, string> triggerSession, string packageName) { ITextSnapshot snapshot = _textBuffer.CurrentSnapshot; int position = session.GetTriggerPoint(_textBuffer).GetPosition(snapshot); // Retrieve parameter positions from the current text buffer snapshot ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(ast, snapshot, position); if (parametersInfo != null) { position = Math.Min(parametersInfo.SignatureEnd, position); int start = Math.Min(position, snapshot.Length); int end = Math.Min(parametersInfo.SignatureEnd, snapshot.Length); ITrackingSpan applicableToSpan = snapshot.CreateTrackingSpan(Span.FromBounds(start, end), SpanTrackingMode.EdgeInclusive); IFunctionInfo functionInfo = null; // First try user-defined function if (string.IsNullOrEmpty(parametersInfo.PackageName)) { functionInfo = ast.GetUserFunctionInfo(parametersInfo.FunctionName, position); } else { packageName = parametersInfo.PackageName; } if (functionInfo == null) { var functionIndex = _shell.ExportProvider.GetExportedValue <IFunctionIndex>(); // Then try package functions packageName = packageName ?? _packageName; _packageName = null; // Get collection of function signatures from documentation (parsed RD file) functionInfo = functionIndex.GetFunctionInfo(parametersInfo.FunctionName, packageName, triggerSession, session); } if (functionInfo != null && functionInfo.Signatures != null) { foreach (ISignatureInfo signatureInfo in functionInfo.Signatures) { ISignature signature = CreateSignature(session, parametersInfo.FunctionName, functionInfo, signatureInfo, applicableToSpan, ast, position); signatures.Add(signature); } session.Properties["functionInfo"] = functionInfo; return(true); } } return(false); }