From 4cd6e8868ce04380f08dd818197d184a80b58f51 Mon Sep 17 00:00:00 2001 From: Tanay Parikh Date: Tue, 16 Jun 2020 18:30:31 -0700 Subject: [PATCH] Added Directive [SPACE] Commit Character (#2043) * Added Directive [SPACE] Commit Character Fixes: https://github.com/dotnet/aspnetcore/issues/22886 * Refactor --- .../Completion/RazorCompletionEndpoint.cs | 1 + .../Completion/DirectiveCompletionItemProvider.cs | 5 ++++- .../Completion/DirectiveCompletionItemProviderTest.cs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionEndpoint.cs index 2d87f72a237..00d08fbbaa4 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionEndpoint.cs @@ -248,6 +248,7 @@ internal bool TryConvert(RazorCompletionItem razorCompletionItem, out Completion SortText = razorCompletionItem.DisplayText, Documentation = descriptionInfo.Description, Kind = CompletionItemKind.Struct, + CommitCharacters = new Container(razorCompletionItem.CommitCharacters), }; if (razorCompletionItem == DirectiveAttributeTransitionCompletionItemProvider.TransitionCompletionItem) diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/DirectiveCompletionItemProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/DirectiveCompletionItemProvider.cs index 6091d7ac7d8..3d4ce6debae 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/DirectiveCompletionItemProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/DirectiveCompletionItemProvider.cs @@ -15,6 +15,8 @@ namespace Microsoft.CodeAnalysis.Razor.Completion [Export(typeof(RazorCompletionItemProvider))] internal class DirectiveCompletionItemProvider : RazorCompletionItemProvider { + private static readonly IReadOnlyCollection DirectiveCommitCharacters = new string[] { " " }; + private static readonly IEnumerable DefaultDirectives = new[] { CSharpCodeParser.AddTagHelperDirectiveDescriptor, @@ -108,7 +110,8 @@ internal static List GetDirectiveCompletionItems(RazorSynta var completionItem = new RazorCompletionItem( completionDisplayText, directive.Directive, - RazorCompletionItemKind.Directive); + RazorCompletionItemKind.Directive, + DirectiveCommitCharacters); var completionDescription = new DirectiveCompletionDescription(directive.Description); completionItem.SetDirectiveCompletionDescription(completionDescription); completionItems.Add(completionItem); diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveCompletionItemProviderTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveCompletionItemProviderTest.cs index d8e9c4013e8..ffe7abc43a9 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveCompletionItemProviderTest.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Completion/DirectiveCompletionItemProviderTest.cs @@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Legacy; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Moq; using Xunit; namespace Microsoft.CodeAnalysis.Razor.Completion @@ -289,6 +288,7 @@ private static void AssertRazorCompletionItem(string completionDisplayText, Dire Assert.Equal(item.InsertText, directive.Directive); var completionDescription = item.GetDirectiveCompletionDescription(); Assert.Equal(directive.Description, completionDescription.Description); + Assert.Single(item.CommitCharacters, " "); } private static void AssertRazorCompletionItem(DirectiveDescriptor directive, RazorCompletionItem item) =>