Пример #1
0
        private IFunctionInfo TryGetCachedFunctionInfo(string functionName)
        {
            IFunctionInfo functionInfo = null;

            _functionToInfoMap?.TryGetValue(functionName, out functionInfo);
            return(functionInfo);
        }
Пример #2
0
        private IEnumerable <IRFunctionSignatureHelp> GetSignaturesAsync(RFunctionSignatureInfo signatureInfo, IRIntellisenseContext context, Action <IEnumerable <IRFunctionSignatureHelp> > callback)
        {
            var snapshot = context.EditorBuffer.CurrentSnapshot;
            var position = Math.Min(Math.Min(signatureInfo.FunctionCall.SignatureEnd, context.Position), snapshot.Length);

            var           applicableToSpan = GetApplicableSpan(signatureInfo, context);
            IFunctionInfo functionInfo     = null;
            string        packageName      = null;

            // First try user-defined function
            if (string.IsNullOrEmpty(signatureInfo.PackageName))
            {
                functionInfo = context.AstRoot.GetUserFunctionInfo(signatureInfo.FunctionName, position);
            }
            else
            {
                packageName = signatureInfo.PackageName;
            }

            if (functionInfo != null)
            {
                return(MakeSignatures(functionInfo, applicableToSpan, context));
            }

            if (callback != null)
            {
                // Get collection of function signatures from documentation (parsed RD file)
                _functionIndex.GetFunctionInfoAsync(signatureInfo.FunctionName, packageName, (fi, o) => {
                    InvokeSignaturesCallback(fi, applicableToSpan, context, callback);
                });
            }
            return(null);
        }
Пример #3
0
        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);
        }
Пример #4
0
        private static string GenerateRoxygenBlock(string functionName, IFunctionDefinition fd, string lineBreak)
        {
            var sb = new StringBuilder();

            IFunctionInfo fi = fd.MakeFunctionInfo(functionName);

            if (fi != null && fi.Signatures.Count > 0)
            {
                sb.Append(Invariant($"#' Title{lineBreak}"));
                sb.Append(Invariant($"#'{lineBreak}"));

                int length = sb.Length;
                foreach (var p in fi.Signatures[0].Arguments)
                {
                    if (!string.IsNullOrEmpty(p.Name))
                    {
                        sb.Append(Invariant($"#' @param {p.Name}{lineBreak}"));
                    }
                }

                if (sb.Length > length)
                {
                    sb.Append(Invariant($"#'{lineBreak}"));
                }

                sb.Append(Invariant($"#' @return{lineBreak}"));
                sb.Append(Invariant($"#' @export{lineBreak}"));
                sb.Append(Invariant($"#'{lineBreak}"));
                sb.Append("#' @examples");
            }

            return(sb.ToString());
        }
Пример #5
0
        /// <summary>
        /// Performs the search on an IFunctionInfo object and combines the results using logical AND.
        /// </summary>
        /// <param name="functionInfo">Object to perform the search on.</param>
        /// <param name="terms">Array of terms to search for.</param>
        /// <param name="target">Property of the object to search.</param>
        /// <returns>True if there is a match, false otherwise.</returns>
        public bool IsAndMatch(IFunctionInfo functionInfo, string[] terms, CalculatorFilterTarget target)
        {
            var overallMatch = true;
            var isMatch      = false;

            for (var i = 0; i < terms.Length && overallMatch; i++)
            {
                if (!isMatch && (target == CalculatorFilterTarget.All || target == CalculatorFilterTarget.Name))
                {
                    isMatch = this.Compare(functionInfo.Name, terms[i]);
                }

                if (!isMatch && (target == CalculatorFilterTarget.All || target == CalculatorFilterTarget.Tags))
                {
                    for (var j = 0; j < functionInfo.Tags.Length && !isMatch; j++)
                    {
                        isMatch = this.Compare(functionInfo.Tags[j], terms[i]);
                    }
                }

                if (!isMatch && (target == CalculatorFilterTarget.All || target == CalculatorFilterTarget.Description))
                {
                    isMatch = this.Compare(functionInfo.Description, terms[i]);
                }

                overallMatch = isMatch;
                isMatch      = false;
            }

            return(overallMatch);
        }
