From 5f3b6e93e571ebeec3c0fd93e847e42726ba6c2f Mon Sep 17 00:00:00 2001 From: Maryam Ariyan Date: Thu, 23 Mar 2023 11:17:55 -0700 Subject: [PATCH 1/3] The code was regressed earlier client capabilities was not being initialized anymore therefore the intellisense was showing up as default plain rather than being markdown showing full type name and colored Fixes #8488 --- .../Completion/RazorCompletionResolveEndpoint.cs | 6 +++--- .../Extensions/IServiceCollectionExtensions.cs | 2 +- .../IRegistrationExtension.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionResolveEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionResolveEndpoint.cs index da11390738..36cb682a47 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionResolveEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionResolveEndpoint.cs @@ -11,7 +11,7 @@ using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion; -internal class RazorCompletionResolveEndpoint : IVSCompletionResolveEndpoint, IOnInitialized +internal class RazorCompletionResolveEndpoint : IVSCompletionResolveEndpoint, IRegistrationExtension { private readonly AggregateCompletionItemResolver _completionItemResolver; private readonly CompletionListCache _completionListCache; @@ -27,11 +27,11 @@ internal class RazorCompletionResolveEndpoint : IVSCompletionResolveEndpoint, IO public bool MutatesSolutionState => false; - public Task OnInitializedAsync(VSInternalClientCapabilities clientCapabilities, CancellationToken cancellationToken) + public RegistrationExtensionResult? GetRegistration(VSInternalClientCapabilities clientCapabilities) { _clientCapabilities = clientCapabilities.ToVSInternalClientCapabilities(); - return Task.CompletedTask; + return null; } public async Task HandleRequestAsync(VSInternalCompletionItem completionItem, RazorRequestContext requestContext, CancellationToken cancellationToken) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs index 80ac74acc6..27afd2f2fa 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs @@ -70,7 +70,7 @@ internal static class IServiceCollectionExtensions if (featureOptions.SingleServerCompletionSupport) { services.AddRegisteringHandler(); - services.AddHandler(); + services.AddRegisteringHandler(); } else { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/IRegistrationExtension.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/IRegistrationExtension.cs index b1b2b7be8c..1811b7c11a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/IRegistrationExtension.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/IRegistrationExtension.cs @@ -7,5 +7,5 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer; internal interface IRegistrationExtension { - RegistrationExtensionResult GetRegistration(VSInternalClientCapabilities clientCapabilities); + RegistrationExtensionResult? GetRegistration(VSInternalClientCapabilities clientCapabilities); } From a56b775910cacb2ba032496041d1579dde383b6b Mon Sep 17 00:00:00 2001 From: Maryam Ariyan Date: Thu, 23 Mar 2023 12:26:17 -0700 Subject: [PATCH 2/3] Fix compile issue --- .../Completion/RazorCompletionResolveEndpointTest.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/RazorCompletionResolveEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/RazorCompletionResolveEndpointTest.cs index b33afe9b9d..9a9ab08cd7 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/RazorCompletionResolveEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/RazorCompletionResolveEndpointTest.cs @@ -31,11 +31,6 @@ public class RazorCompletionResolveEndpointTest : LanguageServerTestBase _completionListCache); } - protected override Task InitializeAsync() - { - return _endpoint.OnInitializedAsync(new VSInternalClientCapabilities(), DisposalToken); - } - [Fact] public async Task Handle_UncachedCompletionItem_NoChange() { From 3478a321e3aee3d331503911b277d570d63e27ed Mon Sep 17 00:00:00 2001 From: Maryam Ariyan Date: Thu, 23 Mar 2023 13:01:30 -0700 Subject: [PATCH 3/3] Update tests --- .../RazorCompletionResolveEndpointTest.cs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/RazorCompletionResolveEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/RazorCompletionResolveEndpointTest.cs index 9a9ab08cd7..08535aa678 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/RazorCompletionResolveEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/RazorCompletionResolveEndpointTest.cs @@ -20,6 +20,7 @@ public class RazorCompletionResolveEndpointTest : LanguageServerTestBase { private readonly RazorCompletionResolveEndpoint _endpoint; private readonly CompletionListCache _completionListCache; + private readonly VSInternalClientCapabilities _clientCapabilities; public RazorCompletionResolveEndpointTest(ITestOutputHelper testOutput) : base(testOutput) @@ -29,6 +30,20 @@ public class RazorCompletionResolveEndpointTest : LanguageServerTestBase new AggregateCompletionItemResolver( new[] { new TestCompletionItemResolver() }, LoggerFactory), _completionListCache); + _clientCapabilities = new VSInternalClientCapabilities() + { + TextDocument = new TextDocumentClientCapabilities() + { + Completion = new VSInternalCompletionSetting() + { + CompletionItem = new CompletionItemSetting() + { + DocumentationFormat = new[] { MarkupKind.Markdown }, + } + } + } + }; + _endpoint.GetRegistration(_clientCapabilities); } [Fact] @@ -78,7 +93,7 @@ public class RazorCompletionResolveEndpointTest : LanguageServerTestBase var resolvedItem = await _endpoint.HandleRequestAsync(parameters, requestContext, DisposalToken); // Assert - Assert.NotNull(resolvedItem.Documentation); + Assert.Equal("I was resolved using markdown", resolvedItem.Documentation.Value.First); } [Fact] @@ -98,7 +113,7 @@ public class RazorCompletionResolveEndpointTest : LanguageServerTestBase var resolvedItem = await _endpoint.HandleRequestAsync(parameters, requestContext, DisposalToken); // Assert - Assert.NotNull(resolvedItem.Documentation); + Assert.Equal("I was resolved using markdown", resolvedItem.Documentation.Value.First); } [Fact] @@ -127,7 +142,7 @@ public class RazorCompletionResolveEndpointTest : LanguageServerTestBase var resolvedItem = await _endpoint.HandleRequestAsync(parameters, requestContext, DisposalToken); // Assert - Assert.NotNull(resolvedItem.Documentation); + Assert.Equal("I was resolved using markdown", resolvedItem.Documentation.Value.First); Assert.Same(completion2Context, resolvedItem.Data); } @@ -150,7 +165,9 @@ public class RazorCompletionResolveEndpointTest : LanguageServerTestBase VSInternalClientCapabilities clientCapabilities, CancellationToken cancellationToken) { - item.Documentation = "I was resolved"; + var completionSupportedKinds = clientCapabilities?.TextDocument?.Completion?.CompletionItem?.DocumentationFormat; + var documentationKind = completionSupportedKinds?.Contains(MarkupKind.Markdown) == true ? MarkupKind.Markdown : MarkupKind.PlainText; + item.Documentation = "I was resolved using " + documentationKind.Value; item.Data = originalRequestContext; return Task.FromResult(item); }