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 283797cbdfc..57377920664 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs @@ -59,19 +59,16 @@ public static void AddLifeCycleServices(this IServiceCollection services, RazorL services.AddSingleton(clientConnection); } - public static void AddFormattingServices(this IServiceCollection services, LanguageServerFeatureOptions featureOptions) + public static void AddFormattingServices(this IServiceCollection services) { // Formatting services.AddSingleton(); - if (!featureOptions.UseRazorCohostServer) - { - services.AddSingleton(); + services.AddSingleton(); - services.AddHandlerWithCapabilities(); - services.AddHandlerWithCapabilities(); - services.AddHandlerWithCapabilities(); - } + services.AddHandlerWithCapabilities(); + services.AddHandlerWithCapabilities(); + services.AddHandlerWithCapabilities(); } public static void AddCompletionServices(this IServiceCollection services) @@ -113,17 +110,14 @@ public static void AddHoverServices(this IServiceCollection services) services.AddHandlerWithCapabilities(); } - public static void AddSemanticTokensServices(this IServiceCollection services, LanguageServerFeatureOptions featureOptions) + public static void AddSemanticTokensServices(this IServiceCollection services) { - if (!featureOptions.UseRazorCohostServer) - { - services.AddHandlerWithCapabilities(); - // Ensure that we don't add the default service if something else has added one. - services.TryAddSingleton(); - services.AddSingleton(); + services.AddHandlerWithCapabilities(); + // Ensure that we don't add the default service if something else has added one. + services.TryAddSingleton(); + services.AddSingleton(); - services.AddSingleton(); - } + services.AddSingleton(); services.AddHandler(); @@ -168,18 +162,15 @@ public static void AddCodeActionsServices(this IServiceCollection services) services.AddSingleton(); } - public static void AddTextDocumentServices(this IServiceCollection services, LanguageServerFeatureOptions featureOptions) + public static void AddTextDocumentServices(this IServiceCollection services) { - if (!featureOptions.UseRazorCohostServer) - { - services.AddHandlerWithCapabilities(); - services.AddHandlerWithCapabilities(); - - services.AddSingleton(); - services.AddSingleton(); - services.AddHandlerWithCapabilities(); - services.AddHandler(); - } + services.AddHandlerWithCapabilities(); + services.AddHandlerWithCapabilities(); + + services.AddSingleton(); + services.AddSingleton(); + services.AddHandlerWithCapabilities(); + services.AddHandler(); services.AddHandlerWithCapabilities(); services.AddHandler(); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/GeneratedDocumentSynchronizer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/GeneratedDocumentSynchronizer.cs index d1f96409fdb..0596eda8c2a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/GeneratedDocumentSynchronizer.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/GeneratedDocumentSynchronizer.cs @@ -34,13 +34,9 @@ public void DocumentProcessed(RazorCodeDocument codeDocument, DocumentSnapshot d return; } - // If cohosting is on, then it is responsible for updating the Html buffer - if (!_languageServerFeatureOptions.UseRazorCohostServer) - { - var htmlText = codeDocument.GetHtmlSourceText(); + var htmlText = codeDocument.GetHtmlSourceText(); - _publisher.PublishHtml(document.Project.Key, filePath, htmlText, hostDocumentVersion); - } + _publisher.PublishHtml(document.Project.Key, filePath, htmlText, hostDocumentVersion); var csharpText = codeDocument.GetCSharpSourceText(); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs index dda62959a52..e89231471fe 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs @@ -82,7 +82,7 @@ public void Dispose() _jsonRpc.Dispose(); } - private static ILspLogger CreateILspLogger(ILoggerFactory loggerFactory, ITelemetryReporter telemetryReporter) + private static ClaspLoggingBridge CreateILspLogger(ILoggerFactory loggerFactory, ITelemetryReporter telemetryReporter) { return new ClaspLoggingBridge(loggerFactory, telemetryReporter); } @@ -127,40 +127,37 @@ protected override ILspServices ConstructLspServices() services.AddLifeCycleServices(this, _clientConnection, _lspServerActivationTracker); - services.AddSemanticTokensServices(featureOptions); + services.AddSemanticTokensServices(); services.AddDocumentManagementServices(); - services.AddFormattingServices(featureOptions); + services.AddFormattingServices(); services.AddOptionsServices(_lspOptions); - services.AddTextDocumentServices(featureOptions); + services.AddTextDocumentServices(); - if (!featureOptions.UseRazorCohostServer) - { - // Diagnostics - services.AddDiagnosticServices(); + // Diagnostics + services.AddDiagnosticServices(); - services.AddCodeActionsServices(); + services.AddCodeActionsServices(); - // Completion - services.AddCompletionServices(); + // Completion + services.AddCompletionServices(); - // Auto insert - services.AddSingleton(); - services.AddSingleton(); + // Auto insert + services.AddSingleton(); + services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); - // Folding Range Providers - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + // Folding Range Providers + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); - // Hover - services.AddHoverServices(); - } + // Hover + services.AddHoverServices(); // Other services.AddSingleton(); @@ -171,13 +168,13 @@ protected override ILspServices ConstructLspServices() // Defaults: For when the caller hasn't provided them through the `configure` action. services.TryAddSingleton(); - AddHandlers(services, featureOptions); + AddHandlers(services); var lspServices = new LspServices(services); return lspServices; - static void AddHandlers(IServiceCollection services, LanguageServerFeatureOptions featureOptions) + static void AddHandlers(IServiceCollection services) { // Not calling AddHandler because we want to register this endpoint as an IOnInitialized too services.AddSingleton(); @@ -185,40 +182,37 @@ static void AddHandlers(IServiceCollection services, LanguageServerFeatureOption // Transient because it should only be used once and I'm hoping it doesn't stick around. services.AddTransient(sp => sp.GetRequiredService()); - if (!featureOptions.UseRazorCohostServer) - { - services.AddHandlerWithCapabilities(); + services.AddHandlerWithCapabilities(); - services.AddSingleton(); - services.AddHandlerWithCapabilities(); + services.AddSingleton(); + services.AddHandlerWithCapabilities(); - services.AddSingleton(); - services.AddHandlerWithCapabilities(); + services.AddSingleton(); + services.AddHandlerWithCapabilities(); - services.AddHandlerWithCapabilities(); - services.AddHandlerWithCapabilities(); - services.AddHandlerWithCapabilities(); - services.AddHandlerWithCapabilities(); - services.AddHandlerWithCapabilities(); + services.AddHandlerWithCapabilities(); + services.AddHandlerWithCapabilities(); + services.AddHandlerWithCapabilities(); + services.AddHandlerWithCapabilities(); + services.AddHandlerWithCapabilities(); - services.AddSingleton(); - services.AddHandlerWithCapabilities(); - services.AddHandler(); + services.AddSingleton(); + services.AddHandlerWithCapabilities(); + services.AddHandler(); - services.AddHandlerWithCapabilities(); - services.AddSingleton(); + services.AddHandlerWithCapabilities(); + services.AddSingleton(); - services.AddHandlerWithCapabilities(); - services.AddHandler(); + services.AddHandlerWithCapabilities(); + services.AddHandler(); - services.AddHandlerWithCapabilities(); + services.AddHandlerWithCapabilities(); - services.AddHandlerWithCapabilities(); + services.AddHandlerWithCapabilities(); - services.AddHandlerWithCapabilities(); - services.AddHandler(); - services.AddHandler(); - } + services.AddHandlerWithCapabilities(); + services.AddHandler(); + services.AddHandler(); services.AddHandler(); diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Endpoints/RazorCustomMessageTarget.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Endpoints/RazorCustomMessageTarget.cs index 11e7cebb5bb..216e29b3a61 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Endpoints/RazorCustomMessageTarget.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Endpoints/RazorCustomMessageTarget.cs @@ -9,14 +9,12 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.ProjectSystem; using Microsoft.AspNetCore.Razor.Telemetry; -using Microsoft.CodeAnalysis.ExternalAccess.Razor; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.VisualStudio.LanguageServer.ContainedLanguage; using Microsoft.VisualStudio.LanguageServer.Protocol; -using Microsoft.VisualStudio.Razor.LanguageClient.Cohost; using Microsoft.VisualStudio.Razor.Settings; using Microsoft.VisualStudio.Razor.Snippets; using Microsoft.VisualStudio.Text; @@ -35,8 +33,6 @@ internal partial class RazorCustomMessageTarget private readonly LanguageServerFeatureOptions _languageServerFeatureOptions; private readonly ProjectSnapshotManager _projectManager; private readonly SnippetCompletionItemProvider _snippetCompletionItemProvider; - private readonly IWorkspaceProvider _workspaceProvider; - private readonly IHtmlDocumentSynchronizer _htmlDocumentSynchronizer; private readonly FormattingOptionsProvider _formattingOptionsProvider; private readonly IClientSettingsManager _editorSettingsManager; private readonly LSPDocumentSynchronizer _documentSynchronizer; @@ -56,25 +52,13 @@ public RazorCustomMessageTarget( LanguageServerFeatureOptions languageServerFeatureOptions, ProjectSnapshotManager projectManager, SnippetCompletionItemProvider snippetCompletionItemProvider, - IWorkspaceProvider workspaceProvider, - IHtmlDocumentSynchronizer htmlDocumentSynchronizer, ILoggerFactory loggerFactory) { - if (documentManager is null) - { - throw new ArgumentNullException(nameof(documentManager)); - } - if (documentManager is not TrackingLSPDocumentManager trackingDocumentManager) { throw new ArgumentException($"The LSP document manager should be of type {typeof(TrackingLSPDocumentManager).FullName}", nameof(documentManager)); } - if (joinableTaskContext is null) - { - throw new ArgumentNullException(nameof(joinableTaskContext)); - } - _documentManager = trackingDocumentManager; _joinableTaskFactory = joinableTaskContext.Factory; @@ -87,8 +71,6 @@ public RazorCustomMessageTarget( _languageServerFeatureOptions = languageServerFeatureOptions ?? throw new ArgumentNullException(nameof(languageServerFeatureOptions)); _projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager)); _snippetCompletionItemProvider = snippetCompletionItemProvider ?? throw new ArgumentNullException(nameof(snippetCompletionItemProvider)); - _workspaceProvider = workspaceProvider; - _htmlDocumentSynchronizer = htmlDocumentSynchronizer; _logger = loggerFactory.GetOrCreateLogger(); } @@ -133,19 +115,13 @@ public RazorCustomMessageTarget( private record struct DelegationRequestDetails(string LanguageServerName, Uri ProjectedUri, ITextBuffer TextBuffer); private async Task> TrySynchronizeVirtualDocumentAsync( - int requiredHostDocumentVersion, - TextDocumentIdentifier hostDocument, - CancellationToken cancellationToken, - bool rejectOnNewerParallelRequest = true, - [CallerMemberName] string? caller = null) - where TVirtualDocumentSnapshot : VirtualDocumentSnapshot + int requiredHostDocumentVersion, + TextDocumentIdentifier hostDocument, + CancellationToken cancellationToken, + bool rejectOnNewerParallelRequest = true, + [CallerMemberName] string? caller = null) + where TVirtualDocumentSnapshot : VirtualDocumentSnapshot { - if (_languageServerFeatureOptions.UseRazorCohostServer && - typeof(TVirtualDocumentSnapshot) == typeof(HtmlVirtualDocumentSnapshot)) - { - return await TempForCohost_TrySynchronizeVirtualDocumentAsync(hostDocument, cancellationToken); - } - _logger.LogDebug($"Trying to synchronize for {caller} to version {requiredHostDocumentVersion} of {hostDocument.Uri} for {hostDocument.GetProjectContext()?.Id ?? "(no project context)"}"); // For Html documents we don't do anything fancy, just call the standard service @@ -205,47 +181,6 @@ private async Task> TrySynchronizeV return result; } - private async Task> TempForCohost_TrySynchronizeVirtualDocumentAsync(TextDocumentIdentifier hostDocument, CancellationToken cancellationToken) - where TVirtualDocumentSnapshot : VirtualDocumentSnapshot - { - Debug.Assert(typeof(TVirtualDocumentSnapshot) == typeof(HtmlVirtualDocumentSnapshot)); - // Cohosting is responsible for Html, so we have to go through its service instead - var workspace = _workspaceProvider.GetWorkspace(); - var documentIds = workspace.CurrentSolution.GetDocumentIdsWithFilePath(RazorUri.GetDocumentFilePathFromUri(hostDocument.Uri)); - - if (documentIds.Length != 1) - { - _logger.LogError($"Couldn't get document id from the workspace for {hostDocument.Uri}"); - return new SynchronizedResult(false, null); - } - - var document = workspace.CurrentSolution.GetAdditionalDocument(documentIds[0]); - if (document is null) - { - _logger.LogError($"Couldn't get document from the workspace for {documentIds[0]} which should be {hostDocument.Uri}"); - return new SynchronizedResult(false, null); - } - - if (!await _htmlDocumentSynchronizer.TrySynchronizeAsync(document, cancellationToken).ConfigureAwait(false)) - { - return new SynchronizedResult(false, null); - } - - if (!_documentManager.TryGetDocument(hostDocument.Uri, out var snapshot)) - { - _logger.LogError($"Couldn't find document in LSPDocumentManager for {hostDocument.Uri}"); - return new SynchronizedResult(false, null); - } - - if (!snapshot.TryGetVirtualDocument(out var virtualDocument)) - { - _logger.LogError($"Couldn't find virtual document snapshot for {hostDocument.Uri}"); - return new SynchronizedResult(false, null); - } - - return new SynchronizedResult(true, virtualDocument); - } - private SynchronizedResult? TryReturnPossiblyFutureSnapshot( int requiredHostDocumentVersion, TextDocumentIdentifier hostDocument) where TVirtualDocumentSnapshot : VirtualDocumentSnapshot diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverEndpointTest.cs index 4fc39e2caaf..25c4261ba97 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverEndpointTest.cs @@ -34,8 +34,7 @@ public async Task Handle_Hover_SingleServer_CallsDelegatedLanguageServer() { // Arrange var languageServerFeatureOptions = StrictMock.Of(options => - options.SingleServerSupport == true && - options.UseRazorCohostServer == false); + options.SingleServerSupport == true); var delegatedHover = new LspHover(); @@ -195,8 +194,7 @@ public async Task Handle_Hover_SingleServer_AddTagHelper() options.SupportsFileManipulation == true && options.SingleServerSupport == true && options.CSharpVirtualDocumentSuffix == ".g.cs" && - options.HtmlVirtualDocumentSuffix == ".g.html" && - options.UseRazorCohostServer == false); + options.HtmlVirtualDocumentSuffix == ".g.html"); var languageServer = new HoverLanguageServer(csharpServer, csharpDocumentUri, DisposalToken); var documentMappingService = new LspDocumentMappingService(FilePathService, documentContextFactory, LoggerFactory); @@ -315,21 +313,14 @@ private HoverEndpoint CreateEndpoint( return endpoint; } - private class HoverLanguageServer : IClientConnection + private class HoverLanguageServer( + CSharpTestLspServer csharpServer, + Uri csharpDocumentUri, + CancellationToken cancellationToken) : IClientConnection { - private readonly CSharpTestLspServer _csharpServer; - private readonly Uri _csharpDocumentUri; - private readonly CancellationToken _cancellationToken; - - public HoverLanguageServer( - CSharpTestLspServer csharpServer, - Uri csharpDocumentUri, - CancellationToken cancellationToken) - { - _csharpServer = csharpServer; - _csharpDocumentUri = csharpDocumentUri; - _cancellationToken = cancellationToken; - } + private readonly CSharpTestLspServer _csharpServer = csharpServer; + private readonly Uri _csharpDocumentUri = csharpDocumentUri; + private readonly CancellationToken _cancellationToken = cancellationToken; public Task SendNotificationAsync(string method, TParams @params, CancellationToken cancellationToken) { diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorCustomMessageTargetTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorCustomMessageTargetTest.cs index 358c34cfb44..67c3804b637 100644 --- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorCustomMessageTargetTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorCustomMessageTargetTest.cs @@ -14,12 +14,10 @@ using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; -using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Razor.Workspaces.Protocol.SemanticTokens; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServer.ContainedLanguage; using Microsoft.VisualStudio.LanguageServer.Protocol; -using Microsoft.VisualStudio.Razor.LanguageClient.Cohost; using Microsoft.VisualStudio.Razor.Settings; using Microsoft.VisualStudio.Razor.Snippets; using Microsoft.VisualStudio.Text; @@ -65,8 +63,6 @@ public async Task UpdateCSharpBuffer_CannotLookupDocument_NoopsGracefully() TestLanguageServerFeatureOptions.Instance, CreateProjectSnapshotManager(), new SnippetCompletionItemProvider(new SnippetCache()), - StrictMock.Of(), - StrictMock.Of(), LoggerFactory); var request = new UpdateBufferRequest() { @@ -110,8 +106,6 @@ public async Task UpdateCSharpBuffer_UpdatesDocument() TestLanguageServerFeatureOptions.Instance, CreateProjectSnapshotManager(), new SnippetCompletionItemProvider(new SnippetCache()), - StrictMock.Of(), - StrictMock.Of(), LoggerFactory); var request = new UpdateBufferRequest() { @@ -166,8 +160,6 @@ public async Task UpdateCSharpBuffer_UpdatesCorrectDocument() new TestLanguageServerFeatureOptions(includeProjectKeyInGeneratedFilePath: true), CreateProjectSnapshotManager(), new SnippetCompletionItemProvider(new SnippetCache()), - StrictMock.Of(), - StrictMock.Of(), LoggerFactory); var request = new UpdateBufferRequest() { @@ -210,8 +202,6 @@ public async Task ProvideCodeActionsAsync_CannotLookupDocument_ReturnsNullAsync( TestLanguageServerFeatureOptions.Instance, CreateProjectSnapshotManager(), new SnippetCompletionItemProvider(new SnippetCache()), - StrictMock.Of(), - StrictMock.Of(), LoggerFactory); var request = new DelegatedCodeActionParams() { @@ -292,8 +282,6 @@ async IAsyncEnumerable> TestLanguageServerFeatureOptions.Instance, CreateProjectSnapshotManager(), new SnippetCompletionItemProvider(new SnippetCache()), - StrictMock.Of(), - StrictMock.Of(), LoggerFactory); var request = new DelegatedCodeActionParams() @@ -379,8 +367,6 @@ async IAsyncEnumerable> GetExpectedRe TestLanguageServerFeatureOptions.Instance, CreateProjectSnapshotManager(), new SnippetCompletionItemProvider(new SnippetCache()), - StrictMock.Of(), - StrictMock.Of(), LoggerFactory); var codeAction = new VSInternalCodeAction() @@ -421,8 +407,6 @@ public async Task ProvideSemanticTokensAsync_CannotLookupDocument_ReturnsNullAsy TestLanguageServerFeatureOptions.Instance, CreateProjectSnapshotManager(), new SnippetCompletionItemProvider(new SnippetCache()), - StrictMock.Of(), - StrictMock.Of(), LoggerFactory); var request = new ProvideSemanticTokensRangesParams( @@ -470,8 +454,6 @@ public async Task ProvideSemanticTokensAsync_CannotLookupVirtualDocument_Returns TestLanguageServerFeatureOptions.Instance, CreateProjectSnapshotManager(), new SnippetCompletionItemProvider(new SnippetCache()), - StrictMock.Of(), - StrictMock.Of(), LoggerFactory); var request = new ProvideSemanticTokensRangesParams( @@ -552,8 +534,6 @@ public async Task ProvideSemanticTokensAsync_ContainsRange_ReturnsSemanticTokens TestLanguageServerFeatureOptions.Instance, CreateProjectSnapshotManager(), new SnippetCompletionItemProvider(new SnippetCache()), - StrictMock.Of(), - StrictMock.Of(), LoggerFactory); var request = new ProvideSemanticTokensRangesParams( @@ -635,8 +615,6 @@ public async Task ProvideSemanticTokensAsync_EmptyRange_ReturnsNoSemanticTokens( TestLanguageServerFeatureOptions.Instance, CreateProjectSnapshotManager(), new SnippetCompletionItemProvider(new SnippetCache()), - StrictMock.Of(), - StrictMock.Of(), LoggerFactory); var request = new ProvideSemanticTokensRangesParams(