Пример #6
0
 public FunctionInfo(string alias, IFunctionInfo primary) :
     this(alias, primary.Package, primary.Description)
 {
     Signatures  = primary.Signatures;
     ReturnValue = primary.ReturnValue;
     IsInternal  = primary.IsInternal;
 }
Пример #7
0
        /// <summary>
        /// Attempts to retrieve function information from cache is a simple manner.
        /// Specifically, when function name is unique (then package name is irrelevant)
        /// or the package name is known.
        /// </summary>
        private IFunctionInfo TryGetCachedFunctionInfo(string functionName, ref string packageName)
        {
            IFunctionInfo functionInfo = null;

            if (string.IsNullOrEmpty(packageName))
            {
                // Find packages that the function may belong to. There may be more than one.
                if (!_functionToPackageMap.TryGetValue(functionName, out var packages) || packages.Count == 0)
                {
                    // Not in the cache
                    return(null);
                }

                // Special case RTVS package
                if (packages.Count == 1 && packages[0].EqualsOrdinal("rtvs"))
                {
                    packageName = packages[0];
                }
                else
                {
                    // If there is only one package, try it.
                    var loaded = _host.LoadedPackageNames.Intersect(packages).ToArray();
                    if (loaded.Length == 1)
                    {
                        packageName = loaded[0];
                    }
                }
            }

            if (!string.IsNullOrEmpty(packageName))
            {
                _functionToInfoMap?.TryGetValue(GetQualifiedName(functionName, packageName), out functionInfo);
            }
            return(functionInfo);
        }
Пример #8
0
        /// <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);
        }
Пример #9
0
 private void SetDescription(IFunctionInfo fi)
 {
     if (fi != null)
     {
         string sig = (fi.Signatures.Count > 0) ? fi.Signatures[0].GetSignatureString(DisplayText) : null;
         this.Description = (sig != null) ? Invariant($"{sig}{Environment.NewLine}{Environment.NewLine}{fi.Description}") : fi.Description;
     }
 }
Пример #10
0
 private void SetDescription(IFunctionInfo fi)
 {
     if (fi != null && !_session.IsDismissed)
     {
         var sig = (fi.Signatures.Count > 0) ? fi.Signatures[0].GetSignatureString(DisplayText) : null;
         Description = (sig != null) ? Invariant($"{sig}{Environment.NewLine}{Environment.NewLine}{fi.Description.RemoveLineBreaks()}") : fi.Description;
     }
 }
Пример #11
0
 private static Boolean TryGetFunctionInfo(
     ParseContext context,
     String name,
     out IFunctionInfo functionInfo)
 {
     return(ExpressionConstants.WellKnownFunctions.TryGetValue(name, out functionInfo) ||
            context.ExtensionFunctions.TryGetValue(name, out functionInfo));
 }
        public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            List <RCompletion> completions   = new List <RCompletion>();
            ImageSource        functionGlyph = GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupValueType, StandardGlyphItem.GlyphItemPublic);

            // Safety checks
            FunctionCall funcCall = context.AstRoot.GetNodeOfTypeFromPosition <FunctionCall>(context.Position);

            if (funcCall == null || funcCall.OpenBrace == null || funcCall.Arguments == null)
            {
                return(completions);
            }

            if (context.Position < funcCall.OpenBrace.End || context.Position >= funcCall.SignatureEnd)
            {
                return(completions);
            }

            // Retrieve parameter positions from the current text buffer snapshot
            ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(context.AstRoot, context.TextBuffer.CurrentSnapshot, context.Position);

            if (parametersInfo == null)
            {
                return(completions);
            }

            // Get collection of function signatures from documentation (parsed RD file)
            IFunctionInfo functionInfo = FunctionIndex.GetFunctionInfo(parametersInfo.FunctionName, o => { }, context.Session.TextView);

            if (functionInfo == null)
            {
                return(completions);
            }

            // Collect parameter names from all signatures
            IEnumerable <KeyValuePair <string, IArgumentInfo> > arguments = new Dictionary <string, IArgumentInfo>();

            foreach (ISignatureInfo signature in functionInfo.Signatures)
            {
                var args = signature.Arguments.ToDictionary(x => x.Name);
                arguments = arguments.Union(args);
            }

            // Add names of arguments that  are not yet specified to the completion
            // list with '=' sign so user can tell them from function names.
            IEnumerable <string> declaredArguments = funcCall.Arguments.Where(x => x is NamedArgument).Select(x => ((NamedArgument)x).Name);
            IEnumerable <KeyValuePair <string, IArgumentInfo> > possibleArguments = arguments.Where(x => x.Key != "..." && !declaredArguments.Contains(x.Key));

            foreach (KeyValuePair <string, IArgumentInfo> arg in possibleArguments)
            {
                string displayText   = arg.Key + " =";
                string insertionText = arg.Key + " = ";
                completions.Add(new RCompletion(displayText, insertionText, arg.Value.Description, functionGlyph));
            }

            return(completions);
        }
