public async Task <IEnumerable <AutoCompleteResponse> > Handle(AutoCompleteRequest request) { var documents = _workspace.GetDocuments(request.FileName); var wordToComplete = request.WordToComplete; var completions = new HashSet <AutoCompleteResponse>(); foreach (var document in documents) { var sourceText = await document.GetTextAsync(); var position = sourceText.GetTextPosition(request); var service = CompletionService.GetService(document); var options = new OmniSharpCompletionOptions( ShowItemsFromUnimportedNamespaces: _omniSharpOptions.RoslynExtensionsOptions.EnableImportCompletion, ForceExpandedCompletionIndexCreation: false); var completionList = await OmniSharpCompletionService.GetCompletionsAsync(service, document, position, trigger : default, roles : null, options, CancellationToken.None);
public async Task <IEnumerable <AutoCompleteResponse> > Handle(AutoCompleteRequest request) { var documents = _workspace.GetDocuments(request.FileName); var wordToComplete = request.WordToComplete; var completions = new HashSet <AutoCompleteResponse>(); foreach (var document in documents) { var sourceText = await document.GetTextAsync(); var position = sourceText.GetTextPosition(request); var service = CompletionService.GetService(document); var completionList = await service.GetCompletionsAsync(document, position); if (completionList != null) { // Only trigger on space if Roslyn has object creation items if (request.TriggerCharacter == " " && !completionList.Items.Any(i => i.GetProviderName() is CompletionListBuilder.ObjectCreationCompletionProvider)) { return(completions); } // get recommended symbols to match them up later with SymbolCompletionProvider var semanticModel = await document.GetSemanticModelAsync(); var recommendedSymbols = (await Recommender.GetRecommendedSymbolsAtPositionAsync(semanticModel, position, _workspace)).ToArray(); var isSuggestionMode = completionList.SuggestionModeItem != null; foreach (var item in completionList.Items) { var completionText = item.DisplayText; var preselect = item.Rules.MatchPriority == MatchPriority.Preselect; if (completionText.IsValidCompletionFor(wordToComplete)) { var symbols = await item.GetCompletionSymbolsAsync(recommendedSymbols, document); if (symbols.Any()) { foreach (var 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)); } } } // 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 or em, create a simple AutoCompleteResponse var response = item.ToAutoCompleteResponse(request.WantKind, isSuggestionMode, preselect); completions.Add(response); } } } } return(completions .OrderByDescending(c => c.CompletionText.IsValidCompletionStartsWithExactCase(wordToComplete)) .ThenByDescending(c => c.CompletionText.IsValidCompletionStartsWithIgnoreCase(wordToComplete)) .ThenByDescending(c => c.CompletionText.IsCamelCaseMatch(wordToComplete)) .ThenByDescending(c => c.CompletionText.IsSubsequenceMatch(wordToComplete)) .ThenBy(c => c.DisplayText, StringComparer.OrdinalIgnoreCase) .ThenBy(c => c.CompletionText, StringComparer.OrdinalIgnoreCase)); }