-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert endpoint to dynamic registration
- Loading branch information
1 parent
6bea738
commit ba73960
Showing
7 changed files
with
110 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...r/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Cohost/CohostEndpointAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; | ||
using Microsoft.CommonLanguageServerProtocol.Framework; | ||
|
||
namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Cohost; | ||
|
||
internal class CohostEndpointAttribute : LanguageServerEndpointAttribute | ||
{ | ||
public CohostEndpointAttribute(string method) | ||
: base(method, Constants.RazorLanguageName) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
...crosoft.VisualStudio.LanguageServerClient.Razor/Cohost/RazorCohostCapabilitiesProvider.cs
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
...t.VisualStudio.LanguageServerClient.Razor/Cohost/RazorCohostDynamicRegistrationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Composition; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Razor; | ||
using Microsoft.AspNetCore.Razor.LanguageServer.Common; | ||
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; | ||
using Microsoft.CodeAnalysis.Razor.Logging; | ||
using Microsoft.CodeAnalysis.Razor.SemanticTokens; | ||
using Microsoft.CodeAnalysis.Razor.Workspaces; | ||
using Microsoft.CodeAnalysis.Razor.Workspaces.Protocol; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.VisualStudio.LanguageServer.Protocol; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Cohost; | ||
|
||
[Shared] | ||
[Export(typeof(IRazorCohostDynamicRegistrationService))] | ||
[Export(typeof(IClientCapabilitiesService))] | ||
[method: ImportingConstructor] | ||
internal class RazorCohostDynamicRegistrationService(LanguageServerFeatureOptions languageServerFeatureOptions, Lazy<ISemanticTokensLegendService> semanticTokensLegendService, IRazorLoggerFactory loggerFactory) : IRazorCohostDynamicRegistrationService, IClientCapabilitiesService | ||
{ | ||
private readonly string _id = Guid.NewGuid().ToString(); | ||
private readonly DocumentFilter[] _filter = [new DocumentFilter() | ||
{ | ||
Language = Constants.RazorLanguageName, | ||
Pattern = "**/*.{razor,cshtml}" | ||
}]; | ||
|
||
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions; | ||
private readonly Lazy<ISemanticTokensLegendService> _semanticTokensLegendService = semanticTokensLegendService; | ||
private readonly ILogger _logger = loggerFactory.CreateLogger<RazorCohostDynamicRegistrationService>(); | ||
|
||
private VSInternalClientCapabilities? _clientCapabilities; | ||
|
||
public bool CanGetClientCapabilities => _clientCapabilities is not null; | ||
|
||
public VSInternalClientCapabilities ClientCapabilities => _clientCapabilities.AssumeNotNull(); | ||
|
||
public async Task RegisterAsync(string clientCapabilities, IRazorCohostClientLanguageServerManager razorCohostClientLanguageServerManager, CancellationToken cancellationToken) | ||
{ | ||
if (!_languageServerFeatureOptions.UseRazorCohostServer) | ||
{ | ||
return; | ||
} | ||
|
||
_clientCapabilities = JsonConvert.DeserializeObject<VSInternalClientCapabilities>(clientCapabilities) ?? new(); | ||
|
||
// TODO: Get the options from the from the endpoints somehow | ||
if (_clientCapabilities.TextDocument?.SemanticTokens?.DynamicRegistration == true) | ||
{ | ||
await razorCohostClientLanguageServerManager.SendRequestAsync( | ||
Methods.ClientRegisterCapabilityName, | ||
new RegistrationParams() | ||
{ | ||
Registrations = [ | ||
new Registration() | ||
{ | ||
Id = _id, | ||
Method = Methods.TextDocumentSemanticTokensRangeName, | ||
RegisterOptions = new SemanticTokensRegistrationOptions() | ||
{ | ||
DocumentSelector = _filter, | ||
}.EnableSemanticTokens(_semanticTokensLegendService.Value) | ||
} | ||
] | ||
}, | ||
cancellationToken).ConfigureAwait(false); | ||
} | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
...ualStudio.LanguageServerClient.Razor/Cohost/RazorCohostLanguageClientActivationService.cs
This file was deleted.
Oops, something went wrong.