Пример #13
0
        private static IEnumerable <IRFunctionSignatureHelp> MakeSignatures(IFunctionInfo functionInfo, ITrackingTextRange applicableToSpan, IRIntellisenseContext context)
        {
            var signatures = new List <IRFunctionSignatureHelp>();

            if (functionInfo?.Signatures != null)
            {
                signatures.AddRange(functionInfo.Signatures.Select(s => RFunctionSignatureHelp.Create(context, functionInfo, s, applicableToSpan)));
                context.Session.Properties["functionInfo"] = functionInfo;
            }
            return(signatures);
        }
Пример #14
0
        internal bool AugmentQuickInfoSession(AstRoot ast, int position, IQuickInfoSession session,
                                              IList <object> quickInfoContent, out ITrackingSpan applicableToSpan,
                                              Action <object> retriggerAction)
        {
            int signatureEnd = position;

            applicableToSpan = null;

            string functionName = SignatureHelp.GetFunctionNameFromBuffer(ast, ref position, out signatureEnd);

            if (!string.IsNullOrEmpty(functionName))
            {
                ITextSnapshot snapshot = session.TextView.TextBuffer.CurrentSnapshot;

                position = Math.Min(signatureEnd, position);
                int start = Math.Min(position, snapshot.Length);
                int end   = Math.Min(signatureEnd, snapshot.Length);

                applicableToSpan = snapshot.CreateTrackingSpan(Span.FromBounds(start, end), SpanTrackingMode.EdgeInclusive);

                IFunctionInfo functionInfo = FunctionIndex.GetFunctionInfo(functionName, retriggerAction, session);

                if (functionInfo != null && functionInfo.Signatures != null)
                {
                    foreach (ISignatureInfo sig in functionInfo.Signatures)
                    {
                        string signatureString = sig.GetSignatureString();
                        int    wrapLength      = Math.Min(SignatureInfo.MaxSignatureLength, signatureString.Length);
                        string text;

                        if (string.IsNullOrWhiteSpace(functionInfo.Description))
                        {
                            text = string.Empty;
                        }
                        else
                        {
                            /// VS may end showing very long tooltip so we need to keep
                            /// description reasonably short: typically about
                            /// same length as the function signature.
                            text = signatureString + "\r\n" + functionInfo.Description.Wrap(wrapLength);
                        }

                        if (text.Length > 0)
                        {
                            quickInfoContent.Add(text);
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Пример #15
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);
        }
Пример #16
0
        private static async Task GetFunctionInfoFromPackageAsync(IFunctionIndex functionIndex, string functionName, string packageName, Action <IFunctionInfo, object> callback, object parameter)
        {
            IFunctionInfo fi = null;

            packageName = packageName ?? await functionIndex.GetPackageNameAsync(functionName);

            if (!string.IsNullOrEmpty(packageName))
            {
                fi = functionIndex.GetFunctionInfo(functionName, packageName);
            }
            await functionIndex.Services.MainThread().SwitchToAsync();

            callback(fi, parameter);
        }
Пример #17
0
        private bool Evaluate(string expression)
        {
            var parser    = new ExpressionParser();
            var functions = new IFunctionInfo[]
            {
                new FunctionInfo <AlwaysFunction>(PipelineTemplateConstants.Always, 0, 0),
                new FunctionInfo <CancelledFunction>(PipelineTemplateConstants.Cancelled, 0, 0),
                new FunctionInfo <FailureFunction>(PipelineTemplateConstants.Failure, 0, 0),
                new FunctionInfo <SuccessFunction>(PipelineTemplateConstants.Success, 0, 0),
            };
            var tree   = parser.CreateTree(expression, null, null, functions);
            var result = tree.Evaluate(null, null, _templateContext, null);

            return(result.IsTruthy);
        }
Пример #18
0
        public void GetRdFunctionInfoTest01()
        {
            string rdData = _files.LoadDestinationFile(@"Help\01.rd");
            IReadOnlyList <IFunctionInfo> functionInfos = RdParser.GetFunctionInfos(rdData);

            functionInfos.Should().HaveCount(2);

            IFunctionInfo functionInfo = functionInfos[0];

            functionInfo.Name.Should().Be("abs");
            functionInfo.Description.Should().Be("abs(x) computes the absolute value of x, sqrt(x) computes the (principal) square root of x, x. The naming follows the standard for computer languages such as C or Fortran.");
            functionInfo.Signatures.Should().ContainSingle()
            .Which.Arguments.Should().ContainSingle()
            .Which.Description.Should().Be("a numeric or complex vector or array.");
        }
        /// <summary>
        /// Extracts information on the current function in the completion context, if any.
        /// </summary>
        /// <returns></returns>
        private IFunctionInfo GetFunctionInfo(IRIntellisenseContext context)
        {
            // Retrieve parameter positions from the current text buffer snapshot
            IFunctionInfo functionInfo = null;

            var parametersInfo = context.AstRoot.GetSignatureInfoFromBuffer(context.EditorBuffer.CurrentSnapshot, context.Position);

            if (parametersInfo != null)
            {
                // User-declared functions take priority
                functionInfo = context.AstRoot.GetUserFunctionInfo(parametersInfo.FunctionName, context.Position)
                               ?? _functionIndex.GetFunctionInfo(parametersInfo.FunctionName, null);
            }
            return(functionInfo);
        }
        private static async Task GetFunctionInfoFromPackageAsync(IFunctionIndex functionIndex
                                                                  , string functionName
                                                                  , string packageName
                                                                  , Action <IFunctionInfo, object> callback
                                                                  , object parameter)
        {
            IFunctionInfo fi = null;

            packageName = packageName ?? await functionIndex.GetPackageNameAsync(functionName);

            if (!string.IsNullOrEmpty(packageName))
            {
                fi = await functionIndex.GetFunctionInfoAsync(functionName, packageName);
            }
            callback(fi, parameter);
        }
Пример #21
0
        private ISignature CreateSignature(ISignatureHelpSession session,
                                           IFunctionInfo functionInfo, ISignatureInfo signatureInfo,
                                           ITrackingSpan span, AstRoot ast, int position)
        {
            SignatureHelp     sig       = new SignatureHelp(session, _textBuffer, functionInfo.Name, string.Empty, signatureInfo);
            List <IParameter> paramList = new List <IParameter>();

            // Locus points in the pretty printed signature (the one displayed in the tooltip)
            var    locusPoints     = new List <int>();
            string signatureString = signatureInfo.GetSignatureString(locusPoints);

            sig.Content          = signatureString;
            sig.ApplicableToSpan = span;

            sig.Documentation = functionInfo.Description?.Wrap(Math.Min(SignatureInfo.MaxSignatureLength, sig.Content.Length));

            Debug.Assert(locusPoints.Count == signatureInfo.Arguments.Count + 1);
            for (int i = 0; i < signatureInfo.Arguments.Count; i++)
            {
                IArgumentInfo p = signatureInfo.Arguments[i];
                if (p != null)
                {
                    int locusStart  = locusPoints[i];
                    int locusLength = locusPoints[i + 1] - locusStart;

                    Debug.Assert(locusLength >= 0);
                    Span locus = new Span(locusStart, locusLength);

                    /// VS may end showing very long tooltip so we need to keep
                    /// description reasonably short: typically about
                    /// same length as the function signature.
                    paramList.Add(
                        new SignatureParameter(
                            p.Description.Wrap(
                                Math.Min(SignatureInfo.MaxSignatureLength, sig.Content.Length)),
                            locus, locus, p.Name, sig));
                }
            }

            sig.Parameters = new ReadOnlyCollection <IParameter>(paramList);
            sig.ComputeCurrentParameter(ast, position);

            return(sig);
        }
        public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context)
        {
            List <RCompletion> completions = new List <RCompletion>();
            FunctionCall       funcCall;
            var functionGlyph = _imageService.GetImage(ImageType.ValueType) as ImageSource;

            // Safety checks
            if (!ShouldProvideCompletions(context, out funcCall))
            {
                return(completions);
            }

            // Get collection of function signatures from documentation (parsed RD file)
            IFunctionInfo functionInfo = GetFunctionInfo(context);

            if (functionInfo == null)
            {
                return(completions);
            }

            // Collect parameter names from all signatures
            IEnumerable <KeyValuePair <string, IArgumentInfo> > arguments = new Dictionary <string, IArgumentInfo>();

            foreach (ISignatureInfo signature in functionInfo.Signatures)
            {
                var args = signature.Arguments.ToDictionary(x => x.Name);
                arguments = arguments.Union(args);
            }

            // Add names of arguments that  are not yet specified to the completion
            // list with '=' sign so user can tell them from function names.
            IEnumerable <string> declaredArguments = funcCall.Arguments.Where(x => x is NamedArgument).Select(x => ((NamedArgument)x).Name);
            var possibleArguments = arguments.Where(x => !x.Key.EqualsOrdinal("...") && !declaredArguments.Contains(x.Key, StringComparer.OrdinalIgnoreCase));

            foreach (var arg in possibleArguments)
            {
                string displayText   = arg.Key + (_settings.FormatOptions.SpacesAroundEquals ? " =" : "=");
                string insertionText = arg.Key + (_settings.FormatOptions.SpacesAroundEquals ? " = " : "=");
                completions.Add(new RCompletion(displayText, insertionText, arg.Value.Description, functionGlyph));
            }

            return(completions);
        }
        /// <summary>
        /// Extracts information on the current function in the completion context, if any.
        /// </summary>
        /// <returns></returns>
        private IFunctionInfo GetFunctionInfo(RCompletionContext context)
        {
            // Retrieve parameter positions from the current text buffer snapshot
            IFunctionInfo functionInfo = null;

            ParameterInfo parametersInfo = SignatureHelp.GetParametersInfoFromBuffer(context.AstRoot, context.TextBuffer.CurrentSnapshot, context.Position);

            if (parametersInfo != null)
            {
                // User-declared functions take priority
                functionInfo = context.AstRoot.GetUserFunctionInfo(parametersInfo.FunctionName, context.Position);
                if (functionInfo == null)
                {
                    // Get collection of function signatures from documentation (parsed RD file)
                    functionInfo = _functionIndex.GetFunctionInfo(parametersInfo.FunctionName, null, (o, p) => { }, context.Session.TextView);
                }
            }
            return(functionInfo);
        }
Пример #24
0
        /// <summary>
        /// Attempts to retrieve function information from cache is a simple manner.
        /// Specifically, when function name is unique (then package name is irrelevant)
        /// or the package name is known.
        /// </summary>
        private IFunctionInfo TryGetCachedFunctionInfo(string functionName, ref string packageName)
        {
            IFunctionInfo functionInfo = null;

            if (string.IsNullOrEmpty(packageName))
            {
                // Find packages that the function may belong to. There may be more than one.
                List <string> packages;
                if (!_functionToPackageMap.TryGetValue(functionName, out packages) || packages.Count == 0)
                {
                    // Not in the cache
                    return(null);
                }

                // Special case RTVS package
                if (packages.Count == 1 && packages[0].EqualsOrdinal("rtvs"))
                {
                    packageName = packages[0];
                }
                else
                {
                    // If there is only one package, try it.
                    var loaded = _host.LoadedPackageNames.Intersect(packages).ToArray();
                    if (loaded.Length == 1)
                    {
                        packageName = loaded[0];
                    }
                }
            }
            else if (!packageName.EqualsOrdinal("rtvs") && !_host.LoadedPackageNames.Contains(packageName))
            {
                // Verify that the package is currently loaded. We do not show functions from all
                // installed packages and do not show from unloaded packages.
                return(null);
            }

            if (!string.IsNullOrEmpty(packageName))
            {
                _functionToInfoMap?.TryGetValue(GetQualifiedName(functionName, packageName), out functionInfo);
            }
            return(functionInfo);
        }
Пример #25
0
            public static int GetFunctionInfo(IntPtr v, int level, out FunctionInfo fi)
            {
                var info = new IFunctionInfo {
                };
                int ret  = _GetFunctionInfo(v, level, out info);

                fi = new FunctionInfo
                {
                    FuncId = info.FuncId,
#if SQUNICODE
                    Name   = Marshal.PtrToStringUni(info.Name),
                    Source = Marshal.PtrToStringUni(info.Source),
#else
                    Name   = Marshal.PtrToStringAnsi(info.Name),
                    Source = Marshal.PtrToStringAnsi(info.Source),
#endif
                };

                return(ret);
            }
        public IExpressionNode Parse(IExecutionContext executionContext, string condition)
        {
            ArgUtil.NotNull(executionContext, nameof(executionContext));
            var expressionTrace = new TraceWriter(Trace, executionContext);
            var parser          = new ExpressionParser();
            var namedValues     = new INamedValueInfo[]
            {
                new NamedValueInfo <VariablesNode>(name: Constants.Expressions.Variables),
            };
            var functions = new IFunctionInfo[]
            {
                new FunctionInfo <AlwaysNode>(name: Constants.Expressions.Always, minParameters: 0, maxParameters: 0),
                new FunctionInfo <CanceledNode>(name: Constants.Expressions.Canceled, minParameters: 0, maxParameters: 0),
                new FunctionInfo <FailedNode>(name: Constants.Expressions.Failed, minParameters: 0, maxParameters: 0),
                new FunctionInfo <SucceededNode>(name: Constants.Expressions.Succeeded, minParameters: 0, maxParameters: 0),
                new FunctionInfo <SucceededOrFailedNode>(name: Constants.Expressions.SucceededOrFailed, minParameters: 0, maxParameters: 0),
            };

            return(parser.CreateTree(condition, expressionTrace, namedValues, functions) ?? new SucceededNode());
        }
Пример #27
0
        private static IExpressionNode Parse(IExecutionContext executionContext, TraceWriter expressionTrace, string condition)
        {
            ArgUtil.NotNull(executionContext, nameof(executionContext));

            if (string.IsNullOrWhiteSpace(condition))
            {
                condition = $"{PipelineTemplateConstants.Success}()";
            }

            var parser      = new ExpressionParser();
            var namedValues = executionContext.ExpressionValues.Keys.Select(x => new NamedValueInfo <ContextValueNode>(x)).ToArray();
            var functions   = new IFunctionInfo[]
            {
                new FunctionInfo <AlwaysNode>(name: Constants.Expressions.Always, minParameters: 0, maxParameters: 0),
                new FunctionInfo <CancelledNode>(name: Constants.Expressions.Cancelled, minParameters: 0, maxParameters: 0),
                new FunctionInfo <FailureNode>(name: Constants.Expressions.Failure, minParameters: 0, maxParameters: 0),
                new FunctionInfo <SuccessNode>(name: Constants.Expressions.Success, minParameters: 0, maxParameters: 0),
            };

            return(parser.CreateTree(condition, expressionTrace, namedValues, functions) ?? new SuccessNode());
        }
Пример #28
0
        public static IRFunctionSignatureHelp Create(IRIntellisenseContext context, IFunctionInfo functionInfo, ISignatureInfo signatureInfo, ITrackingTextRange applicableSpan)
        {
            var sig       = new RFunctionSignatureHelp(context.Session, context.EditorBuffer, functionInfo.Name, string.Empty, signatureInfo);
            var paramList = new List <ISignatureParameterHelp>();

            // Locus points in the pretty printed signature (the one displayed in the tooltip)
            var locusPoints     = new List <int>();
            var signatureString = signatureInfo.GetSignatureString(functionInfo.Name, locusPoints);

            sig.Content           = signatureString;
            sig.ApplicableToRange = applicableSpan;

            sig.Documentation = functionInfo.Description?.Wrap(Math.Min(MaxSignatureLength, sig.Content.Length));

            Debug.Assert(locusPoints.Count == signatureInfo.Arguments.Count + 1);
            for (var i = 0; i < signatureInfo.Arguments.Count; i++)
            {
                var p = signatureInfo.Arguments[i];
                if (p != null)
                {
                    var locusStart  = locusPoints[i];
                    var locusLength = locusPoints[i + 1] - locusStart;

                    Debug.Assert(locusLength >= 0);
                    var locus = new TextRange(locusStart, locusLength);

                    // VS may end showing very long tooltip so we need to keep
                    // description reasonably short: typically about
                    // same length as the function signature.
                    var description = p.Description.Wrap(Math.Min(MaxSignatureLength, sig.Content.Length));
                    paramList.Add(new RSignatureParameterHelp(description, locus, p.Name, sig));
                }
            }

            sig.Parameters = new ReadOnlyCollection <ISignatureParameterHelp>(paramList);
            sig.ComputeCurrentParameter(context.AstRoot, context.Position);

            return(sig);
        }
Пример #29
0
        /// <summary>
        /// Performs the search on an IFunctionInfo object and combines the results using logical OR.
        /// </summary>
        /// <param name="functionInfo">Object to perform the search on.</param>
        /// <param name="terms">Array of terms to search for.</param>
        /// <param name="target">Property of the object to search.</param>
        /// <returns>True if there is a match, false otherwise.</returns>
        public bool IsOrMatch(IFunctionInfo functionInfo, string[] terms, CalculatorFilterTarget target)
        {
            var isMatch = false;

            if (!isMatch && (target == CalculatorFilterTarget.All || target == CalculatorFilterTarget.Name))
            {
                isMatch = terms.Any(i => this.Compare(functionInfo.Name, i));
            }

            if (!isMatch && (target == CalculatorFilterTarget.All || target == CalculatorFilterTarget.Tags))
            {
                for (var i = 0; i < functionInfo.Tags.Length && !isMatch; i++)
                {
                    isMatch = terms.Any(j => this.Compare(functionInfo.Tags[i], j));
                }
            }

            if (!isMatch && (target == CalculatorFilterTarget.All || target == CalculatorFilterTarget.Description))
            {
                isMatch = terms.Any(i => this.Compare(functionInfo.Description, i));
            }

            return(isMatch);
        }
Пример #30
0
 private void SetDescription(IFunctionInfo fi) {
     if (fi != null) {
         string sig = (fi.Signatures.Count > 0) ? fi.Signatures[0].GetSignatureString(DisplayText) : null;
         this.Description = (sig != null) ? Invariant($"{sig}{Environment.NewLine}{Environment.NewLine}{fi.Description}") : fi.Description;
     }
 }
Пример #31
0
 protected BaseFunction(IFunctionInfo functionInfo, params IValue[] inputs)
 {
     this.FunctionInfo = functionInfo;
     this.Inputs       = inputs;
 }
Пример #32
0
        private ISignature CreateSignature(ISignatureHelpSession session,
                                       string functionName, IFunctionInfo functionInfo, ISignatureInfo signatureInfo,
                                       ITrackingSpan span, AstRoot ast, int position) {
            SignatureHelp sig = new SignatureHelp(session, _textBuffer, functionName, string.Empty, signatureInfo, _shell);
            List<IParameter> paramList = new List<IParameter>();

            // Locus points in the pretty printed signature (the one displayed in the tooltip)
            var locusPoints = new List<int>();
            string signatureString = signatureInfo.GetSignatureString(functionName, locusPoints);
            sig.Content = signatureString;
            sig.ApplicableToSpan = span;

            sig.Documentation = functionInfo.Description?.Wrap(Math.Min(SignatureInfo.MaxSignatureLength, sig.Content.Length));

            Debug.Assert(locusPoints.Count == signatureInfo.Arguments.Count + 1);
            for (int i = 0; i < signatureInfo.Arguments.Count; i++) {
                IArgumentInfo p = signatureInfo.Arguments[i];
                if (p != null) {
                    int locusStart = locusPoints[i];
                    int locusLength = locusPoints[i + 1] - locusStart;

                    Debug.Assert(locusLength >= 0);
                    Span locus = new Span(locusStart, locusLength);

                    /// VS may end showing very long tooltip so we need to keep 
                    /// description reasonably short: typically about
                    /// same length as the function signature.
                    paramList.Add(
                        new SignatureParameter(
                            p.Description.Wrap(
                                Math.Min(SignatureInfo.MaxSignatureLength, sig.Content.Length)),
                                locus, locus, p.Name, sig));
                }
            }

            sig.Parameters = new ReadOnlyCollection<IParameter>(paramList);
            sig.ComputeCurrentParameter(ast, position);

            return sig;
        }
Пример #33
0
 public FunctionInfo(string alias, IFunctionInfo primary) : this(alias, primary.Description) {
     Signatures = primary.Signatures;
     ReturnValue = primary.ReturnValue;
     IsInternal = primary.IsInternal;
 }
 /// <inheritdoc />
 public bool Equals(IFunctionInfo other)
 {
     return Equals((object)other);
 }