diff --git a/src/Features/LanguageServer/Protocol/Handler/Completion/CompletionHandler.cs b/src/Features/LanguageServer/Protocol/Handler/Completion/CompletionHandler.cs index fd9b01b503e82391accb2222aa14bbc8ad01df3f..85c161b08c475e7e500a15cef54a6576d3498e7f 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Completion/CompletionHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Completion/CompletionHandler.cs @@ -43,6 +43,8 @@ public CompletionHandler(ILspSolutionProvider solutionProvider) : base(solutionP var position = await document.GetPositionFromLinePositionAsync(ProtocolConversions.PositionToLinePosition(request.Position), cancellationToken).ConfigureAwait(false); + // Filter out snippets as they are not supported in the LSP client + // https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1139740 // Filter out unimported types for now as there are two issues with providing them: // 1. LSP client does not currently provide a way to provide detail text on the completion item to show the namespace. // https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1076759 @@ -51,6 +53,7 @@ public CompletionHandler(ILspSolutionProvider solutionProvider) : base(solutionP // 3. LSP client should support completion filters / expanders var documentOptions = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); var completionOptions = documentOptions + .WithChangedOption(CompletionOptions.SnippetsBehavior, SnippetsRule.NeverInclude) .WithChangedOption(CompletionOptions.ShowItemsFromUnimportedNamespaces, false) .WithChangedOption(CompletionServiceOptions.IsExpandedCompletion, false); diff --git a/src/Features/LanguageServer/ProtocolUnitTests/Completion/CompletionTests.cs b/src/Features/LanguageServer/ProtocolUnitTests/Completion/CompletionTests.cs index ad666ffb501e952df8f4e410b97088087eae3f81..3ffaa6cd8f1b103a14ff565939aec142288acaa5 100644 --- a/src/Features/LanguageServer/ProtocolUnitTests/Completion/CompletionTests.cs +++ b/src/Features/LanguageServer/ProtocolUnitTests/Completion/CompletionTests.cs @@ -60,6 +60,26 @@ void M() Assert.False(results.Any(item => "Console" == item.Label)); } + [Fact] + public async Task TestGetCompletionsDoesNotIncludeSnippetsAsync() + { + var markup = +@"class A +{ + {|caret:|} +}"; + using var workspace = CreateTestWorkspace(markup, out var locations); + var solution = workspace.CurrentSolution; + solution = solution.WithOptions(solution.Options + .WithChangedOption(CompletionOptions.SnippetsBehavior, LanguageNames.CSharp, SnippetsRule.AlwaysInclude)); + + var clientCapabilities = new LSP.VSClientCapabilities { SupportsVisualStudioExtensions = true }; + + var results = await RunGetCompletionsAsync(solution, locations["caret"].Single(), clientCapabilities); + + Assert.False(results.Any(item => "ctor" == item.Label)); + } + private static async Task RunGetCompletionsAsync(Solution solution, LSP.Location caret, LSP.ClientCapabilities clientCapabilities = null) => await GetLanguageServer(solution).ExecuteRequestAsync(LSP.Methods.TextDocumentCompletionName, CreateCompletionParams(caret), clientCapabilities, null, CancellationToken.None);