private Task <List <RCompletion> > GetRemoteDirectoryItemsAsync(string directory) { return(Task.Run(async() => { var session = _workflow.RSession; var completions = new List <RCompletion>(); try { var rPath = directory.ToRPath().ToRStringLiteral(); var files = await session.EvaluateAsync <JArray>(Invariant($"as.list(list.files(path = {rPath}, include.dirs = FALSE))"), REvaluationKind.Normal); var dirs = await session.EvaluateAsync <JArray>(Invariant($"as.list(list.dirs(path = {rPath}, full.names = FALSE, recursive = FALSE))"), REvaluationKind.Normal); var folderGlyph = _glyphService.GetGlyphThreadSafe(StandardGlyphGroup.GlyphClosedFolder, StandardGlyphItem.GlyphItemPublic); foreach (var d in dirs) { completions.Add(new RCompletion((string)d, (string)d + "/", string.Empty, folderGlyph)); } foreach (var f in files) { completions.Add(new RCompletion((string)f, (string)f, string.Empty, folderGlyph)); } } catch (RException) { } catch (OperationCanceledException) { } return completions; })); }
public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context) { List <RCompletion> completions = new List <RCompletion>(); if (!context.IsInNameSpace()) { var infoSource = _snippetInformationSource?.InformationSource; ImageSource keyWordGlyph = _glyphService.GetGlyphThreadSafe(StandardGlyphGroup.GlyphKeyword, StandardGlyphItem.GlyphItemPublic); // 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 RCompletion(keyword, keyword, string.Empty, keyWordGlyph)); } } ImageSource buildInGlyph = _glyphService.GetGlyphThreadSafe(StandardGlyphGroup.GlyphGroupIntrinsic, StandardGlyphItem.GlyphItemPublic); foreach (string s in Builtins.BuiltinList) { completions.Add(new RCompletion(s, s, string.Empty, buildInGlyph)); } } return(completions); }
public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context) { List <RCompletion> completions = new List <RCompletion>(); ImageSource functionGlyph = _glyphService.GetGlyphThreadSafe(StandardGlyphGroup.GlyphGroupMethod, StandardGlyphItem.GlyphItemPublic); ImageSource variableGlyph = _glyphService.GetGlyphThreadSafe(StandardGlyphGroup.GlyphGroupVariable, StandardGlyphItem.GlyphItemPublic); var start = DateTime.Now; _variablesProvider.Initialize(); var names = GetFieldProvidingVariableNames(context); foreach (var variableName in names) { int memberCount = _variablesProvider.GetMemberCount(variableName); IReadOnlyCollection <INamedItemInfo> members = _variablesProvider.GetMembers(variableName, 200); foreach (var v in members) { Debug.Assert(v != null); if (v.Name.Length > 0 && v.Name[0] != '[') { ImageSource glyph = v.ItemType == NamedItemType.Variable ? variableGlyph : functionGlyph; var completion = new RCompletion(v.Name, CompletionUtilities.BacktickName(v.Name), v.Description, glyph); completions.Add(completion); } } } Debug.WriteLine("Variable members fetch: " + (DateTime.Now - start).TotalMilliseconds); return(completions); }
public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context) { List <RCompletion> completions = new List <RCompletion>(); ImageSource functionGlyph = _glyphService.GetGlyphThreadSafe(StandardGlyphGroup.GlyphGroupMethod, StandardGlyphItem.GlyphItemPublic); ImageSource variableGlyph = _glyphService.GetGlyphThreadSafe(StandardGlyphGroup.GlyphGroupVariable, StandardGlyphItem.GlyphItemPublic); string variableName = context.Session.TextView.GetVariableNameBeforeCaret(); _variablesProvider.Initialize(); int memberCount = _variablesProvider.GetMemberCount(variableName); IReadOnlyCollection <INamedItemInfo> members = _variablesProvider.GetMembers(variableName, 200); // Get list of functions in the package foreach (var v in members) { Debug.Assert(v != null); if (v.Name.Length > 0 && v.Name[0] != '[') { ImageSource glyph = v.ItemType == NamedItemType.Variable ? variableGlyph : functionGlyph; var completion = new RCompletion(v.Name, CompletionUtilities.BacktickName(v.Name), v.Description, glyph); completions.Add(completion); } } return(completions); }
public PackageFunctionCompletionProvider( ILoadedPackagesProvider loadedPackagesProvider, [Import(AllowDefault = true)] ISnippetInformationSourceProvider snippetInformationSource, IPackageIndex packageIndex, IFunctionIndex functionIndex, IGlyphService glyphService) { _loadedPackagesProvider = loadedPackagesProvider; _snippetInformationSource = snippetInformationSource; _packageIndex = packageIndex; _functionIndex = functionIndex; _functionGlyph = glyphService.GetGlyphThreadSafe(StandardGlyphGroup.GlyphGroupMethod, StandardGlyphItem.GlyphItemPublic); _constantGlyph = glyphService.GetGlyphThreadSafe(StandardGlyphGroup.GlyphGroupConstant, StandardGlyphItem.GlyphItemPublic); }
public IReadOnlyCollection <RCompletion> GetEntries(RCompletionContext context) { List <RCompletion> completions = new List <RCompletion>(); FunctionCall funcCall; ImageSource functionGlyph = _glyphService.GetGlyphThreadSafe(StandardGlyphGroup.GlyphGroupValueType, StandardGlyphItem.GlyphItemPublic); // 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 + " ="; string insertionText = arg.Key + " = "; completions.Add(new RCompletion(displayText, insertionText, arg.Value.Description, functionGlyph)); } return(completions); }
public UserVariablesCompletionProvider(IGlyphService glyphService) { _functionGlyph = glyphService.GetGlyphThreadSafe(StandardGlyphGroup.GlyphGroupMethod, StandardGlyphItem.GlyphItemPublic); _variableGlyph = glyphService.GetGlyphThreadSafe(StandardGlyphGroup.GlyphGroupVariable, StandardGlyphItem.GlyphItemPublic); }
public SnippetCompletionProvider([Import(AllowDefault = true)] ISnippetInformationSourceProvider snippetInformationSource, IGlyphService glyphService) { _snippetInformationSource = snippetInformationSource; _snippetGlyph = glyphService.GetGlyphThreadSafe(StandardGlyphGroup.GlyphCSharpExpansion, StandardGlyphItem.GlyphItemPublic); }
public PackagesCompletionProvider(IPackageIndex packageIndex, IGlyphService glyphService) { _packageIndex = packageIndex; _glyph = glyphService.GetGlyphThreadSafe(StandardGlyphGroup.GlyphLibrary, StandardGlyphItem.GlyphItemPublic); }