Пример #1
0
        public IReadOnlyCollection <ICompletionEntry> GetEntries(IRIntellisenseContext context)
        {
            var completions = new List <ICompletionEntry>();

            if (!context.IsCaretInNameSpace())
            {
                var infoSource   = _snippetInformationSource?.InformationSource;
                var keyWordGlyph = _imageService.GetImage(ImageType.Keyword);

                // Union with constants like TRUE and other common things
                var keywords = Keywords.KeywordList.Concat(Logicals.LogicalsList).Concat(Constants.ConstantsList);
                foreach (string keyword in keywords)
                {
                    bool?isSnippet = infoSource?.IsSnippet(keyword);
                    if (!isSnippet.HasValue || !isSnippet.Value)
                    {
                        completions.Add(new EditorCompletionEntry(keyword, keyword, string.Empty, keyWordGlyph));
                    }
                }

                var buildInGlyph = _imageService.GetImage(ImageType.Keyword);
                foreach (string s in Builtins.BuiltinList)
                {
                    completions.Add(new EditorCompletionEntry(s, s, string.Empty, buildInGlyph));
                }
            }

            return(completions);
        }
Пример #2
0
        public IReadOnlyCollection <ICompletionEntry> GetEntries(IRIntellisenseContext context)
        {
            var completions = new List <ICompletionEntry>();
            var infoSource  = _snippetInformationSource?.InformationSource;
            var packages    = GetPackages(context);

            // Get list of functions in the package
            foreach (var pkg in packages)
            {
                Debug.Assert(pkg != null);
                var functions = pkg.Functions;
                if (functions == null)
                {
                    continue;
                }

                foreach (var function in functions)
                {
                    // Snippets are suppressed if user typed namespace
                    if (!context.IsCaretInNameSpace() && infoSource != null)
                    {
                        if (infoSource.IsSnippet(function.Name))
                        {
                            continue;
                        }
                    }
                    var glyph      = function.ItemType == NamedItemType.Constant ? _constantGlyph : _functionGlyph;
                    var completion = new RFunctionCompletionEntry(function.Name, function.Name.BacktickName(), function.Description, glyph, _functionIndex, context.Session);
                    completions.Add(completion);
                }
            }

            return(completions);
        }
Пример #3
0
        private IEnumerable <IPackageInfo> GetPackages(IRIntellisenseContext context)
        {
            if (context.IsCaretInNameSpace())
            {
                return(GetSpecificPackage(context));
            }

            var t = GetAllFilePackagesAsync(context);

            t.Wait(_asyncWaitTimeout);
            return(t.IsCompleted ? t.Result : Enumerable.Empty <IPackageInfo>());
        }
Пример #4
0
        public IReadOnlyCollection <ICompletionEntry> GetEntries(IRIntellisenseContext context)
        {
            var completions = new List <ICompletionEntry>();

            if (_snippetInformationSource?.InformationSource != null && !context.IsCaretInNameSpace())
            {
                foreach (ISnippetInfo info in _snippetInformationSource.InformationSource.Snippets)
                {
                    completions.Add(new EditorCompletionEntry(info.Name, info.Name, info.Description, _snippetGlyph));
                }
            }
            return(completions);
        }
Пример #5
0
        /// <summary>
        /// Provides list of completion entries for a given location in the AST.
        /// </summary>
        /// <param name="context"></param>
        /// <returns>List of completion entries for a given location in the AST</returns>
        public IReadOnlyCollection <IRCompletionListProvider> GetCompletionForLocation(IRIntellisenseContext context)
        {
            var ast = context.AstRoot;

            var providers = new List <IRCompletionListProvider>();

            if (ast.Comments.Contains(context.Position))
            {
                // No completion in comments except iif it is Roxygen
                providers.Add(new RoxygenTagCompletionProvider(_imageService));
                return(providers);
            }

            // First check file completion - it happens inside strings
            string directory;

            if (CanShowFileCompletion(ast, context.Position, out directory))
            {
                if (!string.IsNullOrEmpty(directory))
                {
                    providers.Add(new FilesCompletionProvider(directory, _services));
                }
                return(providers);
            }

            // Special case for unterminated strings
            var tokenNode = ast.GetNodeOfTypeFromPosition <TokenNode>(context.Position, includeEnd: true);

            if (tokenNode != null && context.Position == tokenNode.End && tokenNode.Token.TokenType == RTokenType.String)
            {
                var snapshot = context.EditorBuffer.CurrentSnapshot;
                // String token at least has opening quote
                char quote = snapshot[tokenNode.Start];
                if (tokenNode.Length == 1 || quote != snapshot[tokenNode.End - 1])
                {
                    // No completion at the end of underminated string
                    return(providers);
                }
            }

            // Now check if position is inside a string or a number and if so, suppress the completion list
            tokenNode = ast.GetNodeOfTypeFromPosition <TokenNode>(context.Position);
            if (tokenNode != null && (tokenNode.Token.TokenType == RTokenType.String ||
                                      tokenNode.Token.TokenType == RTokenType.Number ||
                                      tokenNode.Token.TokenType == RTokenType.Complex))
            {
                // No completion in strings or numbers
                return(providers);
            }

            // We do not want automatic completion inside identifiers such as in a middle
            // of ab|c or in `abc|`. Manually invoked completion is fine.
            if (tokenNode != null && tokenNode.Token.TokenType == RTokenType.Identifier && context.AutoShownCompletion)
            {
                return(providers);
            }

            // Check end of numeric token like 2.- dot should not be bringing completion
            tokenNode = ast.GetNodeOfTypeFromPosition <TokenNode>(Math.Max(0, context.Position - 1));
            if (tokenNode != null && (tokenNode.Token.TokenType == RTokenType.Number ||
                                      tokenNode.Token.TokenType == RTokenType.Complex))
            {
                // No completion in numbers
                return(providers);
            }

            if (ast.IsInFunctionArgumentName <FunctionDefinition>(context.Position))
            {
                // No completion in function definition argument names
                return(providers);
            }

            var variablesProvider = _services.GetService <IVariablesProvider>();
            var packageIndex      = _services.GetService <IPackageIndex>();

            if (ast.TextProvider.IsInObjectMemberName(context.Position))
            {
                providers.Add(new WorkspaceVariableCompletionProvider(variablesProvider, _imageService));
                return(providers);
            }

            if (IsPackageListCompletion(context.EditorBuffer, context.Position))
            {
                providers.Add(new PackagesCompletionProvider(packageIndex, _imageService));
            }
            else
            {
                if (ast.IsInFunctionArgumentName <FunctionCall>(context.Position))
                {
                    var functionIndex = _services.GetService <IFunctionIndex>();
                    providers.Add(new ParameterNameCompletionProvider(functionIndex, _imageService));
                }

                providers.Add(new KeywordCompletionProvider(_services));
                providers.Add(new PackageFunctionCompletionProvider(_services));
                providers.Add(new UserVariablesCompletionProvider(_imageService));
                providers.Add(new SnippetCompletionProvider(_services));

                if (!context.IsCaretInNameSpace())
                {
                    providers.Add(new PackagesCompletionProvider(packageIndex, _imageService));
                }
            }

            if (!context.IsCaretInNameSpace())
            {
                providers.Add(new WorkspaceVariableCompletionProvider(variablesProvider, _imageService));
            }

            return(providers);
        }