From 00a1134ad8241e10cf15bd883cc19b423be2bacd Mon Sep 17 00:00:00 2001 From: David Barbet Date: Mon, 29 Jun 2020 14:07:15 -0700 Subject: [PATCH] Remove snippets from completion list until they are supported --- .../Handler/Completion/CompletionHandler.cs | 3 +++ .../Completion/CompletionTests.cs | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Features/LanguageServer/Protocol/Handler/Completion/CompletionHandler.cs b/src/Features/LanguageServer/Protocol/Handler/Completion/CompletionHandler.cs index fd9b01b503e..85c161b08c4 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 ad666ffb501..933ad0d1a3d 100644 --- a/src/Features/LanguageServer/ProtocolUnitTests/Completion/CompletionTests.cs +++ b/src/Features/LanguageServer/ProtocolUnitTests/Completion/CompletionTests.cs @@ -60,6 +60,27 @@ 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 expected = CreateCompletionItem("A", LSP.CompletionItemKind.Class, new string[] { "Class", "Internal" }, CreateCompletionParams(locations["caret"].Single())); + 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); -- GitLab