From 7a833789b80fae27020f7397d59a88f7cbf68618 Mon Sep 17 00:00:00 2001 From: "Stephen Weatherford (MSFT)" Date: Tue, 16 Jul 2024 13:48:55 -0700 Subject: [PATCH] CR: use record --- .../Helpers/LanguageServerHelper.cs | 2 +- .../Handlers/BicepCodeActionHandlerTests.cs | 3 ++- .../Handlers/BicepTextDocumentSyncHandlerTests.cs | 3 ++- src/Bicep.LangServer/IServiceCollectionExtensions.cs | 2 +- .../Options/BicepLangServerOptions.cs | 4 ++-- .../Options/IBicepLangServerOptions.cs | 12 ------------ src/Bicep.LangServer/Server.cs | 2 +- .../Utils/DocumentSelectorFactory.cs | 2 +- 8 files changed, 10 insertions(+), 20 deletions(-) delete mode 100644 src/Bicep.LangServer/Options/IBicepLangServerOptions.cs diff --git a/src/Bicep.LangServer.IntegrationTests/Helpers/LanguageServerHelper.cs b/src/Bicep.LangServer.IntegrationTests/Helpers/LanguageServerHelper.cs index a6e08f7d1d2..939c1d32e98 100644 --- a/src/Bicep.LangServer.IntegrationTests/Helpers/LanguageServerHelper.cs +++ b/src/Bicep.LangServer.IntegrationTests/Helpers/LanguageServerHelper.cs @@ -40,7 +40,7 @@ public static async Task StartServer(TestContext testConte var serverPipe = new Pipe(); var server = new Server( - new BicepLangServerOptions(), + BicepLangServerOptions.Default, options => options .WithInput(serverPipe.Reader) .WithOutput(clientPipe.Writer) diff --git a/src/Bicep.LangServer.UnitTests/Handlers/BicepCodeActionHandlerTests.cs b/src/Bicep.LangServer.UnitTests/Handlers/BicepCodeActionHandlerTests.cs index d6e8b9888d0..a8550b3c187 100644 --- a/src/Bicep.LangServer.UnitTests/Handlers/BicepCodeActionHandlerTests.cs +++ b/src/Bicep.LangServer.UnitTests/Handlers/BicepCodeActionHandlerTests.cs @@ -7,6 +7,7 @@ using Bicep.Core.UnitTests.Utils; using Bicep.LanguageServer; using Bicep.LanguageServer.Handlers; +using Bicep.LanguageServer.Options; using Bicep.LanguageServer.Providers; using Bicep.LanguageServer.Utils; using FluentAssertions; @@ -63,7 +64,7 @@ private async Task> GetCodeActions( clientCapabilitiesProvider.Setup(m => m.DoesClientSupportShowDocumentRequest()).Returns(clientSupportShowDocumentRequestAndWorkspaceFolders); clientCapabilitiesProvider.Setup(m => m.DoesClientSupportWorkspaceFolders()).Returns(clientSupportShowDocumentRequestAndWorkspaceFolders); - var bicepEditLinterRuleHandler = new BicepCodeActionHandler(bicepCompilationManager, clientCapabilitiesProvider.Object, new DocumentSelectorFactory(null)); + var bicepEditLinterRuleHandler = new BicepCodeActionHandler(bicepCompilationManager, clientCapabilitiesProvider.Object, new DocumentSelectorFactory(BicepLangServerOptions.Default)); var range = new Range() { diff --git a/src/Bicep.LangServer.UnitTests/Handlers/BicepTextDocumentSyncHandlerTests.cs b/src/Bicep.LangServer.UnitTests/Handlers/BicepTextDocumentSyncHandlerTests.cs index 06609af9fbd..3a0e0cad170 100644 --- a/src/Bicep.LangServer.UnitTests/Handlers/BicepTextDocumentSyncHandlerTests.cs +++ b/src/Bicep.LangServer.UnitTests/Handlers/BicepTextDocumentSyncHandlerTests.cs @@ -9,6 +9,7 @@ using Bicep.LangServer.IntegrationTests.Helpers; using Bicep.LanguageServer.Configuration; using Bicep.LanguageServer.Handlers; +using Bicep.LanguageServer.Options; using Bicep.LanguageServer.Telemetry; using Bicep.LanguageServer.Utils; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -197,7 +198,7 @@ private async Task ChangeLinterRuleState(Mock telemetryProvi new Workspace()); - var bicepTextDocumentSyncHandler = new BicepTextDocumentSyncHandler(compilationManager, bicepConfigChangeHandler, new DocumentSelectorFactory(null)); + var bicepTextDocumentSyncHandler = new BicepTextDocumentSyncHandler(compilationManager, bicepConfigChangeHandler, new DocumentSelectorFactory(BicepLangServerOptions.Default)); await bicepTextDocumentSyncHandler.Handle(TextDocumentParamHelper.CreateDidOpenDocumentParams(bicepConfigUri, prevBicepConfigFileContents, 1), CancellationToken.None); diff --git a/src/Bicep.LangServer/IServiceCollectionExtensions.cs b/src/Bicep.LangServer/IServiceCollectionExtensions.cs index 86b60a5923e..fbe19292b34 100644 --- a/src/Bicep.LangServer/IServiceCollectionExtensions.cs +++ b/src/Bicep.LangServer/IServiceCollectionExtensions.cs @@ -56,7 +56,7 @@ public static IServiceCollection AddBicepDecompiler(this IServiceCollection serv public static IServiceCollection AddServerDependencies( this IServiceCollection services, - IBicepLangServerOptions bicepLangServerOptions + BicepLangServerOptions bicepLangServerOptions ) => services .AddBicepCore() .AddBicepDecompiler() diff --git a/src/Bicep.LangServer/Options/BicepLangServerOptions.cs b/src/Bicep.LangServer/Options/BicepLangServerOptions.cs index 6c5d95b3ac7..7e4a96a6d06 100644 --- a/src/Bicep.LangServer/Options/BicepLangServerOptions.cs +++ b/src/Bicep.LangServer/Options/BicepLangServerOptions.cs @@ -6,7 +6,7 @@ namespace Bicep.LanguageServer.Options; -public class BicepLangServerOptions : IBicepLangServerOptions +public record BicepLangServerOptions(bool VsCompatibilityMode = false) { - public bool VsCompatibilityMode { get; set; } + public static BicepLangServerOptions Default = new(); } diff --git a/src/Bicep.LangServer/Options/IBicepLangServerOptions.cs b/src/Bicep.LangServer/Options/IBicepLangServerOptions.cs deleted file mode 100644 index c9e8b18485d..00000000000 --- a/src/Bicep.LangServer/Options/IBicepLangServerOptions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Bicep.LanguageServer.Options; - -public interface IBicepLangServerOptions -{ - public bool VsCompatibilityMode { get; set; } -} diff --git a/src/Bicep.LangServer/Server.cs b/src/Bicep.LangServer/Server.cs index 5650c0c5cca..ac989eaeb79 100644 --- a/src/Bicep.LangServer/Server.cs +++ b/src/Bicep.LangServer/Server.cs @@ -24,7 +24,7 @@ namespace Bicep.LanguageServer public class Server : IDisposable { private readonly OmnisharpLanguageServer server; - public Server(IBicepLangServerOptions bicepLangServerOptions, Action onOptionsFunc) + public Server(BicepLangServerOptions bicepLangServerOptions, Action onOptionsFunc) { server = OmnisharpLanguageServer.PreInit(options => { diff --git a/src/Bicep.LangServer/Utils/DocumentSelectorFactory.cs b/src/Bicep.LangServer/Utils/DocumentSelectorFactory.cs index f7308dcc385..c8ed7d1d7dd 100644 --- a/src/Bicep.LangServer/Utils/DocumentSelectorFactory.cs +++ b/src/Bicep.LangServer/Utils/DocumentSelectorFactory.cs @@ -9,7 +9,7 @@ namespace Bicep.LanguageServer.Utils { - public class DocumentSelectorFactory(IBicepLangServerOptions? langServerOptions) + public class DocumentSelectorFactory(BicepLangServerOptions langServerOptions) { private static string Glob(params string[] extensions) {