コード例 #1
0
        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);
        }