Merge pull request #8503 from dotnet/bugfix-completion-regression

Brings back `GetRegistration` for `RazorCompletionResolveEndpoint`
This commit is contained in:
Maryam Ariyan 2023-03-23 17:05:51 -04:00 коммит произвёл GitHub
Родитель d26d2072b8 3478a321e3
Коммит 87ff0af6ca
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 26 добавлений и 14 удалений

Просмотреть файл

@ -11,7 +11,7 @@ using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion; namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion;
internal class RazorCompletionResolveEndpoint : IVSCompletionResolveEndpoint, IOnInitialized internal class RazorCompletionResolveEndpoint : IVSCompletionResolveEndpoint, IRegistrationExtension
{ {
private readonly AggregateCompletionItemResolver _completionItemResolver; private readonly AggregateCompletionItemResolver _completionItemResolver;
private readonly CompletionListCache _completionListCache; private readonly CompletionListCache _completionListCache;
@ -27,11 +27,11 @@ internal class RazorCompletionResolveEndpoint : IVSCompletionResolveEndpoint, IO
public bool MutatesSolutionState => false; public bool MutatesSolutionState => false;
public Task OnInitializedAsync(VSInternalClientCapabilities clientCapabilities, CancellationToken cancellationToken) public RegistrationExtensionResult? GetRegistration(VSInternalClientCapabilities clientCapabilities)
{ {
_clientCapabilities = clientCapabilities.ToVSInternalClientCapabilities(); _clientCapabilities = clientCapabilities.ToVSInternalClientCapabilities();
return Task.CompletedTask; return null;
} }
public async Task<VSInternalCompletionItem> HandleRequestAsync(VSInternalCompletionItem completionItem, RazorRequestContext requestContext, CancellationToken cancellationToken) public async Task<VSInternalCompletionItem> HandleRequestAsync(VSInternalCompletionItem completionItem, RazorRequestContext requestContext, CancellationToken cancellationToken)

Просмотреть файл

@ -70,7 +70,7 @@ internal static class IServiceCollectionExtensions
if (featureOptions.SingleServerCompletionSupport) if (featureOptions.SingleServerCompletionSupport)
{ {
services.AddRegisteringHandler<RazorCompletionEndpoint>(); services.AddRegisteringHandler<RazorCompletionEndpoint>();
services.AddHandler<RazorCompletionResolveEndpoint>(); services.AddRegisteringHandler<RazorCompletionResolveEndpoint>();
} }
else else
{ {

Просмотреть файл

@ -7,5 +7,5 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer;
internal interface IRegistrationExtension internal interface IRegistrationExtension
{ {
RegistrationExtensionResult GetRegistration(VSInternalClientCapabilities clientCapabilities); RegistrationExtensionResult? GetRegistration(VSInternalClientCapabilities clientCapabilities);
} }

Просмотреть файл

@ -20,6 +20,7 @@ public class RazorCompletionResolveEndpointTest : LanguageServerTestBase
{ {
private readonly RazorCompletionResolveEndpoint _endpoint; private readonly RazorCompletionResolveEndpoint _endpoint;
private readonly CompletionListCache _completionListCache; private readonly CompletionListCache _completionListCache;
private readonly VSInternalClientCapabilities _clientCapabilities;
public RazorCompletionResolveEndpointTest(ITestOutputHelper testOutput) public RazorCompletionResolveEndpointTest(ITestOutputHelper testOutput)
: base(testOutput) : base(testOutput)
@ -29,11 +30,20 @@ public class RazorCompletionResolveEndpointTest : LanguageServerTestBase
new AggregateCompletionItemResolver( new AggregateCompletionItemResolver(
new[] { new TestCompletionItemResolver() }, LoggerFactory), new[] { new TestCompletionItemResolver() }, LoggerFactory),
_completionListCache); _completionListCache);
} _clientCapabilities = new VSInternalClientCapabilities()
{
protected override Task InitializeAsync() TextDocument = new TextDocumentClientCapabilities()
{ {
return _endpoint.OnInitializedAsync(new VSInternalClientCapabilities(), DisposalToken); Completion = new VSInternalCompletionSetting()
{
CompletionItem = new CompletionItemSetting()
{
DocumentationFormat = new[] { MarkupKind.Markdown },
}
}
}
};
_endpoint.GetRegistration(_clientCapabilities);
} }
[Fact] [Fact]
@ -83,7 +93,7 @@ public class RazorCompletionResolveEndpointTest : LanguageServerTestBase
var resolvedItem = await _endpoint.HandleRequestAsync(parameters, requestContext, DisposalToken); var resolvedItem = await _endpoint.HandleRequestAsync(parameters, requestContext, DisposalToken);
// Assert // Assert
Assert.NotNull(resolvedItem.Documentation); Assert.Equal("I was resolved using markdown", resolvedItem.Documentation.Value.First);
} }
[Fact] [Fact]
@ -103,7 +113,7 @@ public class RazorCompletionResolveEndpointTest : LanguageServerTestBase
var resolvedItem = await _endpoint.HandleRequestAsync(parameters, requestContext, DisposalToken); var resolvedItem = await _endpoint.HandleRequestAsync(parameters, requestContext, DisposalToken);
// Assert // Assert
Assert.NotNull(resolvedItem.Documentation); Assert.Equal("I was resolved using markdown", resolvedItem.Documentation.Value.First);
} }
[Fact] [Fact]
@ -132,7 +142,7 @@ public class RazorCompletionResolveEndpointTest : LanguageServerTestBase
var resolvedItem = await _endpoint.HandleRequestAsync(parameters, requestContext, DisposalToken); var resolvedItem = await _endpoint.HandleRequestAsync(parameters, requestContext, DisposalToken);
// Assert // Assert
Assert.NotNull(resolvedItem.Documentation); Assert.Equal("I was resolved using markdown", resolvedItem.Documentation.Value.First);
Assert.Same(completion2Context, resolvedItem.Data); Assert.Same(completion2Context, resolvedItem.Data);
} }
@ -155,7 +165,9 @@ public class RazorCompletionResolveEndpointTest : LanguageServerTestBase
VSInternalClientCapabilities clientCapabilities, VSInternalClientCapabilities clientCapabilities,
CancellationToken cancellationToken) 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; item.Data = originalRequestContext;
return Task.FromResult(item); return Task.FromResult(item);
} }