From c12873008149cb869d16b7ee7f92eb47179beda4 Mon Sep 17 00:00:00 2001 From: David Wengier Date: Mon, 16 Sep 2024 15:00:12 +1000 Subject: [PATCH] Remove AdhocWorkspaceFactory from DI, and make it fully own the workspace it creates --- .../InlineCompletionEndPoint.cs | 13 +++++----- .../LspWorkspaceProvider.cs | 9 ++++--- .../RazorLanguageServer.cs | 1 - .../AdhocWorkspaceFactory.cs | 21 ++++++++++++++-- .../Formatting/FormattingContext.cs | 22 +++++------------ .../Formatting/RazorFormattingService.cs | 18 +++++++------- .../IAdhocWorkspaceFactory.cs | 9 ------- .../RemoteRazorFormattingService.cs | 4 ++-- .../RemoteAdhocWorkspaceFactory.cs | 12 ---------- .../FormattingContentValidationPassTest.cs | 10 ++++---- .../FormattingDiagnosticValidationPassTest.cs | 9 +++---- .../TestRazorFormattingService.cs | 4 ++-- .../TestAdhocWorkspaceFactory.cs | 24 ------------------- 13 files changed, 60 insertions(+), 96 deletions(-) delete mode 100644 src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/IAdhocWorkspaceFactory.cs delete mode 100644 src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoteAdhocWorkspaceFactory.cs delete mode 100644 src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestAdhocWorkspaceFactory.cs diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/InlineCompletion/InlineCompletionEndPoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/InlineCompletion/InlineCompletionEndPoint.cs index 671a119fa5..322158c4b0 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/InlineCompletion/InlineCompletionEndPoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/InlineCompletion/InlineCompletionEndPoint.cs @@ -29,7 +29,7 @@ internal sealed class InlineCompletionEndpoint( IDocumentMappingService documentMappingService, IClientConnection clientConnection, IFormattingCodeDocumentProvider formattingCodeDocumentProvider, - IAdhocWorkspaceFactory adhocWorkspaceFactory, + IHostServicesProvider hostServicesProvider, RazorLSPOptionsMonitor optionsMonitor, ILoggerFactory loggerFactory) : IRazorRequestHandler, ICapabilitiesProvider @@ -39,10 +39,10 @@ internal sealed class InlineCompletionEndpoint( "if", "indexer", "interface", "invoke", "iterator", "iterindex", "lock", "mbox", "namespace", "#if", "#region", "prop", "propfull", "propg", "sim", "struct", "svm", "switch", "try", "tryf", "unchecked", "unsafe", "using", "while"); - private readonly IDocumentMappingService _documentMappingService = documentMappingService ?? throw new ArgumentNullException(nameof(documentMappingService)); - private readonly IClientConnection _clientConnection = clientConnection ?? throw new ArgumentNullException(nameof(clientConnection)); + private readonly IDocumentMappingService _documentMappingService = documentMappingService; + private readonly IClientConnection _clientConnection = clientConnection; private readonly IFormattingCodeDocumentProvider _formattingCodeDocumentProvider = formattingCodeDocumentProvider; - private readonly IAdhocWorkspaceFactory _adhocWorkspaceFactory = adhocWorkspaceFactory ?? throw new ArgumentNullException(nameof(adhocWorkspaceFactory)); + private readonly IHostServicesProvider _hostServicesProvider = hostServicesProvider; private readonly RazorLSPOptionsMonitor _optionsMonitor = optionsMonitor; private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); @@ -128,13 +128,14 @@ internal sealed class InlineCompletionEndpoint( } var options = RazorFormattingOptions.From(request.Options, _optionsMonitor.CurrentValue.CodeBlockBraceOnNextLine); - using var formattingContext = FormattingContext.Create( + using var adhocWorkspaceFactory = new AdhocWorkspaceFactory(_hostServicesProvider); + var formattingContext = FormattingContext.Create( request.TextDocument.Uri, documentContext.Snapshot, codeDocument, options, _formattingCodeDocumentProvider, - _adhocWorkspaceFactory); + adhocWorkspaceFactory); if (!TryGetSnippetWithAdjustedIndentation(formattingContext, item.Text, hostDocumentIndex, out var newSnippetText)) { continue; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LspWorkspaceProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LspWorkspaceProvider.cs index e6e0e83aeb..a30b824634 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LspWorkspaceProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LspWorkspaceProvider.cs @@ -7,11 +7,10 @@ using Microsoft.CodeAnalysis.Razor.Workspaces; namespace Microsoft.AspNetCore.Razor.LanguageServer; -internal sealed class LspWorkspaceProvider(IAdhocWorkspaceFactory workspaceFactory) : IWorkspaceProvider, IDisposable +internal sealed class LspWorkspaceProvider(IHostServicesProvider hostServicesProvider) : IWorkspaceProvider, IDisposable { - private readonly IAdhocWorkspaceFactory _workspaceFactory = workspaceFactory; + private readonly AdhocWorkspaceFactory _workspaceFactory = new AdhocWorkspaceFactory(hostServicesProvider); - private Workspace? _workspace; private bool _disposed; void IDisposable.Dispose() @@ -21,7 +20,7 @@ internal sealed class LspWorkspaceProvider(IAdhocWorkspaceFactory workspaceFacto return; } - _workspace?.Dispose(); + _workspaceFactory.Dispose(); _disposed = true; } @@ -32,6 +31,6 @@ internal sealed class LspWorkspaceProvider(IAdhocWorkspaceFactory workspaceFacto throw new ObjectDisposedException(nameof(LspWorkspaceProvider)); } - return _workspace ??= _workspaceFactory.Create(); + return _workspaceFactory.GetOrCreate(); } } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs index be86fe0140..e072f6fefe 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs @@ -119,7 +119,6 @@ internal partial class RazorLanguageServer : SystemTextJsonLanguageServer(Logger); - services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AdhocWorkspaceFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AdhocWorkspaceFactory.cs index b6e30fb47f..cae437367a 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AdhocWorkspaceFactory.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AdhocWorkspaceFactory.cs @@ -1,11 +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 System; + namespace Microsoft.CodeAnalysis.Razor.Workspaces; -internal class AdhocWorkspaceFactory(IHostServicesProvider hostServicesProvider) : IAdhocWorkspaceFactory +internal sealed class AdhocWorkspaceFactory(IHostServicesProvider hostServicesProvider) : IDisposable { - public AdhocWorkspace Create() + private readonly Lazy _lazyWorkspace = new(() => CreateWorkspace(hostServicesProvider)); + + private static AdhocWorkspace CreateWorkspace(IHostServicesProvider hostServicesProvider) { var fallbackServices = hostServicesProvider.GetServices(); var services = AdhocServices.Create( @@ -15,4 +19,17 @@ internal class AdhocWorkspaceFactory(IHostServicesProvider hostServicesProvider) return new AdhocWorkspace(services); } + + public AdhocWorkspace GetOrCreate() + { + return _lazyWorkspace.Value; + } + + public void Dispose() + { + if (_lazyWorkspace.IsValueCreated) + { + _lazyWorkspace.Value.Dispose(); + } + } } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingContext.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingContext.cs index e0a16ef90d..fddc6c3e9a 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingContext.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/FormattingContext.cs @@ -18,20 +18,19 @@ using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.CodeAnalysis.Razor.Formatting; -internal sealed class FormattingContext : IDisposable +internal sealed class FormattingContext { - private readonly IAdhocWorkspaceFactory _workspaceFactory; + private readonly AdhocWorkspaceFactory _workspaceFactory; private readonly IFormattingCodeDocumentProvider _codeDocumentProvider; private Document? _csharpWorkspaceDocument; - private AdhocWorkspace? _csharpWorkspace; private IReadOnlyList? _formattingSpans; private IReadOnlyDictionary? _indentations; private FormattingContext( IFormattingCodeDocumentProvider codeDocumentProvider, - IAdhocWorkspaceFactory workspaceFactory, + AdhocWorkspaceFactory workspaceFactory, Uri uri, IDocumentSnapshot originalSnapshot, RazorCodeDocument codeDocument, @@ -83,7 +82,7 @@ internal sealed class FormattingContext : IDisposable } } - public AdhocWorkspace CSharpWorkspace => _csharpWorkspace ??= _workspaceFactory.Create(); + public AdhocWorkspace CSharpWorkspace => _workspaceFactory.GetOrCreate(); /// A Dictionary of int (line number) to IndentationContext. /// @@ -252,15 +251,6 @@ internal sealed class FormattingContext : IDisposable return false; } - public void Dispose() - { - _csharpWorkspace?.Dispose(); - if (_csharpWorkspaceDocument != null) - { - _csharpWorkspaceDocument = null; - } - } - public async Task WithTextAsync(SourceText changedText) { var changedSnapshot = OriginalSnapshot.WithText(changedText); @@ -307,7 +297,7 @@ internal sealed class FormattingContext : IDisposable RazorCodeDocument codeDocument, RazorFormattingOptions options, IFormattingCodeDocumentProvider codeDocumentProvider, - IAdhocWorkspaceFactory workspaceFactory, + AdhocWorkspaceFactory workspaceFactory, bool automaticallyAddUsings, int hostDocumentIndex, char triggerCharacter) @@ -330,7 +320,7 @@ internal sealed class FormattingContext : IDisposable RazorCodeDocument codeDocument, RazorFormattingOptions options, IFormattingCodeDocumentProvider codeDocumentProvider, - IAdhocWorkspaceFactory workspaceFactory) + AdhocWorkspaceFactory workspaceFactory) { return new FormattingContext( codeDocumentProvider, diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/RazorFormattingService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/RazorFormattingService.cs index 8a15e2cb32..94100dedd3 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/RazorFormattingService.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/RazorFormattingService.cs @@ -30,7 +30,7 @@ internal class RazorFormattingService : IRazorFormattingService private static readonly FrozenSet s_htmlTriggerCharacterSet = FrozenSet.ToFrozenSet(["\n", "{", "}", ";"], StringComparer.Ordinal); private readonly IFormattingCodeDocumentProvider _codeDocumentProvider; - private readonly IAdhocWorkspaceFactory _workspaceFactory; + private readonly IHostServicesProvider _hostServicesProvider; private readonly ImmutableArray _documentFormattingPasses; private readonly ImmutableArray _validationPasses; @@ -40,11 +40,11 @@ internal class RazorFormattingService : IRazorFormattingService public RazorFormattingService( IFormattingCodeDocumentProvider codeDocumentProvider, IDocumentMappingService documentMappingService, - IAdhocWorkspaceFactory workspaceFactory, + IHostServicesProvider hostServicesProvider, ILoggerFactory loggerFactory) { _codeDocumentProvider = codeDocumentProvider; - _workspaceFactory = workspaceFactory; + _hostServicesProvider = hostServicesProvider; _htmlOnTypeFormattingPass = new HtmlOnTypeFormattingPass(loggerFactory); _csharpOnTypeFormattingPass = new CSharpOnTypeFormattingPass(documentMappingService, loggerFactory); @@ -97,13 +97,14 @@ internal class RazorFormattingService : IRazorFormattingService var uri = documentContext.Uri; var documentSnapshot = documentContext.Snapshot; var hostDocumentVersion = documentContext.Snapshot.Version; - using var context = FormattingContext.Create( + using var adhocWorkspaceFactory = new AdhocWorkspaceFactory(_hostServicesProvider); + var context = FormattingContext.Create( uri, documentSnapshot, codeDocument, options, _codeDocumentProvider, - _workspaceFactory); + adhocWorkspaceFactory); var originalText = context.SourceText; var result = htmlChanges; @@ -225,14 +226,15 @@ internal class RazorFormattingService : IRazorFormattingService var documentSnapshot = documentContext.Snapshot; var uri = documentContext.Uri; var codeDocument = await _codeDocumentProvider.GetCodeDocumentAsync(documentSnapshot).ConfigureAwait(false); - using var context = FormattingContext.CreateForOnTypeFormatting( + using var adhocWorkspaceFactory = new AdhocWorkspaceFactory(_hostServicesProvider); + var context = FormattingContext.CreateForOnTypeFormatting( uri, documentSnapshot, codeDocument, options, _codeDocumentProvider, - _workspaceFactory, - automaticallyAddUsings: automaticallyAddUsings, + adhocWorkspaceFactory, + automaticallyAddUsings, hostDocumentIndex, triggerCharacter); var result = generatedDocumentChanges; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/IAdhocWorkspaceFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/IAdhocWorkspaceFactory.cs deleted file mode 100644 index 26ae985f46..0000000000 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/IAdhocWorkspaceFactory.cs +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the MIT license. See License.txt in the project root for license information. - -namespace Microsoft.CodeAnalysis.Razor.Workspaces; - -internal interface IAdhocWorkspaceFactory -{ - AdhocWorkspace Create(); -} diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/RemoteRazorFormattingService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/RemoteRazorFormattingService.cs index 6974dabd01..7de42441ec 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/RemoteRazorFormattingService.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/RemoteRazorFormattingService.cs @@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.Remote.Razor.Formatting; [Export(typeof(IRazorFormattingService)), Shared] [method: ImportingConstructor] -internal sealed class RemoteRazorFormattingService(IFormattingCodeDocumentProvider codeDocumentProvider, IDocumentMappingService documentMappingService, IAdhocWorkspaceFactory adhocWorkspaceFactory, ILoggerFactory loggerFactory) - : RazorFormattingService(codeDocumentProvider, documentMappingService, adhocWorkspaceFactory, loggerFactory) +internal sealed class RemoteRazorFormattingService(IFormattingCodeDocumentProvider codeDocumentProvider, IDocumentMappingService documentMappingService, IHostServicesProvider hostServicesProvider, ILoggerFactory loggerFactory) + : RazorFormattingService(codeDocumentProvider, documentMappingService, hostServicesProvider, loggerFactory) { } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoteAdhocWorkspaceFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoteAdhocWorkspaceFactory.cs deleted file mode 100644 index 621f0b9149..0000000000 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/RemoteAdhocWorkspaceFactory.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the MIT license. See License.txt in the project root for license information. - -using System.Composition; -using Microsoft.CodeAnalysis.Razor.Workspaces; - -namespace Microsoft.CodeAnalysis.Remote.Razor; - -[Export(typeof(IAdhocWorkspaceFactory)), Shared] -internal sealed class RemoteAdhocWorkspaceFactory(IHostServicesProvider hostServicesProvider) : AdhocWorkspaceFactory(hostServicesProvider) -{ -} diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingContentValidationPassTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingContentValidationPassTest.cs index 119c16efd7..0de25f1066 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingContentValidationPassTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingContentValidationPassTest.cs @@ -6,13 +6,12 @@ using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.Test; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; +using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; -using Microsoft.VisualStudio.LanguageServer.Protocol; using Moq; using Xunit; using Xunit.Abstractions; @@ -30,7 +29,7 @@ public class FormattingContentValidationPassTest(ITestOutputHelper testOutput) : [||]public class Foo { } } """; - using var context = CreateFormattingContext(source); + var context = CreateFormattingContext(source); var edits = ImmutableArray.Create(new TextChange(source.Span, " ")); var input = edits; var pass = GetPass(); @@ -51,7 +50,7 @@ public class FormattingContentValidationPassTest(ITestOutputHelper testOutput) : [|public class Foo { } |]} """; - using var context = CreateFormattingContext(source); + var context = CreateFormattingContext(source); var edits = ImmutableArray.Create(new TextChange(source.Span, " ")); var input = edits; var pass = GetPass(); @@ -85,13 +84,14 @@ public class FormattingContentValidationPassTest(ITestOutputHelper testOutput) : InsertSpaces = insertSpaces, }; + using var adhocWorkspaceFactory = new AdhocWorkspaceFactory(new DefaultHostServicesProvider()); var context = FormattingContext.Create( uri, documentSnapshot, codeDocument, options, new LspFormattingCodeDocumentProvider(), - TestAdhocWorkspaceFactory.Instance); + adhocWorkspaceFactory); return context; } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingDiagnosticValidationPassTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingDiagnosticValidationPassTest.cs index d3c305d51d..e449640ef5 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingDiagnosticValidationPassTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingDiagnosticValidationPassTest.cs @@ -5,11 +5,11 @@ using System; using System.Collections.Immutable; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.Test; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; +using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; using Xunit; using Xunit.Abstractions; @@ -27,7 +27,7 @@ public class FormattingDiagnosticValidationPassTest(ITestOutputHelper testOutput [||]public class Foo { } } """; - using var context = CreateFormattingContext(source); + var context = CreateFormattingContext(source); var edits = ImmutableArray.Create(new TextChange(source.Span, " ")); var input = edits; var pass = GetPass(); @@ -49,7 +49,7 @@ public class FormattingDiagnosticValidationPassTest(ITestOutputHelper testOutput public class Foo { } } """; - using var context = CreateFormattingContext(source); + var context = CreateFormattingContext(source); var badEdit = new TextChange(source.Span, "@ "); // Creates a diagnostic var pass = GetPass(); @@ -82,13 +82,14 @@ public class FormattingDiagnosticValidationPassTest(ITestOutputHelper testOutput InsertSpaces = insertSpaces, }; + using var adhocWorkspaceFactory = new AdhocWorkspaceFactory(new DefaultHostServicesProvider()); var context = FormattingContext.Create( uri, documentSnapshot, codeDocument, options, new LspFormattingCodeDocumentProvider(), - TestAdhocWorkspaceFactory.Instance); + adhocWorkspaceFactory); return context; } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/TestRazorFormattingService.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/TestRazorFormattingService.cs index fc10917be7..217024e2dc 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/TestRazorFormattingService.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/TestRazorFormattingService.cs @@ -5,7 +5,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; -using Microsoft.AspNetCore.Razor.LanguageServer.Test; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; using Microsoft.CodeAnalysis.Razor.Formatting; @@ -40,7 +39,8 @@ internal static class TestRazorFormattingService } var formattingCodeDocumentProvider = new LspFormattingCodeDocumentProvider(); + var hostServicesProvider = new DefaultHostServicesProvider(); - return new RazorFormattingService(formattingCodeDocumentProvider, mappingService, TestAdhocWorkspaceFactory.Instance, loggerFactory); + return new RazorFormattingService(formattingCodeDocumentProvider, mappingService, hostServicesProvider, loggerFactory); } } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestAdhocWorkspaceFactory.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestAdhocWorkspaceFactory.cs deleted file mode 100644 index 8918b3cc93..0000000000 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestAdhocWorkspaceFactory.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the MIT license. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Razor.Workspaces; - -namespace Microsoft.AspNetCore.Razor.LanguageServer.Test; - -internal class TestAdhocWorkspaceFactory : IAdhocWorkspaceFactory -{ - public static readonly TestAdhocWorkspaceFactory Instance = new(); - - private TestAdhocWorkspaceFactory() - { - } - - public AdhocWorkspace Create() - { - var services = TestServices.Create(workspaceServices: [], razorLanguageServices: []); - var workspace = TestWorkspace.Create(services); - return workspace; - } -}