From 9f6a54c1fdefb6039e43d7461cfc9570e64781de Mon Sep 17 00:00:00 2001 From: David Wengier Date: Fri, 2 Dec 2022 13:22:43 +1100 Subject: [PATCH] Have a separate feature flag for single server diagnostics, that defaults to off --- .../DefaultLanguageServerFeatureOptions.cs | 2 ++ .../Diagnostics/RazorPullDiagnosticsEndpoint.cs | 6 +++--- .../LanguageServerFeatureOptions.cs | 2 ++ .../HtmlCSharp/InitializeHandler.cs | 4 ++++ ...VisualStudioWindowsLanguageServerFeatureOptions.cs | 11 +++++++++++ .../VisualStudioMacLanguageServerFeatureOptions.cs | 2 ++ ...icrosoft.VisualStudio.RazorExtension.Custom.pkgdef | 6 ++++++ .../TestLanguageServerFeatureOptions.cs | 2 ++ 8 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultLanguageServerFeatureOptions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultLanguageServerFeatureOptions.cs index e21c3c8bcb..bd53b54103 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultLanguageServerFeatureOptions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultLanguageServerFeatureOptions.cs @@ -19,4 +19,6 @@ internal class DefaultLanguageServerFeatureOptions : LanguageServerFeatureOption public override bool SingleServerCompletionSupport => false; public override bool SingleServerSupport => false; + + public override bool SingleServerDiagnosticsSupport => false; } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorPullDiagnosticsEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorPullDiagnosticsEndpoint.cs index 0d80bad55d..327d541121 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorPullDiagnosticsEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorPullDiagnosticsEndpoint.cs @@ -49,13 +49,13 @@ internal class RazorPullDiagnosticsEndpoint public async Task?> HandleRequestAsync(VSInternalDocumentDiagnosticsParams request, RazorRequestContext context, CancellationToken cancellationToken) { - var documentContext = context.GetRequiredDocumentContext(); - - if (!_languageServerFeatureOptions.SingleServerSupport) + if (!_languageServerFeatureOptions.SingleServerDiagnosticsSupport) { return default; } + var documentContext = context.GetRequiredDocumentContext(); + var delegatedParams = new DelegatedDiagnosticParams(documentContext.Identifier); var delegatedResponse = await _languageServer.SendRequestAsync>( diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LanguageServerFeatureOptions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LanguageServerFeatureOptions.cs index 85382c6908..8b7068f0c9 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LanguageServerFeatureOptions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LanguageServerFeatureOptions.cs @@ -19,6 +19,8 @@ internal abstract class LanguageServerFeatureOptions public abstract bool SingleServerSupport { get; } + public abstract bool SingleServerDiagnosticsSupport { get; } + public string GetRazorCSharpFilePath(string razorFilePath) => razorFilePath + CSharpVirtualDocumentSuffix; public string GetRazorHtmlFilePath(string razorFilePath) => razorFilePath + HtmlVirtualDocumentSuffix; diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/HtmlCSharp/InitializeHandler.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/HtmlCSharp/InitializeHandler.cs index 31a95f403d..89dc09269b 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/HtmlCSharp/InitializeHandler.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/HtmlCSharp/InitializeHandler.cs @@ -115,6 +115,10 @@ internal class InitializeHandler : IRequestHandler _singleServerCompletionSupport; private readonly Lazy _singleServerSupport; + private readonly Lazy _singleServerDiagnosticsSupport; [ImportingConstructor] public VisualStudioWindowsLanguageServerFeatureOptions(LSPEditorFeatureDetector lspEditorFeatureDetector) @@ -42,6 +44,13 @@ internal class VisualStudioWindowsLanguageServerFeatureOptions : LanguageServerF var singleServerEnabled = featureFlags.IsFeatureEnabled(SingleServerFeatureFlag, defaultValue: false); return singleServerEnabled; }); + + _singleServerDiagnosticsSupport = new Lazy(() => + { + var featureFlags = (IVsFeatureFlags)AsyncPackage.GetGlobalService(typeof(SVsFeatureFlags)); + var singleServerDiagnosticsEnabled = featureFlags.IsFeatureEnabled(SingleServerDiagnosticsFeatureFlag, defaultValue: false); + return singleServerDiagnosticsEnabled; + }); } // We don't currently support file creation operations on VS Codespaces or VS Liveshare @@ -58,5 +67,7 @@ internal class VisualStudioWindowsLanguageServerFeatureOptions : LanguageServerF public override bool SingleServerSupport => _singleServerSupport.Value; + public override bool SingleServerDiagnosticsSupport => _singleServerDiagnosticsSupport.Value; + private bool IsCodespacesOrLiveshare => _lspEditorFeatureDetector.IsRemoteClient() || _lspEditorFeatureDetector.IsLiveShareHost(); } diff --git a/src/Razor/src/Microsoft.VisualStudio.Mac.LanguageServices.Razor/VisualStudioMacLanguageServerFeatureOptions.cs b/src/Razor/src/Microsoft.VisualStudio.Mac.LanguageServices.Razor/VisualStudioMacLanguageServerFeatureOptions.cs index 12ce87d604..32c9cbb2d2 100644 --- a/src/Razor/src/Microsoft.VisualStudio.Mac.LanguageServices.Razor/VisualStudioMacLanguageServerFeatureOptions.cs +++ b/src/Razor/src/Microsoft.VisualStudio.Mac.LanguageServices.Razor/VisualStudioMacLanguageServerFeatureOptions.cs @@ -37,6 +37,8 @@ internal class VisualStudioMacLanguageServerFeatureOptions : LanguageServerFeatu public override bool SingleServerSupport => false; + public override bool SingleServerDiagnosticsSupport => false; + private bool IsCodespacesOrLiveshare => _lspEditorFeatureDetector.IsRemoteClient() || _lspEditorFeatureDetector.IsLiveShareHost(); } diff --git a/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Microsoft.VisualStudio.RazorExtension.Custom.pkgdef b/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Microsoft.VisualStudio.RazorExtension.Custom.pkgdef index 04cea85b9b..639960d343 100644 --- a/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Microsoft.VisualStudio.RazorExtension.Custom.pkgdef +++ b/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Microsoft.VisualStudio.RazorExtension.Custom.pkgdef @@ -53,4 +53,10 @@ "Description"="Enable single server support when editing Razor (ASP.NET Core)." "Value"=dword:00000001 "Title"="Enable enhanced Razor LSP server (requires restart)" +"PreviewPaneChannels"="IntPreview,int.main" + +[$RootKey$\FeatureFlags\Razor\LSP\SingleServerDiagnostics] +"Description"="Enable single server diagnostics support when editing Razor (ASP.NET Core)." +"Value"=dword:00000000 +"Title"="Enable enhanced Razor LSP diagnostics (requires restart)" "PreviewPaneChannels"="IntPreview,int.main" \ No newline at end of file diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test.Common/TestLanguageServerFeatureOptions.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test.Common/TestLanguageServerFeatureOptions.cs index 440cab6adf..a8e52858a7 100644 --- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test.Common/TestLanguageServerFeatureOptions.cs +++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test.Common/TestLanguageServerFeatureOptions.cs @@ -24,4 +24,6 @@ internal class TestLanguageServerFeatureOptions : LanguageServerFeatureOptions public override bool SingleServerCompletionSupport => false; public override bool SingleServerSupport => false; + + public override bool SingleServerDiagnosticsSupport => false; }