private async Task UpdateCompletion() { int position = EditorControl.CaretOffset; try { string fullSource = OwnerEditor.FullSource; CompletionWindow.Document = Document.WithText(SourceText.From(fullSource)); CompletionList completion = await CompletionService.GetCompletionsAsync(CompletionWindow.Document, position + OwnerEditor.PreSource.Length + 1); if (completion != null && completion.Items != null && completion.Items.Length > 0) { string filter = fullSource.Substring(completion.Span.Start, completion.Span.Length); await CompletionWindow.SetCompletionList(completion); await CompletionWindow.SetFilterText(filter); if (CompletionWindow.VisibleItems > 0) { CompletionWindow.IsVisible = true; } } else { CompletionWindow.IsVisible = false; } } catch (Exception ex) { Debug.WriteLine("Error while updating completion: {0}", ex.Message); } }
public static Task <bool> validateNamespace(string s) { //var namespaces = Assembly.GetAssembly(typeof(List<>)).GetModules(); //return false; var position = s.Length - 1; //scriptCode = SourceText.From(s); return(service.GetCompletionsAsync(scriptDocument, position).ContinueWith(f => { return false; })); }
public async Task <IEnumerable <CompletionItem> > GetAutoCompleteAsync() { if (Workspace.EditingDocument is null) { return(new List <CompletionItem>()); } CompletionList completionList = await _completionService.GetCompletionsAsync(Workspace.EditingDocument, Workspace.EditingFile.EditorPosition.Value); return(FilterByActiveSpan(completionList, Workspace.EditingFile.RawContents, Workspace.EditingFile.EditorPosition)); }
public static Task <CompletionList> GetCompletionsAsync( this CompletionService completionService, Document document, int caretPosition, CompletionTrigger trigger, ImmutableHashSet <string>?roles, OmniSharpCompletionOptions options, CancellationToken cancellationToken) { return(completionService.GetCompletionsAsync(document, caretPosition, options.ToCompletionOptions(), document.Project.Solution.Options, trigger, roles, cancellationToken)); }
public Task <CompletionList?> GetCompletionListAsync(int position) { if (CurrentDocument != null) { Document document = CurrentDocument; CompletionService completionService = CompletionService.GetService(document); return(completionService.GetCompletionsAsync(document, position)); } return(Task.FromResult <CompletionList?>(null)); }
private async Task <Model> DoInBackgroundAsync(CancellationToken cancellationToken) { using (Logger.LogBlock(FunctionId.Completion_ModelComputer_DoInBackground, cancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); if (_completionService == null || _options == null) { // both completionService and options can be null if given buffer is not registered to workspace yet. // could happen in razor more frequently Logger.Log(FunctionId.Completion_ModelComputer_DoInBackground, (c, o) => $"service: {c != null}, options: {o != null}", _completionService, _options); return(null); } // get partial solution from background thread. _documentOpt = _text.GetDocumentWithFrozenPartialSemantics(cancellationToken); // TODO(cyrusn): We're calling into extensions, we need to make ourselves resilient // to the extension crashing. var completionList = _documentOpt == null ? null : await _completionService.GetCompletionsAsync( _documentOpt, _subjectBufferCaretPosition, _trigger, _roles, _options, cancellationToken).ConfigureAwait(false); if (completionList == null) { Logger.Log(FunctionId.Completion_ModelComputer_DoInBackground, d => $"No completionList, document: {d != null}, document open: {d?.IsOpen()}", _documentOpt); return(null); } var suggestionMode = _useSuggestionMode || completionList.SuggestionModeItem != null; return(Model.CreateModel( _documentOpt, _disconnectedBufferGraph, completionList, useSuggestionMode: suggestionMode, trigger: _trigger)); } }
/// <summary> /// Generates completion options for a manager script. /// </summary> /// <param name="code">Source code.</param> /// <param name="offset">Offset of the cursor/caret in the source code.</param> /// <param name="controlSpace">True iff this intellisense request was generated by the user pressing control + space.</param> /// <returns>True if any completion options are found. False otherwise.</returns> public async Task <List <NeedContextItemsArgs.ContextItem> > GenerateScriptCompletions(string code, int offset, bool controlSpace = false) { // Alternative approach using CompletionService: // UpdateDocument(code); string contents = (await doc.GetTextAsync()).ToString(); CompletionList results = await completion.GetCompletionsAsync(doc, offset); if (results == null) { return(null); } // Can't use await in a lambda...ugh List <NeedContextItemsArgs.ContextItem> result = new List <NeedContextItemsArgs.ContextItem>(); foreach (CompletionItem item in results.Items) { result.Add(await GetContextItem(item)); } return(result); }
public async Task <IEnumerable <NeedContextItemsArgs.ContextItem> > GetCompletionItemsAsync(string code, int offset) { UpdateDocument(code); Document[] documents = new Document[1] { document }; string wordToComplete = GetPartialWord(code, offset); var completions = new List <NeedContextItemsArgs.ContextItem>(); foreach (Document document in documents) { SourceText source = await document.GetTextAsync(); CompletionService service = CompletionService.GetService(document); CompletionList completionList = await service.GetCompletionsAsync(document, offset); if (completionList != null) { // get recommended symbols to match them up later with SymbolCompletionProvider SemanticModel semanticModel = await document.GetSemanticModelAsync(); ISymbol[] recommendedSymbols = (await Recommender.GetRecommendedSymbolsAtPositionAsync(semanticModel, offset, workspace)).ToArray(); bool isSuggestionMode = completionList.SuggestionModeItem != null; foreach (CompletionItem item in completionList.Items) { string completionText = item.DisplayText; bool preselect = item.Rules.MatchPriority == MatchPriority.Preselect; if (completionText.IsValidCompletionFor(wordToComplete)) { var symbols = await item.GetCompletionSymbolsAsync(recommendedSymbols, document); if (symbols.Any()) { foreach (ISymbol symbol in symbols) { if (item.UseDisplayTextAsCompletionText()) { completionText = item.DisplayText; } else if (item.TryGetInsertionText(out var insertionText)) { completionText = insertionText; } else { completionText = symbol.Name; } if (symbol != null) { //if (request.WantSnippet) //{ // foreach (var completion in MakeSnippetedResponses(request, symbol, completionText, preselect, isSuggestionMode)) // { // completions.Add(completion); // } //} //else { //completions.Add(MakeAutoCompleteResponse(request, symbol, completionText, preselect, isSuggestionMode)); completions.Add(new NeedContextItemsArgs.ContextItem() { Name = symbol.Name, Descr = symbol.ToDisplayString(), IsMethod = symbol.Kind == SymbolKind.Method, IsProperty = symbol.Kind == SymbolKind.Property, IsEvent = symbol.Kind == SymbolKind.Event }); if (symbol is IPropertySymbol property) { completions.Last().IsWriteable = !property.IsReadOnly; } } } } // if we had any symbols from the completion, we can continue, otherwise it means // the completion didn't have an associated symbol so we'll add it manually continue; } // for other completions, i.e. keywords, create a simple AutoCompleteResponse // we'll just assume that the completion text is the same // as the display text. //var response = new AutoCompleteResponse() //{ // CompletionText = item.DisplayText, // DisplayText = item.DisplayText, // Snippet = item.DisplayText, // Kind = request.WantKind ? item.Tags.First() : null, // IsSuggestionMode = isSuggestionMode, // Preselect = preselect //}; completions.Add(new NeedContextItemsArgs.ContextItem() { Name = item.DisplayText, Descr = item.Tags.First(), }); } } } } return(completions .OrderByDescending(c => c.Name.IsValidCompletionStartsWithExactCase(wordToComplete)) .ThenByDescending(c => c.Name.IsValidCompletionStartsWithIgnoreCase(wordToComplete)) .ThenByDescending(c => c.Name.IsCamelCaseMatch(wordToComplete)) .ThenByDescending(c => c.Name.IsSubsequenceMatch(wordToComplete)) .ThenBy(c => c.Name, StringComparer.OrdinalIgnoreCase) .ThenBy(c => c.Name, StringComparer.OrdinalIgnoreCase)); }
internal Task <CompletionList> GetCompletionListAsync( CompletionService service, Document document, int position, CompletionTrigger triggerInfo, OptionSet options = null) { return(service.GetCompletionsAsync(document, position, triggerInfo, options: options)); }
private async Task <CompletionList> GetCompletionListAsync(CompletionService completionService, CompletionTrigger trigger, CancellationToken cancellationToken) { return(_documentOpt != null ? await completionService.GetCompletionsAsync(_documentOpt, _subjectBufferCaretPosition, trigger, _roles, _options, cancellationToken).ConfigureAwait(false) : null); }
public Task <CompletionList> GetCompletionsAsync(int cursorPosition, CompletionTrigger trigger, CancellationToken cancellationToken) { return(_completionService.GetCompletionsAsync(Document, cursorPosition, trigger, cancellationToken: cancellationToken)); }