public IReadOnlyCollection <ICompletionEntry> GetEntries(IRIntellisenseContext context) { var completions = new List <ICompletionEntry>(); var infoSource = _snippetInformationSource?.InformationSource; var packages = GetPackages(context).ToList(); var packageName = packages.Count == 1 ? packages[0].Name : null; // 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, packageName, _functionIndex, context.Session); completions.Add(completion); } } return(completions); }
public Task <IReadOnlyCollection <ICompletionEntry> > GetEntriesAsync(IRIntellisenseContext context, string prefixFilter = null) { 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 (var keyword in keywords) { var 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 (var s in Builtins.BuiltinList) { completions.Add(new EditorCompletionEntry(s, s, string.Empty, buildInGlyph)); } } return(Task.FromResult <IReadOnlyCollection <ICompletionEntry> >(completions)); }
private async Task <IEnumerable <IPackageInfo> > GetPackagesAsync(IRIntellisenseContext context) { if (context.IsCaretInNamespace()) { return(GetSpecificPackage(context)); } return(await GetAllFilePackagesAsync(context)); }
public IReadOnlyCollection <ICompletionEntry> GetEntries(IRIntellisenseContext context, string prefixFilter = null) { var completions = new List <ICompletionEntry>(); if (_snippetInformationSource?.InformationSource != null && !context.IsCaretInNamespace()) { var snippets = _snippetInformationSource.InformationSource.Snippets; completions.AddRange(snippets.Select(info => new EditorCompletionEntry(info.Name, info.Name, info.Description, _snippetGlyph))); } return(completions); }
private IEnumerable <IPackageInfo> GetPackages(IRIntellisenseContext context) { if (context.IsCaretInNamespace()) { return(GetSpecificPackage(context)); } return(_taskService.Wait(() => GetAllFilePackagesAsync(context), out var result, _asyncWaitTimeout) ? result : Enumerable.Empty <IPackageInfo>()); }
private IEnumerable <IPackageInfo> GetPackages(IRIntellisenseContext context) { if (context.IsCaretInNamespace()) { return(GetSpecificPackage(context)); } var t = GetAllFilePackagesAsync(context); return(_taskService.Wait(t, CancellationToken.None, _asyncWaitTimeout) ? t.Result : Enumerable.Empty <IPackageInfo>()); }
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); }
/// <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); } if (context.IsRHistoryRequest) { var history = _services.GetService <IRInteractiveWorkflowProvider>().GetOrCreate().History; providers.Add(new RHistoryCompletionProvider(history, _imageService)); return(providers); } // First check file completion - it happens inside strings if (CanShowFileCompletion(ast, context.Position, out var 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 var 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 { 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); }