diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/Delegation/SnippetResponseRewriter.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/Delegation/SnippetResponseRewriter.cs index 520eeba432e..0b090d4e363 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/Delegation/SnippetResponseRewriter.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/Delegation/SnippetResponseRewriter.cs @@ -1,10 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -using System.Collections.Frozen; -using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.VisualStudio.LanguageServer.Protocol; @@ -14,20 +13,10 @@ namespace Microsoft.CodeAnalysis.Razor.Completion.Delegation; /// Modifies delegated snippet completion items /// /// -/// At the moment primarily used to modify C# "using" snippet to "using statement" snippet -/// in order to disambiguate it from Razor "using directive" snippet +/// At the moment primarily used to remove the C# "using" snippet because we have our own /// internal class SnippetResponseRewriter : IDelegatedCSharpCompletionResponseRewriter { - private static readonly FrozenDictionary s_snippetToCompletionData = new Dictionary() - { - // Modifying label of the C# using snippet to "using statement" to disambiguate from - // Razor @using directive, and also appending a space to sort text to make sure it's sorted - // after Razor "using" keyword and "using directive ..." entries (which use "using" as sort text) - ["using"] = (Label: $"using {SR.Statement}", SortText: "using ") - } - .ToFrozenDictionary(); - public Task RewriteAsync( VSInternalCompletionList completionList, int hostDocumentIndex, @@ -36,21 +25,22 @@ public Task RewriteAsync( RazorCompletionOptions completionOptions, CancellationToken cancellationToken) { + using var items = new PooledArrayBuilder(completionList.Items.Length); + foreach (var item in completionList.Items) { - if (item.Kind == CompletionItemKind.Snippet) + if (item is { Kind: CompletionItemKind.Snippet, Label: "using" }) { - if (item.Label is null) - { - continue; - } - - if (s_snippetToCompletionData.TryGetValue(item.Label, out var completionData)) - { - item.Label = completionData.Label; - item.SortText = completionData.SortText; - } + continue; } + + items.Add(item); + } + + // If we didn't remove anything, then don't bother materializing the array + if (completionList.Items.Length != items.Count) + { + completionList.Items = items.ToArray(); } return Task.FromResult(completionList); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/SR.resx b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/SR.resx index 442340fd995..0b98ecd9394 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/SR.resx +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/SR.resx @@ -193,9 +193,6 @@ Blazor directive attributes - - statement - Promote using directive to {0} diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.cs.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.cs.xlf index 6ff41b1e692..712a1aec14c 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.cs.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.cs.xlf @@ -109,11 +109,6 @@ Promote using directive to {0} - - statement - příkaz - - Razor TagHelper Attribute Glyph Piktogram atributu Razor TagHelper diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.de.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.de.xlf index b717f904acf..050c796ee1d 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.de.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.de.xlf @@ -109,11 +109,6 @@ Promote using directive to {0} - - statement - Anweisung - - Razor TagHelper Attribute Glyph Razor TagHelper-Attributsymbol diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.es.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.es.xlf index e0638d63512..baf0ad2104e 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.es.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.es.xlf @@ -109,11 +109,6 @@ Promote using directive to {0} - - statement - instrucción - - Razor TagHelper Attribute Glyph Glifo del atributo TagHelper de Razor diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.fr.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.fr.xlf index 72ac75265fb..52e49c3b3bd 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.fr.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.fr.xlf @@ -109,11 +109,6 @@ Promote using directive to {0} - - statement - déclaration - - Razor TagHelper Attribute Glyph Glyphe d’attribut Razor TagHelper diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.it.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.it.xlf index e8f4db0022c..f1cc06b27c9 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.it.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.it.xlf @@ -109,11 +109,6 @@ Promote using directive to {0} - - statement - istruzione - - Razor TagHelper Attribute Glyph Glifo attributo TagHelper Razor diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ja.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ja.xlf index ad91b7d997f..497ad8a8479 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ja.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ja.xlf @@ -109,11 +109,6 @@ Promote using directive to {0} - - statement - ステートメント - - Razor TagHelper Attribute Glyph Razor TagHelper 属性のグリフ diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ko.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ko.xlf index a4fd248e2a5..4e711f18112 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ko.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ko.xlf @@ -109,11 +109,6 @@ Promote using directive to {0} - - statement - - - Razor TagHelper Attribute Glyph Razor TagHelper 특성 문자 모양 diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pl.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pl.xlf index 6a0de777662..83415dfd000 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pl.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pl.xlf @@ -109,11 +109,6 @@ Promote using directive to {0} - - statement - instrukcja - - Razor TagHelper Attribute Glyph Symbol atrybutu pomocnika tagów składni Razor diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pt-BR.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pt-BR.xlf index 06059caf1a1..13bea0d9292 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pt-BR.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.pt-BR.xlf @@ -109,11 +109,6 @@ Promote using directive to {0} - - statement - instrução - - Razor TagHelper Attribute Glyph Atributo Glyph Razor TagHelper diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ru.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ru.xlf index 5d2051841c8..4b44a5fecc8 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ru.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.ru.xlf @@ -109,11 +109,6 @@ Promote using directive to {0} - - statement - инструкция - - Razor TagHelper Attribute Glyph Глиф атрибута TagHelper Razor diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.tr.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.tr.xlf index b1cb398c00e..ce72b044eb0 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.tr.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.tr.xlf @@ -109,11 +109,6 @@ Promote using directive to {0} - - statement - deyim - - Razor TagHelper Attribute Glyph Razor TagHelper Öznitelik Karakteri diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hans.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hans.xlf index 973acaa8b29..d2d008f34bb 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hans.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hans.xlf @@ -109,11 +109,6 @@ Promote using directive to {0} - - statement - 语句 - - Razor TagHelper Attribute Glyph Razor TagHelper 特性字形 diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hant.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hant.xlf index 8f7b9134772..3a47b07904e 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hant.xlf +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources/xlf/SR.zh-Hant.xlf @@ -109,11 +109,6 @@ Promote using directive to {0} - - statement - 陳述式 - - Razor TagHelper Attribute Glyph Razor TagHelper 屬性字元 diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/SnippetResponseRewriterTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/SnippetResponseRewriterTest.cs index 7de0121b894..5c14c8563b2 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/SnippetResponseRewriterTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/SnippetResponseRewriterTest.cs @@ -17,7 +17,7 @@ public class SnippetResponseRewriterTest(ITestOutputHelper testOutput) : ResponseRewriterTestBase(testOutput) { [Fact] - public async Task RewriteAsync_ChangesUsingSnippetLabel() + public async Task RewriteAsync_RemovesUsingSnippetLabel() { // Arrange var documentContent = "@$$"; @@ -37,11 +37,6 @@ public async Task RewriteAsync_ChangesUsingSnippetLabel() Assert.Collection( rewrittenCompletionList.Items, completion => - { - Assert.Equal("using statement", completion.Label); - Assert.Equal("using ", completion.SortText); - }, - completion => { Assert.Equal("if", completion.Label); Assert.Equal("if", completion.SortText);