diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs index 3f479f3e3bf..42c688c7211 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs @@ -55,7 +55,7 @@ public async Task SetupAsync() htmlCodeActionProviders: languageServer.GetRequiredService>(), clientConnection: languageServer.GetRequiredService(), languageServerFeatureOptions: languageServer.GetRequiredService(), - loggerFactory: languageServer.GetRequiredService(), + loggerFactory: languageServer.GetRequiredService(), telemetryReporter: null); var projectRoot = Path.Combine(RepoRoot, "src", "Razor", "test", "testapps", "ComponentApp"); diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCompletionBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCompletionBenchmark.cs index 470ad0df740..4766976f9c5 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCompletionBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCompletionBenchmark.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Razor.LanguageServer; using Microsoft.AspNetCore.Razor.LanguageServer.Completion; using Microsoft.AspNetCore.Razor.LanguageServer.Completion.Delegation; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; @@ -43,11 +44,12 @@ public async Task SetupAsync() var documentMappingService = lspServices.GetRequiredService(); var clientConnection = lspServices.GetRequiredService(); var completionListCache = lspServices.GetRequiredService(); - var loggerFactory = lspServices.GetRequiredService(); + var loggerFactory = lspServices.GetRequiredService(); var delegatedCompletionListProvider = new TestDelegatedCompletionListProvider(responseRewriters, documentMappingService, clientConnection, completionListCache); var completionListProvider = new CompletionListProvider(razorCompletionListProvider, delegatedCompletionListProvider); - var optionsMonitor = new BenchmarkOptionsMonitor(RazorLSPOptions.Default); + var configurationService = new DefaultRazorConfigurationService(clientConnection, loggerFactory); + var optionsMonitor = new RazorLSPOptionsMonitor(configurationService, RazorLSPOptions.Default); CompletionEndpoint = new RazorCompletionEndpoint(completionListProvider, telemetryReporter: null, optionsMonitor, loggerFactory); diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorDiagnosticsBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorDiagnosticsBenchmark.cs index 80571e96049..c3340ab5ade 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorDiagnosticsBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorDiagnosticsBenchmark.cs @@ -148,8 +148,8 @@ private IRazorDocumentMappingService BuildRazorDocumentMappingService() return razorDocumentMappingService.Object; } - private IRazorLoggerFactory BuildLoggerFactory() => Mock.Of( - r => r.CreateLogger( + private ILoggerFactory BuildLoggerFactory() => Mock.Of( + r => r.GetOrCreateLogger( It.IsAny()) == new NoopLogger(), MockBehavior.Strict); diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorLanguageServerBenchmarkBase.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorLanguageServerBenchmarkBase.cs index 815f989742a..fef65b2ff62 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorLanguageServerBenchmarkBase.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorLanguageServerBenchmarkBase.cs @@ -19,7 +19,6 @@ using Microsoft.CodeAnalysis.Text; using Microsoft.CommonLanguageServerProtocol.Framework; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; using Nerdbank.Streams; @@ -109,9 +108,9 @@ public Task SendRequestAsync(string method, TPara } } - internal class NoopLoggerFactory() : AbstractRazorLoggerFactory([new NoopLoggerProvider()]); + internal class NoopLoggerFactory() : AbstractLoggerFactory([new NoopLoggerProvider()]); - internal class NoopLoggerProvider : IRazorLoggerProvider + internal class NoopLoggerProvider : ILoggerProvider { public ILogger CreateLogger(string categoryName) { @@ -125,17 +124,12 @@ public void Dispose() internal class NoopLogger : ILogger, ILspLogger { - public IDisposable BeginScope(TState state) - { - throw new NotImplementedException(); - } - public bool IsEnabled(LogLevel logLevel) { return true; } - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + public void Log(LogLevel logLevel, TState state, Exception exception, Func formatter) { } diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs index ce3badc25a4..75a8be4e3c4 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs @@ -130,7 +130,7 @@ public TestRazorSemanticTokensInfoService( LanguageServerFeatureOptions languageServerFeatureOptions, IRazorDocumentMappingService documentMappingService, RazorSemanticTokensLegendService razorSemanticTokensLegendService, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : base(documentMappingService, razorSemanticTokensLegendService, csharpSemanticTokensProvider: null!, languageServerFeatureOptions, loggerFactory) { } diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensRangeEndpointBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensRangeEndpointBenchmark.cs index c8fd8c8ac0d..908195d20bf 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensRangeEndpointBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensRangeEndpointBenchmark.cs @@ -64,7 +64,7 @@ public async Task InitializeRazorSemanticAsync() { EnsureServicesInitialized(); - var loggerFactory = RazorLanguageServer.GetRequiredService(); + var loggerFactory = RazorLanguageServer.GetRequiredService(); var projectRoot = Path.Combine(RepoRoot, "src", "Razor", "test", "testapps", "ComponentApp"); ProjectFilePath = Path.Combine(projectRoot, "ComponentApp.csproj"); @@ -159,7 +159,7 @@ public TestCustomizableRazorSemanticTokensInfoService( LanguageServerFeatureOptions languageServerFeatureOptions, IRazorDocumentMappingService documentMappingService, RazorSemanticTokensLegendService razorSemanticTokensLegendService, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : base(documentMappingService, razorSemanticTokensLegendService, csharpSemanticTokensProvider: null!, languageServerFeatureOptions, loggerFactory) { } diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks.csproj b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks.csproj index 58def5258e1..1184bce9841 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks.csproj +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks.csproj @@ -56,7 +56,6 @@ - diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs index b7a3be10427..f0feb8acf1b 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs @@ -12,7 +12,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; using Moq; namespace Microsoft.AspNetCore.Razor.Microbenchmarks; @@ -63,9 +62,9 @@ protected ProjectSnapshotManagerBenchmarkBase(int documentCount = 100) Documents = documents.ToImmutable(); - var loggerFactoryMock = new Mock(MockBehavior.Strict); + var loggerFactoryMock = new Mock(MockBehavior.Strict); loggerFactoryMock - .Setup(x => x.CreateLogger(It.IsAny())) + .Setup(x => x.GetOrCreateLogger(It.IsAny())) .Returns(Mock.Of(MockBehavior.Strict)); ErrorReporter = new TestErrorReporter(); diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/BenchmarkConfigurationSyncService.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/BenchmarkConfigurationSyncService.cs new file mode 100644 index 00000000000..eb9ce26a080 --- /dev/null +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/BenchmarkConfigurationSyncService.cs @@ -0,0 +1,17 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.LanguageServer; +using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; + +namespace Microsoft.AspNetCore.Razor.Microbenchmarks.Serialization; + +internal class BenchmarkConfigurationSyncService : IConfigurationSyncService +{ + public Task GetLatestOptionsAsync(CancellationToken cancellationToken) + { + return Task.FromResult(null); + } +} diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/BenchmarkOptionsMonitor.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/BenchmarkOptionsMonitor.cs deleted file mode 100644 index b27463767e1..00000000000 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/BenchmarkOptionsMonitor.cs +++ /dev/null @@ -1,28 +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; -using Microsoft.Extensions.Options; - -namespace Microsoft.AspNetCore.Razor.Microbenchmarks.Serialization; - -internal class BenchmarkOptionsMonitor : IOptionsMonitor -{ - public BenchmarkOptionsMonitor(T value) - { - CurrentValue = value; - } - - public T CurrentValue { get; } - - public T Get(string name) => CurrentValue; - - public IDisposable OnChange(Action listener) => new Disposable(); - - private class Disposable : IDisposable - { - public void Dispose() - { - } - } -} diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/CompletionListSerializationBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/CompletionListSerializationBenchmark.cs index 83ca12d7f64..811f9e7d574 100644 --- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/CompletionListSerializationBenchmark.cs +++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/Serialization/CompletionListSerializationBenchmark.cs @@ -5,6 +5,7 @@ using System.Text; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.LanguageServer; using Microsoft.AspNetCore.Razor.LanguageServer.Completion; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.Completion; @@ -24,7 +25,8 @@ public class CompletionListSerializationBenchmark public CompletionListSerializationBenchmark() { var completionService = new LspTagHelperCompletionService(); - var optionsMonitor = new BenchmarkOptionsMonitor(RazorLSPOptions.Default); + var configurationService = new BenchmarkConfigurationSyncService(); + var optionsMonitor = new RazorLSPOptionsMonitor(configurationService, RazorLSPOptions.Default); var tagHelperCompletionProvider = new TagHelperCompletionProvider(completionService, optionsMonitor); _serializer = JsonSerializer.Create(); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AbstractRazorDelegatingEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AbstractRazorDelegatingEndpoint.cs index 25cffbb9a0f..c5d7eb826ea 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AbstractRazorDelegatingEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AbstractRazorDelegatingEndpoint.cs @@ -9,9 +9,9 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Telemetry; using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; using StreamJsonRpc; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/AutoClosingTagOnAutoInsertProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/AutoClosingTagOnAutoInsertProvider.cs index c9443dfec11..a69469ab185 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/AutoClosingTagOnAutoInsertProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/AutoClosingTagOnAutoInsertProvider.cs @@ -8,11 +8,8 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Syntax; using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert; @@ -41,10 +38,10 @@ internal sealed class AutoClosingTagOnAutoInsertProvider : IOnAutoInsertProvider ); private static readonly ImmutableHashSet s_voidElementsCaseSensitive = s_voidElements.WithComparer(StringComparer.Ordinal); - private readonly IOptionsMonitor _optionsMonitor; + private readonly RazorLSPOptionsMonitor _optionsMonitor; private readonly ILogger _logger; - public AutoClosingTagOnAutoInsertProvider(IOptionsMonitor optionsMonitor, IRazorLoggerFactory loggerFactory) + public AutoClosingTagOnAutoInsertProvider(RazorLSPOptionsMonitor optionsMonitor, ILoggerFactory loggerFactory) { if (optionsMonitor is null) { @@ -57,7 +54,7 @@ public AutoClosingTagOnAutoInsertProvider(IOptionsMonitor optio } _optionsMonitor = optionsMonitor; - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); } public string TriggerCharacter => ">"; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/CloseTextTagOnAutoInsertProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/CloseTextTagOnAutoInsertProvider.cs index 5164b71b3a1..81207b73be5 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/CloseTextTagOnAutoInsertProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/CloseTextTagOnAutoInsertProvider.cs @@ -8,21 +8,18 @@ using Microsoft.AspNetCore.Razor.Language.Legacy; using Microsoft.AspNetCore.Razor.Language.Syntax; using Microsoft.AspNetCore.Razor.LanguageServer.Formatting; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert; internal sealed class CloseTextTagOnAutoInsertProvider : IOnAutoInsertProvider { - private readonly IOptionsMonitor _optionsMonitor; + private readonly RazorLSPOptionsMonitor _optionsMonitor; private readonly ILogger _logger; - public CloseTextTagOnAutoInsertProvider(IOptionsMonitor optionsMonitor, IRazorLoggerFactory loggerFactory) + public CloseTextTagOnAutoInsertProvider(RazorLSPOptionsMonitor optionsMonitor, ILoggerFactory loggerFactory) { if (optionsMonitor is null) { @@ -35,7 +32,7 @@ public CloseTextTagOnAutoInsertProvider(IOptionsMonitor options } _optionsMonitor = optionsMonitor; - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); } public string TriggerCharacter => ">"; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertEndpoint.cs index 6500b92fb3d..2712684d4aa 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertEndpoint.cs @@ -14,8 +14,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert; @@ -26,15 +24,15 @@ internal class OnAutoInsertEndpoint( IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, IEnumerable onAutoInsertProvider, - IOptionsMonitor optionsMonitor, - IRazorLoggerFactory loggerFactory) - : AbstractRazorDelegatingEndpoint(languageServerFeatureOptions, documentMappingService, clientConnection, loggerFactory.CreateLogger()), ICapabilitiesProvider + RazorLSPOptionsMonitor optionsMonitor, + ILoggerFactory loggerFactory) + : AbstractRazorDelegatingEndpoint(languageServerFeatureOptions, documentMappingService, clientConnection, loggerFactory.GetOrCreateLogger()), ICapabilitiesProvider { private static readonly HashSet s_htmlAllowedTriggerCharacters = new(StringComparer.Ordinal) { "=", }; private static readonly HashSet s_cSharpAllowedTriggerCharacters = new(StringComparer.Ordinal) { "'", "/", "\n" }; private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions ?? throw new ArgumentNullException(nameof(languageServerFeatureOptions)); - private readonly IOptionsMonitor _optionsMonitor = optionsMonitor ?? throw new ArgumentNullException(nameof(optionsMonitor)); + private readonly RazorLSPOptionsMonitor _optionsMonitor = optionsMonitor ?? throw new ArgumentNullException(nameof(optionsMonitor)); private readonly IReadOnlyList _onAutoInsertProviders = onAutoInsertProvider?.ToList() ?? throw new ArgumentNullException(nameof(onAutoInsertProvider)); protected override string CustomMessageTarget => CustomMessageNames.RazorOnAutoInsertEndpointName; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/PreferHtmlInAttributeValuesDocumentPositionStrategy.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/PreferHtmlInAttributeValuesDocumentPositionStrategy.cs index ea3ccde841b..70454c11b6a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/PreferHtmlInAttributeValuesDocumentPositionStrategy.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/PreferHtmlInAttributeValuesDocumentPositionStrategy.cs @@ -5,9 +5,9 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language.Syntax; using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs index 44cd850d306..d46d0a645dc 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs @@ -21,7 +21,6 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; using Newtonsoft.Json.Linq; using StreamJsonRpc; @@ -36,7 +35,7 @@ internal sealed class CodeActionEndpoint( IEnumerable htmlCodeActionProviders, IClientConnection clientConnection, LanguageServerFeatureOptions languageServerFeatureOptions, - IRazorLoggerFactory loggerFactory, + ILoggerFactory loggerFactory, ITelemetryReporter? telemetryReporter) : IRazorRequestHandler[]?>, ICapabilitiesProvider { @@ -48,7 +47,7 @@ internal sealed class CodeActionEndpoint( private readonly IEnumerable _htmlCodeActionProviders = htmlCodeActionProviders ?? throw new ArgumentNullException(nameof(htmlCodeActionProviders)); private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions ?? throw new ArgumentNullException(nameof(languageServerFeatureOptions)); private readonly IClientConnection _clientConnection = clientConnection ?? throw new ArgumentNullException(nameof(clientConnection)); - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); private readonly ITelemetryReporter? _telemetryReporter = telemetryReporter; internal bool _supportsCodeActionResolve = false; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs index acf4f940157..c2c162b9bfe 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolveEndpoint.cs @@ -11,7 +11,6 @@ using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; using Newtonsoft.Json.Linq; @@ -31,7 +30,7 @@ public CodeActionResolveEndpoint( IEnumerable razorCodeActionResolvers, IEnumerable csharpCodeActionResolvers, IEnumerable htmlCodeActionResolvers, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) { if (razorCodeActionResolvers is null) { @@ -53,7 +52,7 @@ public CodeActionResolveEndpoint( throw new ArgumentNullException(nameof(loggerFactory)); } - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); _razorCodeActionResolvers = CreateResolverMap(razorCodeActionResolvers); _csharpCodeActionResolvers = CreateResolverMap(csharpCodeActionResolvers); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs index 6656104acf5..516cd4aa744 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionProvider.cs @@ -16,7 +16,6 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions; @@ -25,14 +24,14 @@ internal sealed class ExtractToCodeBehindCodeActionProvider : IRazorCodeActionPr private static readonly Task?> s_emptyResult = Task.FromResult?>(null); private readonly ILogger _logger; - public ExtractToCodeBehindCodeActionProvider(IRazorLoggerFactory loggerFactory) + public ExtractToCodeBehindCodeActionProvider(ILoggerFactory loggerFactory) { if (loggerFactory is null) { throw new ArgumentNullException(nameof(loggerFactory)); } - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); } public Task?> ProvideAsync(RazorCodeActionContext context, CancellationToken cancellationToken) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/AggregateCompletionItemResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/AggregateCompletionItemResolver.cs index 5351da8a910..b468a35bad4 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/AggregateCompletionItemResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/AggregateCompletionItemResolver.cs @@ -7,7 +7,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion; @@ -17,10 +16,10 @@ internal class AggregateCompletionItemResolver private readonly IReadOnlyList _completionItemResolvers; private readonly ILogger _logger; - public AggregateCompletionItemResolver(IEnumerable completionItemResolvers, IRazorLoggerFactory loggerFactory) + public AggregateCompletionItemResolver(IEnumerable completionItemResolvers, ILoggerFactory loggerFactory) { _completionItemResolvers = completionItemResolvers.ToArray(); - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); } public async Task ResolveAsync( diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/LegacyRazorCompletionEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/LegacyRazorCompletionEndpoint.cs index f5c64f4ca04..43d3bc3f74f 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/LegacyRazorCompletionEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/LegacyRazorCompletionEndpoint.cs @@ -14,7 +14,6 @@ using Microsoft.CodeAnalysis.Razor.Completion; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion; @@ -25,12 +24,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion; internal class LegacyRazorCompletionEndpoint( IRazorCompletionFactsService completionFactsService, CompletionListCache completionListCache, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : IVSCompletionEndpoint { private readonly IRazorCompletionFactsService _completionFactsService = completionFactsService; private readonly CompletionListCache _completionListCache = completionListCache; - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); private static readonly Command s_retriggerCompletionCommand = new() { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/LegacyRazorCompletionResolveEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/LegacyRazorCompletionResolveEndpoint.cs index 710b551b286..6f10d6054de 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/LegacyRazorCompletionResolveEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/LegacyRazorCompletionResolveEndpoint.cs @@ -12,7 +12,6 @@ using Microsoft.CodeAnalysis.Razor.Completion; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; using Microsoft.VisualStudio.Text.Adornments; @@ -40,7 +39,7 @@ public LegacyRazorCompletionResolveEndpoint( LSPTagHelperTooltipFactory lspTagHelperTooltipFactory, VSLSPTagHelperTooltipFactory vsLspTagHelperTooltipFactory, CompletionListCache completionListCache, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) { if (lspTagHelperTooltipFactory is null) { @@ -64,7 +63,7 @@ public LegacyRazorCompletionResolveEndpoint( _lspTagHelperTooltipFactory = lspTagHelperTooltipFactory; _vsLspTagHelperTooltipFactory = vsLspTagHelperTooltipFactory; - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); _completionListCache = completionListCache; } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionEndpoint.cs index 748ab3269b9..22b7370c350 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionEndpoint.cs @@ -7,12 +7,9 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Telemetry; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion; @@ -20,14 +17,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion; internal class RazorCompletionEndpoint( CompletionListProvider completionListProvider, ITelemetryReporter? telemetryReporter, - IOptionsMonitor optionsMonitor, - IRazorLoggerFactory loggerFactory) + RazorLSPOptionsMonitor optionsMonitor, + ILoggerFactory loggerFactory) : IVSCompletionEndpoint { private readonly CompletionListProvider _completionListProvider = completionListProvider; private readonly ITelemetryReporter? _telemetryReporter = telemetryReporter; - private readonly IOptionsMonitor _optionsMonitor = optionsMonitor; - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly RazorLSPOptionsMonitor _optionsMonitor = optionsMonitor; + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); private VSInternalClientCapabilities? _clientCapabilities; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionListProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionListProvider.cs index 480f9f88e14..53a1c7756b1 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionListProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionListProvider.cs @@ -14,7 +14,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion; @@ -22,11 +21,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion; internal class RazorCompletionListProvider( IRazorCompletionFactsService completionFactsService, CompletionListCache completionListCache, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) { private readonly IRazorCompletionFactsService _completionFactsService = completionFactsService; private readonly CompletionListCache _completionListCache = completionListCache; - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); private static readonly Command s_retriggerCompletionCommand = new() { CommandIdentifier = "editor.action.triggerSuggest", diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/TagHelperCompletionProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/TagHelperCompletionProvider.cs index 40a8181277e..45eaf100a43 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/TagHelperCompletionProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/TagHelperCompletionProvider.cs @@ -9,11 +9,9 @@ using System.Linq; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Syntax; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.CodeAnalysis.Razor.Completion; using Microsoft.CodeAnalysis.Razor.Tooltip; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.Editor.Razor; namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion; @@ -29,11 +27,11 @@ internal class TagHelperCompletionProvider : IRazorCompletionItemProvider private static readonly ImmutableArray s_elementCommitCharacters_WithoutSpace = RazorCommitCharacter.CreateArray([">"]); private readonly ITagHelperCompletionService _tagHelperCompletionService; - private readonly IOptionsMonitor _optionsMonitor; + private readonly RazorLSPOptionsMonitor _optionsMonitor; public TagHelperCompletionProvider( ITagHelperCompletionService tagHelperCompletionService, - IOptionsMonitor optionsMonitor) + RazorLSPOptionsMonitor optionsMonitor) { _tagHelperCompletionService = tagHelperCompletionService; _optionsMonitor = optionsMonitor; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Debugging/RazorBreakpointSpanEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Debugging/RazorBreakpointSpanEndpoint.cs index d25377e6b23..4978c2150d7 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Debugging/RazorBreakpointSpanEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Debugging/RazorBreakpointSpanEndpoint.cs @@ -15,7 +15,6 @@ using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; using Microsoft.CommonLanguageServerProtocol.Framework; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Debugging; @@ -30,7 +29,7 @@ internal class RazorBreakpointSpanEndpoint : IRazorDocumentlessRequestHandler(); + _logger = loggerFactory.GetOrCreateLogger(); } public Uri GetTextDocumentIdentifier(RazorBreakpointSpanParams request) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Debugging/RazorProximityExpressionsEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Debugging/RazorProximityExpressionsEndpoint.cs index 5c9fea53968..6090cfa2aaf 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Debugging/RazorProximityExpressionsEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Debugging/RazorProximityExpressionsEndpoint.cs @@ -15,7 +15,6 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Text; using Microsoft.CommonLanguageServerProtocol.Framework; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer.Debugging; @@ -27,7 +26,7 @@ internal class RazorProximityExpressionsEndpoint : IRazorDocumentlessRequestHand public RazorProximityExpressionsEndpoint( IRazorDocumentMappingService documentMappingService, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) { if (documentMappingService is null) { @@ -40,7 +39,7 @@ public RazorProximityExpressionsEndpoint( } _documentMappingService = documentMappingService; - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); } public bool MutatesSolutionState => false; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Debugging/ValidateBreakpointRangeEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Debugging/ValidateBreakpointRangeEndpoint.cs index cfd67d62f05..065528e37f3 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Debugging/ValidateBreakpointRangeEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Debugging/ValidateBreakpointRangeEndpoint.cs @@ -10,7 +10,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Debugging; @@ -20,12 +19,12 @@ internal class ValidateBreakpointRangeEndpoint( IRazorDocumentMappingService documentMappingService, LanguageServerFeatureOptions languageServerFeatureOptions, IClientConnection clientConnection, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : AbstractRazorDelegatingEndpoint( languageServerFeatureOptions, documentMappingService, clientConnection, - loggerFactory.CreateLogger()), ICapabilitiesProvider + loggerFactory.GetOrCreateLogger()), ICapabilitiesProvider { private readonly IRazorDocumentMappingService _documentMappingService = documentMappingService; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultDocumentPositionInfoStrategy.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultDocumentPositionInfoStrategy.cs index 5d927303e09..c421b4e8e97 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultDocumentPositionInfoStrategy.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultDocumentPositionInfoStrategy.cs @@ -4,9 +4,9 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorComponentSearchEngine.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorComponentSearchEngine.cs index d5cc8fb4884..8f41a773af8 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorComponentSearchEngine.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorComponentSearchEngine.cs @@ -12,17 +12,16 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer; internal class DefaultRazorComponentSearchEngine( IProjectSnapshotManager projectManager, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : RazorComponentSearchEngine { private readonly IProjectSnapshotManager _projectManager = projectManager; - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public async override Task TryGetTagHelperDescriptorAsync(IDocumentSnapshot documentSnapshot, CancellationToken cancellationToken) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorConfigurationService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorConfigurationService.cs index 68d6e9e1993..fce5693288e 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorConfigurationService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorConfigurationService.cs @@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Settings; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -19,7 +18,7 @@ internal class DefaultRazorConfigurationService : IConfigurationSyncService private readonly IClientConnection _clientConnection; private readonly ILogger _logger; - public DefaultRazorConfigurationService(IClientConnection clientConnection, IRazorLoggerFactory loggerFactory) + public DefaultRazorConfigurationService(IClientConnection clientConnection, ILoggerFactory loggerFactory) { if (clientConnection is null) { @@ -32,7 +31,7 @@ public DefaultRazorConfigurationService(IClientConnection clientConnection, IRaz } _clientConnection = clientConnection; - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); } public async Task GetLatestOptionsAsync(CancellationToken cancellationToken) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Definition/DefinitionEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Definition/DefinitionEndpoint.cs index 7ebc1f43a2b..f7a2294e449 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Definition/DefinitionEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Definition/DefinitionEndpoint.cs @@ -16,7 +16,6 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; using DefinitionResult = Microsoft.VisualStudio.LanguageServer.Protocol.SumType< Microsoft.VisualStudio.LanguageServer.Protocol.VSInternalLocation, @@ -32,8 +31,8 @@ internal sealed class DefinitionEndpoint( IRazorDocumentMappingService documentMappingService, LanguageServerFeatureOptions languageServerFeatureOptions, IClientConnection clientConnection, - IRazorLoggerFactory loggerFactory) - : AbstractRazorDelegatingEndpoint(languageServerFeatureOptions, documentMappingService, clientConnection, loggerFactory.CreateLogger()), ICapabilitiesProvider + ILoggerFactory loggerFactory) + : AbstractRazorDelegatingEndpoint(languageServerFeatureOptions, documentMappingService, clientConnection, loggerFactory.GetOrCreateLogger()), ICapabilitiesProvider { private readonly RazorComponentSearchEngine _componentSearchEngine = componentSearchEngine ?? throw new ArgumentNullException(nameof(componentSearchEngine)); private readonly IRazorDocumentMappingService _documentMappingService = documentMappingService ?? throw new ArgumentNullException(nameof(documentMappingService)); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorDiagnosticsPublisher.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorDiagnosticsPublisher.cs index 7a82dd04f50..b7163a7efd7 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorDiagnosticsPublisher.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorDiagnosticsPublisher.cs @@ -14,7 +14,6 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; using Microsoft.VisualStudio.Threading; @@ -45,7 +44,7 @@ public RazorDiagnosticsPublisher( LanguageServerFeatureOptions languageServerFeatureOptions, Lazy razorTranslateDiagnosticsService, Lazy documentContextFactory, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) { if (projectSnapshotManagerDispatcher is null) { @@ -85,7 +84,7 @@ public RazorDiagnosticsPublisher( PublishedRazorDiagnostics = new Dictionary>(FilePathComparer.Instance); PublishedCSharpDiagnostics = new Dictionary>(FilePathComparer.Instance); _work = new Dictionary(FilePathComparer.Instance); - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); } // Used in tests to ensure we can control when background work completes. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorTranslateDiagnosticsEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorTranslateDiagnosticsEndpoint.cs index f1440fb1449..172017e5ca0 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorTranslateDiagnosticsEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorTranslateDiagnosticsEndpoint.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics; @@ -22,7 +21,7 @@ internal class RazorTranslateDiagnosticsEndpoint : IRazorRequestHandler(); + _logger = loggerFactory.GetOrCreateLogger(); } public async Task HandleRequestAsync(RazorDiagnosticsParams request, RazorRequestContext requestContext, CancellationToken cancellationToken) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorTranslateDiagnosticsService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorTranslateDiagnosticsService.cs index 18d74c32f4f..8a39a978d96 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorTranslateDiagnosticsService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorTranslateDiagnosticsService.cs @@ -16,7 +16,6 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; using Diagnostic = Microsoft.VisualStudio.LanguageServer.Protocol.Diagnostic; using DiagnosticSeverity = Microsoft.VisualStudio.LanguageServer.Protocol.DiagnosticSeverity; using Position = Microsoft.VisualStudio.LanguageServer.Protocol.Position; @@ -43,9 +42,9 @@ internal class RazorTranslateDiagnosticsService /// translating code diagnostics from one representation into another, such as from C# to Razor. /// /// The . - /// The . + /// The . /// - public RazorTranslateDiagnosticsService(IRazorDocumentMappingService documentMappingService, IRazorLoggerFactory loggerFactory) + public RazorTranslateDiagnosticsService(IRazorDocumentMappingService documentMappingService, ILoggerFactory loggerFactory) { if (documentMappingService is null) { @@ -58,7 +57,7 @@ public RazorTranslateDiagnosticsService(IRazorDocumentMappingService documentMap } _documentMappingService = documentMappingService; - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); } /// diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DirectoryHelper.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DirectoryHelper.cs index 859f87f208c..cfc2e6cd256 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DirectoryHelper.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DirectoryHelper.cs @@ -6,7 +6,7 @@ using System.IO; using System.Linq; using Microsoft.CodeAnalysis.Razor; -using Microsoft.Extensions.Logging; +using Microsoft.CodeAnalysis.Razor.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentContextFactory.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentContextFactory.cs index 9c603951971..9eaf45bef36 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentContextFactory.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentContextFactory.cs @@ -10,7 +10,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer; @@ -19,13 +18,13 @@ internal sealed class DocumentContextFactory( IProjectSnapshotManager projectManager, ISnapshotResolver snapshotResolver, IDocumentVersionCache documentVersionCache, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : IDocumentContextFactory { private readonly IProjectSnapshotManager _projectManager = projectManager; private readonly ISnapshotResolver _snapshotResolver = snapshotResolver; private readonly IDocumentVersionCache _documentVersionCache = documentVersionCache; - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public DocumentContext? TryCreate(Uri documentUri, VSProjectContext? projectContext, bool versioned) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentHighlighting/DocumentHighlightEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentHighlighting/DocumentHighlightEndpoint.cs index a59a1e60e3b..948f967c31e 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentHighlighting/DocumentHighlightEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentHighlighting/DocumentHighlightEndpoint.cs @@ -10,7 +10,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.DocumentHighlighting; @@ -24,8 +23,8 @@ public DocumentHighlightEndpoint( LanguageServerFeatureOptions languageServerFeatureOptions, IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, - IRazorLoggerFactory loggerFactory) - : base(languageServerFeatureOptions, documentMappingService, clientConnection, loggerFactory.CreateLogger()) + ILoggerFactory loggerFactory) + : base(languageServerFeatureOptions, documentMappingService, clientConnection, loggerFactory.GetOrCreateLogger()) { _documentMappingService = documentMappingService ?? throw new ArgumentNullException(nameof(documentMappingService)); } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentPresentation/AbstractTextDocumentPresentationEndpointBase.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentPresentation/AbstractTextDocumentPresentationEndpointBase.cs index 21cbd83f3bc..87ea3bb798a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentPresentation/AbstractTextDocumentPresentationEndpointBase.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentPresentation/AbstractTextDocumentPresentationEndpointBase.cs @@ -11,11 +11,11 @@ using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.DocumentPresentation; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.DocumentPresentation; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentPresentation/TextDocumentTextPresentationEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentPresentation/TextDocumentTextPresentationEndpoint.cs index 31562a6c5d4..0091662b682 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentPresentation/TextDocumentTextPresentationEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentPresentation/TextDocumentTextPresentationEndpoint.cs @@ -17,8 +17,8 @@ internal class TextDocumentTextPresentationEndpoint( IRazorDocumentMappingService razorDocumentMappingService, IClientConnection clientConnection, IFilePathService filePathService, - IRazorLoggerFactory loggerFactory) - : AbstractTextDocumentPresentationEndpointBase(razorDocumentMappingService, clientConnection, filePathService, loggerFactory.CreateLogger()), ITextDocumentTextPresentationHandler + ILoggerFactory loggerFactory) + : AbstractTextDocumentPresentationEndpointBase(razorDocumentMappingService, clientConnection, filePathService, loggerFactory.GetOrCreateLogger()), ITextDocumentTextPresentationHandler { public override string EndpointName => CustomMessageNames.RazorTextPresentationEndpoint; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentPresentation/TextDocumentUriPresentationEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentPresentation/TextDocumentUriPresentationEndpoint.cs index e5041f357d5..5c56ea5197d 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentPresentation/TextDocumentUriPresentationEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentPresentation/TextDocumentUriPresentationEndpoint.cs @@ -16,7 +16,6 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.DocumentPresentation; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.DocumentPresentation; @@ -27,8 +26,8 @@ internal class TextDocumentUriPresentationEndpoint( IClientConnection clientConnection, IFilePathService filePathService, IDocumentContextFactory documentContextFactory, - IRazorLoggerFactory loggerFactory) - : AbstractTextDocumentPresentationEndpointBase(razorDocumentMappingService, clientConnection, filePathService, loggerFactory.CreateLogger()), ITextDocumentUriPresentationHandler + ILoggerFactory loggerFactory) + : AbstractTextDocumentPresentationEndpointBase(razorDocumentMappingService, clientConnection, filePathService, loggerFactory.GetOrCreateLogger()), ITextDocumentUriPresentationHandler { private readonly RazorComponentSearchEngine _razorComponentSearchEngine = razorComponentSearchEngine ?? throw new ArgumentNullException(nameof(razorComponentSearchEngine)); private readonly IDocumentContextFactory _documentContextFactory = documentContextFactory ?? throw new ArgumentNullException(nameof(documentContextFactory)); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSynchronization/DocumentDidChangeEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSynchronization/DocumentDidChangeEndpoint.cs index 2d485f44915..837a97d7dad 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSynchronization/DocumentDidChangeEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSynchronization/DocumentDidChangeEndpoint.cs @@ -12,7 +12,6 @@ using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; using Microsoft.CommonLanguageServerProtocol.Framework; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.DocumentSynchronization; @@ -21,14 +20,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.DocumentSynchronization; internal class DocumentDidChangeEndpoint( ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher, IRazorProjectService razorProjectService, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : IRazorNotificationHandler, ITextDocumentIdentifierHandler, ICapabilitiesProvider { public bool MutatesSolutionState => true; private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher; private readonly IRazorProjectService _projectService = razorProjectService; - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, VSInternalClientCapabilities clientCapabilities) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSynchronization/DocumentDidSaveEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSynchronization/DocumentDidSaveEndpoint.cs index c15899f843e..153093ce4e5 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSynchronization/DocumentDidSaveEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DocumentSynchronization/DocumentDidSaveEndpoint.cs @@ -7,16 +7,15 @@ using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CommonLanguageServerProtocol.Framework; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.DocumentSynchronization; [RazorLanguageServerEndpoint(Methods.TextDocumentDidSaveName)] -internal class DocumentDidSaveEndpoint(IRazorLoggerFactory loggerFactory) +internal class DocumentDidSaveEndpoint(ILoggerFactory loggerFactory) : IRazorNotificationHandler, ITextDocumentIdentifierHandler { - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public bool MutatesSolutionState => false; 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 db727510bfe..a79efd8810e 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Extensions/IServiceCollectionExtensions.cs @@ -30,7 +30,6 @@ using Microsoft.CommonLanguageServerProtocol.Framework; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Extensions; @@ -194,11 +193,8 @@ public static void AddOptionsServices(this IServiceCollection services, RazorLSP { return new RazorLSPOptionsMonitor( s.GetRequiredService(), - s.GetRequiredService>(), currentOptions); }); - - services.AddSingleton, RazorLSPOptionsMonitor>(s => s.GetRequiredService()); } public static void AddDocumentManagementServices(this IServiceCollection services, LanguageServerFeatureOptions featureOptions) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/FindAllReferences/FindAllReferencesEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/FindAllReferences/FindAllReferencesEndpoint.cs index aea07ae9e5b..2a6988c5d60 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/FindAllReferences/FindAllReferencesEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/FindAllReferences/FindAllReferencesEndpoint.cs @@ -12,7 +12,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; using Microsoft.VisualStudio.Text.Adornments; @@ -28,9 +27,9 @@ public FindAllReferencesEndpoint( LanguageServerFeatureOptions languageServerFeatureOptions, IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, - IRazorLoggerFactory loggerFactory, + ILoggerFactory loggerFactory, IFilePathService filePathService) - : base(languageServerFeatureOptions, documentMappingService, clientConnection, loggerFactory.CreateLogger()) + : base(languageServerFeatureOptions, documentMappingService, clientConnection, loggerFactory.GetOrCreateLogger()) { _filePathService = filePathService ?? throw new ArgumentNullException(nameof(filePathService)); _documentMappingService = documentMappingService ?? throw new ArgumentNullException(nameof(documentMappingService)); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Folding/FoldingRangeEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Folding/FoldingRangeEndpoint.cs index fde872180a2..77597beb222 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Folding/FoldingRangeEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Folding/FoldingRangeEndpoint.cs @@ -17,7 +17,6 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.Folding; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Folding; @@ -36,12 +35,12 @@ public FoldingRangeEndpoint( IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, IEnumerable foldingRangeProviders, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) { _documentMappingService = documentMappingService ?? throw new ArgumentNullException(nameof(documentMappingService)); _clientConnection = clientConnection ?? throw new ArgumentNullException(nameof(clientConnection)); _foldingRangeProviders = foldingRangeProviders ?? throw new ArgumentNullException(nameof(foldingRangeProviders)); - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); } public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, VSInternalClientCapabilities clientCapabilities) @@ -56,8 +55,6 @@ public TextDocumentIdentifier GetTextDocumentIdentifier(FoldingRangeParams reque public async Task?> HandleRequestAsync(FoldingRangeParams @params, RazorRequestContext requestContext, CancellationToken cancellationToken) { - using var _ = _logger.BeginScope("FoldingRangeEndpoint.Handle"); - var documentContext = requestContext.DocumentContext; if (documentContext is null) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormattingPass.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormattingPass.cs index 76c4a123765..065d1e28add 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormattingPass.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormattingPass.cs @@ -12,7 +12,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; using TextSpan = Microsoft.CodeAnalysis.Text.TextSpan; @@ -25,7 +24,7 @@ internal class CSharpFormattingPass : CSharpFormattingPassBase public CSharpFormattingPass( IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : base(documentMappingService, clientConnection) { if (loggerFactory is null) @@ -33,7 +32,7 @@ public CSharpFormattingPass( throw new ArgumentNullException(nameof(loggerFactory)); } - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); } // Run after the HTML and Razor formatter pass. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpOnTypeFormattingPass.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpOnTypeFormattingPass.cs index 88de23f6483..d3369dc5c36 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpOnTypeFormattingPass.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpOnTypeFormattingPass.cs @@ -21,8 +21,6 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; using SyntaxNode = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxNode; using TextSpan = Microsoft.CodeAnalysis.Text.TextSpan; @@ -32,13 +30,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; internal class CSharpOnTypeFormattingPass : CSharpFormattingPassBase { private readonly ILogger _logger; - private readonly IOptionsMonitor _optionsMonitor; + private readonly RazorLSPOptionsMonitor _optionsMonitor; public CSharpOnTypeFormattingPass( IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, - IOptionsMonitor optionsMonitor, - IRazorLoggerFactory loggerFactory) + RazorLSPOptionsMonitor optionsMonitor, + ILoggerFactory loggerFactory) : base(documentMappingService, clientConnection) { if (loggerFactory is null) @@ -46,7 +44,7 @@ public CSharpOnTypeFormattingPass( throw new ArgumentNullException(nameof(loggerFactory)); } - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); _optionsMonitor = optionsMonitor; } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentFormattingEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentFormattingEndpoint.cs index 24f67f8afcb..1c074702874 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentFormattingEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentFormattingEndpoint.cs @@ -6,8 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; @@ -16,11 +14,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; internal class DocumentFormattingEndpoint : IRazorRequestHandler, ICapabilitiesProvider { private readonly IRazorFormattingService _razorFormattingService; - private readonly IOptionsMonitor _optionsMonitor; + private readonly RazorLSPOptionsMonitor _optionsMonitor; public DocumentFormattingEndpoint( IRazorFormattingService razorFormattingService, - IOptionsMonitor optionsMonitor) + RazorLSPOptionsMonitor optionsMonitor) { _razorFormattingService = razorFormattingService ?? throw new ArgumentNullException(nameof(razorFormattingService)); _optionsMonitor = optionsMonitor ?? throw new ArgumentNullException(nameof(optionsMonitor)); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentOnTypeFormattingEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentOnTypeFormattingEndpoint.cs index a723df1cf28..8c517e92784 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentOnTypeFormattingEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentOnTypeFormattingEndpoint.cs @@ -9,13 +9,10 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; @@ -24,14 +21,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; internal class DocumentOnTypeFormattingEndpoint( IRazorFormattingService razorFormattingService, IRazorDocumentMappingService razorDocumentMappingService, - IOptionsMonitor optionsMonitor, - IRazorLoggerFactory loggerFactory) + RazorLSPOptionsMonitor optionsMonitor, + ILoggerFactory loggerFactory) : IRazorRequestHandler, ICapabilitiesProvider { private readonly IRazorFormattingService _razorFormattingService = razorFormattingService ?? throw new ArgumentNullException(nameof(razorFormattingService)); private readonly IRazorDocumentMappingService _razorDocumentMappingService = razorDocumentMappingService ?? throw new ArgumentNullException(nameof(razorDocumentMappingService)); - private readonly IOptionsMonitor _optionsMonitor = optionsMonitor ?? throw new ArgumentNullException(nameof(optionsMonitor)); - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly RazorLSPOptionsMonitor _optionsMonitor = optionsMonitor ?? throw new ArgumentNullException(nameof(optionsMonitor)); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); private static readonly IReadOnlyList s_csharpTriggerCharacters = new[] { "}", ";" }; private static readonly IReadOnlyList s_htmlTriggerCharacters = new[] { "\n", "{", "}", ";" }; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentRangeFormattingEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentRangeFormattingEndpoint.cs index d92100b8b7f..414a1bf1ef5 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentRangeFormattingEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/DocumentRangeFormattingEndpoint.cs @@ -6,8 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; @@ -16,11 +14,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; internal class DocumentRangeFormattingEndpoint : IRazorRequestHandler, ICapabilitiesProvider { private readonly IRazorFormattingService _razorFormattingService; - private readonly IOptionsMonitor _optionsMonitor; + private readonly RazorLSPOptionsMonitor _optionsMonitor; public DocumentRangeFormattingEndpoint( IRazorFormattingService razorFormattingService, - IOptionsMonitor optionsMonitor) + RazorLSPOptionsMonitor optionsMonitor) { _razorFormattingService = razorFormattingService ?? throw new ArgumentNullException(nameof(razorFormattingService)); _optionsMonitor = optionsMonitor ?? throw new ArgumentNullException(nameof(optionsMonitor)); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingContentValidationPass.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingContentValidationPass.cs index f7d3c210cc1..cf541ca0f58 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingContentValidationPass.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingContentValidationPass.cs @@ -11,7 +11,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; @@ -23,7 +22,7 @@ internal class FormattingContentValidationPass : FormattingPassBase public FormattingContentValidationPass( IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : base(documentMappingService, clientConnection) { if (loggerFactory is null) @@ -31,7 +30,7 @@ public FormattingContentValidationPass( throw new ArgumentNullException(nameof(loggerFactory)); } - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); } // We want this to run at the very end. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingDiagnosticValidationPass.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingDiagnosticValidationPass.cs index 1524295be61..82f7ba41fb9 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingDiagnosticValidationPass.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingDiagnosticValidationPass.cs @@ -13,7 +13,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; @@ -25,7 +24,7 @@ internal class FormattingDiagnosticValidationPass : FormattingPassBase public FormattingDiagnosticValidationPass( IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : base(documentMappingService, clientConnection) { if (loggerFactory is null) @@ -33,7 +32,7 @@ public FormattingDiagnosticValidationPass( throw new ArgumentNullException(nameof(loggerFactory)); } - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); } // We want this to run at the very end. diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormattingPass.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormattingPass.cs index 30a49a33bb1..a7e62a6abf7 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormattingPass.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormattingPass.cs @@ -14,8 +14,6 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; using TextSpan = Microsoft.CodeAnalysis.Text.TextSpan; @@ -24,14 +22,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; internal class HtmlFormattingPass : FormattingPassBase { private readonly ILogger _logger; - private readonly IOptionsMonitor _optionsMonitor; + private readonly RazorLSPOptionsMonitor _optionsMonitor; public HtmlFormattingPass( IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, IDocumentVersionCache documentVersionCache, - IOptionsMonitor optionsMonitor, - IRazorLoggerFactory loggerFactory) + RazorLSPOptionsMonitor optionsMonitor, + ILoggerFactory loggerFactory) : base(documentMappingService, clientConnection) { if (loggerFactory is null) @@ -39,7 +37,7 @@ public HtmlFormattingPass( throw new ArgumentNullException(nameof(loggerFactory)); } - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); HtmlFormatter = new HtmlFormatter(clientConnection, documentVersionCache); _optionsMonitor = optionsMonitor; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/RazorFormattingPass.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/RazorFormattingPass.cs index bc534c96a43..e415a51200d 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/RazorFormattingPass.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/RazorFormattingPass.cs @@ -14,8 +14,6 @@ using Microsoft.CodeAnalysis.Razor.DocumentMapping; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; @@ -23,12 +21,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; internal class RazorFormattingPass( IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, - IOptionsMonitor optionsMonitor, - IRazorLoggerFactory loggerFactory) + RazorLSPOptionsMonitor optionsMonitor, + ILoggerFactory loggerFactory) : FormattingPassBase(documentMappingService, clientConnection) { - private readonly ILogger _logger = loggerFactory.CreateLogger(); - private readonly IOptionsMonitor _optionsMonitor = optionsMonitor; + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); + private readonly RazorLSPOptionsMonitor _optionsMonitor = optionsMonitor; // Run after the C# formatter pass. public override int Order => DefaultOrder - 4; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/GeneratedDocumentPublisher.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/GeneratedDocumentPublisher.cs index fdd4c21bb09..8d7f783364a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/GeneratedDocumentPublisher.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/GeneratedDocumentPublisher.cs @@ -14,7 +14,6 @@ using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer; @@ -33,13 +32,13 @@ public GeneratedDocumentPublisher( ProjectSnapshotManagerDispatcher dispatcher, IClientConnection clientConnection, LanguageServerFeatureOptions options, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) { _projectManager = projectManager; _dispatcher = dispatcher; _clientConnection = clientConnection; _options = options; - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); _publishedCSharpData = new Dictionary(); // We don't generate individual Html documents per-project, so in order to ensure diffs are calculated correctly diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hosting/ClaspLoggingBridge.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hosting/ClaspLoggingBridge.cs index f0001c41bb3..052e2345037 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hosting/ClaspLoggingBridge.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hosting/ClaspLoggingBridge.cs @@ -5,7 +5,6 @@ using Microsoft.AspNetCore.Razor.Telemetry; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CommonLanguageServerProtocol.Framework; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer.Hosting; @@ -20,28 +19,13 @@ internal class ClaspLoggingBridge : ILspLogger private readonly ILogger _logger; private readonly ITelemetryReporter? _telemetryReporter; - public ClaspLoggingBridge(IRazorLoggerFactory loggerFactory, ITelemetryReporter? telemetryReporter = null) + public ClaspLoggingBridge(ILoggerFactory loggerFactory, ITelemetryReporter? telemetryReporter = null) { - // We're creating this on behalf of CLaSP, because it doesn't know how to use IRazorLoggerFactory, so using that as the category name. - _logger = loggerFactory.CreateLogger("CLaSP"); + // We're creating this on behalf of CLaSP, because it doesn't know how to use our ILoggerFactory, so using that as the category name. + _logger = loggerFactory.GetOrCreateLogger("CLaSP"); _telemetryReporter = telemetryReporter; } - public IDisposable BeginScope(TState state) - { - return _logger.BeginScope(state); - } - - public bool IsEnabled(LogLevel logLevel) - { - return _logger.IsEnabled(logLevel); - } - - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) - { - _logger.Log(logLevel, eventId, state, exception, formatter); - } - public void LogStartContext(string message, params object[] @params) { // This is a special log message formatted so that the LogHub logger can detect it, and trigger the right trace event diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hosting/LspLogger.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hosting/LspLogger.cs index 92dc23724f7..f73f87ed56c 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hosting/LspLogger.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hosting/LspLogger.cs @@ -3,7 +3,7 @@ using System; using System.Threading; -using Microsoft.Extensions.Logging; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Hosting; @@ -24,17 +24,12 @@ public LspLogger(string categoryName, LogLevel logLevel, IClientConnection clien _clientConnection = clientConnection; } - public IDisposable BeginScope(TState state) - { - return new Disposable(); - } - public bool IsEnabled(LogLevel logLevel) { return logLevel >= _logLevel; } - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) + public void Log(LogLevel logLevel, TState state, Exception? exception, Func formatter) { if (!IsEnabled(logLevel)) { @@ -70,11 +65,4 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except _ = _clientConnection.SendNotificationAsync(Methods.WindowLogMessageName, @params, CancellationToken.None); } - - private class Disposable : IDisposable - { - public void Dispose() - { - } - } } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hosting/RazorLanguageServerWrapper.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hosting/RazorLanguageServerWrapper.cs index fc5bc72f6d0..14843ff1289 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hosting/RazorLanguageServerWrapper.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hosting/RazorLanguageServerWrapper.cs @@ -36,7 +36,7 @@ private RazorLanguageServerWrapper(RazorLanguageServer innerServer) public static RazorLanguageServerWrapper Create( Stream input, Stream output, - IRazorLoggerFactory loggerFactory, + ILoggerFactory loggerFactory, ITelemetryReporter telemetryReporter, ProjectSnapshotManagerDispatcher? projectSnapshotManagerDispatcher = null, Action? configure = null, diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/HoverEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/HoverEndpoint.cs index 7c57c1948b3..f8f219ee63a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/HoverEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/HoverEndpoint.cs @@ -10,7 +10,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Hover; @@ -25,8 +24,8 @@ public HoverEndpoint( LanguageServerFeatureOptions languageServerFeatureOptions, IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, - IRazorLoggerFactory loggerFactory) - : base(languageServerFeatureOptions, documentMappingService, clientConnection, loggerFactory.CreateLogger()) + ILoggerFactory loggerFactory) + : base(languageServerFeatureOptions, documentMappingService, clientConnection, loggerFactory.GetOrCreateLogger()) { _hoverService = hoverService ?? throw new ArgumentNullException(nameof(hoverService)); } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/IDocumentPositionInfoStrategy.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/IDocumentPositionInfoStrategy.cs index 7410740f36f..b2cdbc19a05 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/IDocumentPositionInfoStrategy.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/IDocumentPositionInfoStrategy.cs @@ -4,8 +4,8 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ILoggerExtensions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ILoggerExtensions.cs index aa8d16440f6..94018346769 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ILoggerExtensions.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ILoggerExtensions.cs @@ -2,7 +2,7 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using System.Diagnostics; -using Microsoft.Extensions.Logging; +using Microsoft.CodeAnalysis.Razor.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Implementation/ImplementationEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Implementation/ImplementationEndpoint.cs index e9e23cbb1b0..5c19314fd8a 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Implementation/ImplementationEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Implementation/ImplementationEndpoint.cs @@ -10,7 +10,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; using ImplementationResult = Microsoft.VisualStudio.LanguageServer.Protocol.SumType< Microsoft.VisualStudio.LanguageServer.Protocol.Location[], @@ -27,8 +26,8 @@ public ImplementationEndpoint( LanguageServerFeatureOptions languageServerFeatureOptions, IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, - IRazorLoggerFactory loggerFactory) - : base(languageServerFeatureOptions, documentMappingService, clientConnection, loggerFactory.CreateLogger()) + ILoggerFactory loggerFactory) + : base(languageServerFeatureOptions, documentMappingService, clientConnection, loggerFactory.GetOrCreateLogger()) { _documentMappingService = documentMappingService ?? throw new ArgumentNullException(nameof(documentMappingService)); } 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 4b1027362a5..31cc544bbdf 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/InlineCompletion/InlineCompletionEndPoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/InlineCompletion/InlineCompletionEndPoint.cs @@ -19,7 +19,6 @@ using Microsoft.CodeAnalysis.Razor.Protocol.Completion; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.InlineCompletion; @@ -29,7 +28,7 @@ internal sealed class InlineCompletionEndpoint( IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, IAdhocWorkspaceFactory adhocWorkspaceFactory, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : IRazorRequestHandler, ICapabilitiesProvider { private static readonly ImmutableHashSet s_cSharpKeywords = ImmutableHashSet.Create( @@ -40,7 +39,7 @@ internal sealed class InlineCompletionEndpoint( private readonly IRazorDocumentMappingService _documentMappingService = documentMappingService ?? throw new ArgumentNullException(nameof(documentMappingService)); private readonly IClientConnection _clientConnection = clientConnection ?? throw new ArgumentNullException(nameof(clientConnection)); private readonly IAdhocWorkspaceFactory _adhocWorkspaceFactory = adhocWorkspaceFactory ?? throw new ArgumentNullException(nameof(adhocWorkspaceFactory)); - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public bool MutatesSolutionState => false; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LanguageServerErrorReporter.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LanguageServerErrorReporter.cs index 8a9f54837f0..c03c704d2f6 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LanguageServerErrorReporter.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LanguageServerErrorReporter.cs @@ -6,7 +6,6 @@ using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer; @@ -14,14 +13,14 @@ internal class LanguageServerErrorReporter : IErrorReporter { private readonly ILogger _logger; - public LanguageServerErrorReporter(IRazorLoggerFactory loggerFactory) + public LanguageServerErrorReporter(ILoggerFactory loggerFactory) { if (loggerFactory is null) { throw new ArgumentNullException(nameof(loggerFactory)); } - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); } public void ReportError(Exception exception) diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LinkedEditingRange/LinkedEditingRangeEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LinkedEditingRange/LinkedEditingRangeEndpoint.cs index 367ea6a1f73..bfd3b3eee8b 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LinkedEditingRange/LinkedEditingRangeEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LinkedEditingRange/LinkedEditingRangeEndpoint.cs @@ -11,7 +11,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.LinkedEditingRange; @@ -27,14 +26,14 @@ internal class LinkedEditingRangeEndpoint : IRazorRequestHandler(); + _logger = loggerFactory.GetOrCreateLogger(); } public bool MutatesSolutionState => false; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LspProjectEngineFactoryProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LspProjectEngineFactoryProvider.cs index 745a9a54e49..54e1ef845a9 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LspProjectEngineFactoryProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/LspProjectEngineFactoryProvider.cs @@ -3,9 +3,7 @@ using System; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.ProjectEngineHost; -using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Razor.LanguageServer; @@ -14,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer; /// and configure every /// with the current code-gen options. /// -internal sealed class LspProjectEngineFactoryProvider(IOptionsMonitor optionsMonitor) : IProjectEngineFactoryProvider +internal sealed class LspProjectEngineFactoryProvider(RazorLSPOptionsMonitor optionsMonitor) : IProjectEngineFactoryProvider { public IProjectEngineFactory GetFactory(RazorConfiguration configuration) { @@ -23,7 +21,7 @@ public IProjectEngineFactory GetFactory(RazorConfiguration configuration) return new Factory(factory, optionsMonitor); } - private class Factory(IProjectEngineFactory innerFactory, IOptionsMonitor optionsMonitor) : IProjectEngineFactory + private class Factory(IProjectEngineFactory innerFactory, RazorLSPOptionsMonitor optionsMonitor) : IProjectEngineFactory { public string ConfigurationName => innerFactory.ConfigurationName; @@ -47,7 +45,7 @@ void Configure(RazorProjectEngineBuilder builder) } } - private class CodeGenFeature(IOptionsMonitor optionsMonitor) : RazorEngineFeatureBase, IConfigureRazorCodeGenerationOptionsFeature + private class CodeGenFeature(RazorLSPOptionsMonitor optionsMonitor) : RazorEngineFeatureBase, IConfigureRazorCodeGenerationOptionsFeature { public int Order { get; set; } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Mapping/RazorLanguageQueryEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Mapping/RazorLanguageQueryEndpoint.cs index 15b9c43e66a..d8e226ebde5 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Mapping/RazorLanguageQueryEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Mapping/RazorLanguageQueryEndpoint.cs @@ -9,17 +9,16 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Mapping; [RazorLanguageServerEndpoint(LanguageServerConstants.RazorLanguageQueryEndpoint)] -internal sealed class RazorLanguageQueryEndpoint(IRazorDocumentMappingService documentMappingService, IRazorLoggerFactory loggerFactory) +internal sealed class RazorLanguageQueryEndpoint(IRazorDocumentMappingService documentMappingService, ILoggerFactory loggerFactory) : IRazorRequestHandler { private readonly IRazorDocumentMappingService _documentMappingService = documentMappingService; - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public bool MutatesSolutionState { get; } = false; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Microsoft.AspNetCore.Razor.LanguageServer.csproj b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Microsoft.AspNetCore.Razor.LanguageServer.csproj index f412871b184..55e955e8d38 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Microsoft.AspNetCore.Razor.LanguageServer.csproj +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Microsoft.AspNetCore.Razor.LanguageServer.csproj @@ -22,8 +22,6 @@ - - diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/PreferAttributeNameDocumentPositionInfoStrategy.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/PreferAttributeNameDocumentPositionInfoStrategy.cs index fb501e6249b..bf829aade9e 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/PreferAttributeNameDocumentPositionInfoStrategy.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/PreferAttributeNameDocumentPositionInfoStrategy.cs @@ -4,9 +4,9 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeDetector.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeDetector.cs index 421afa2759d..3958289cb63 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeDetector.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeDetector.cs @@ -11,7 +11,6 @@ using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer; @@ -34,7 +33,7 @@ public ProjectConfigurationFileChangeDetector( ProjectSnapshotManagerDispatcher dispatcher, IEnumerable listeners, LanguageServerFeatureOptions options, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) { if (loggerFactory is null) { @@ -44,7 +43,7 @@ public ProjectConfigurationFileChangeDetector( _dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher)); _listeners = listeners ?? throw new ArgumentNullException(nameof(listeners)); _options = options ?? throw new ArgumentNullException(nameof(options)); - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); } public async Task StartAsync(string workspaceDirectory, CancellationToken cancellationToken) @@ -150,8 +149,6 @@ protected virtual void OnInitializationFinished() // Protected virtual for testing protected virtual IEnumerable GetExistingConfigurationFiles(string workspaceDirectory) { - using var _ = _logger.BeginScope("Searching for existing project configuration files"); - return DirectoryHelper.GetFilteredFiles( workspaceDirectory, _options.ProjectConfigurationFileName, diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs index e56d6043ad1..646324e6345 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs @@ -15,7 +15,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer; @@ -31,13 +30,13 @@ internal class ProjectConfigurationStateSynchronizer : IProjectConfigurationFile public ProjectConfigurationStateSynchronizer( ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher, IRazorProjectService projectService, - IRazorLoggerFactory loggerFactory, + ILoggerFactory loggerFactory, LanguageServerFeatureOptions languageServerFeatureOptions) { _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher; _projectService = projectService; _languageServerFeatureOptions = languageServerFeatureOptions; - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); _configurationToProjectMap = new Dictionary(FilePathComparer.Instance); ProjectInfoMap = new Dictionary(); } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/MonitorProjectConfigurationFilePathEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/MonitorProjectConfigurationFilePathEndpoint.cs index c24f6dd2598..dbb996fefe7 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/MonitorProjectConfigurationFilePathEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/MonitorProjectConfigurationFilePathEndpoint.cs @@ -14,7 +14,6 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Razor.Workspaces.Protocol.ProjectSystem; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem; @@ -26,7 +25,7 @@ internal class MonitorProjectConfigurationFilePathEndpoint : IRazorNotificationH private readonly WorkspaceDirectoryPathResolver _workspaceDirectoryPathResolver; private readonly IEnumerable _listeners; private readonly LanguageServerFeatureOptions _options; - private readonly IRazorLoggerFactory _loggerFactory; + private readonly ILoggerFactory _loggerFactory; private readonly ILogger _logger; private readonly ConcurrentDictionary _outputPathMonitors; private readonly object _disposeLock; @@ -40,7 +39,7 @@ public MonitorProjectConfigurationFilePathEndpoint( WorkspaceDirectoryPathResolver workspaceDirectoryPathResolver, IEnumerable listeners, LanguageServerFeatureOptions options, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) { _projectManager = projectManager; _dispatcher = dispatcher; @@ -48,7 +47,7 @@ public MonitorProjectConfigurationFilePathEndpoint( _listeners = listeners; _options = options; _loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); _outputPathMonitors = new ConcurrentDictionary(FilePathComparer.Instance); _disposeLock = new object(); } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs index bfa6dbc1d81..e68b904ce9f 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/RazorProjectService.cs @@ -19,7 +19,6 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem; @@ -29,7 +28,7 @@ internal class RazorProjectService( ISnapshotResolver snapshotResolver, IDocumentVersionCache documentVersionCache, IProjectSnapshotManager projectManager, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : IRazorProjectService { private readonly IProjectSnapshotManager _projectManager = projectManager; @@ -37,7 +36,7 @@ internal class RazorProjectService( private readonly RemoteTextLoaderFactory _remoteTextLoaderFactory = remoteTextLoaderFactory; private readonly ISnapshotResolver _snapshotResolver = snapshotResolver; private readonly IDocumentVersionCache _documentVersionCache = documentVersionCache; - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public void AddDocument(string filePath) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/SnapshotResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/SnapshotResolver.cs index 58a379a4331..3bc1f08256e 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/SnapshotResolver.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/SnapshotResolver.cs @@ -10,7 +10,6 @@ using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem; @@ -22,10 +21,10 @@ internal sealed class SnapshotResolver : ISnapshotResolver // Internal for testing internal readonly HostProject MiscellaneousHostProject; - public SnapshotResolver(IProjectSnapshotManager projectManager, IRazorLoggerFactory loggerFactory) + public SnapshotResolver(IProjectSnapshotManager projectManager, ILoggerFactory loggerFactory) { _projectManager = projectManager; - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); var miscellaneousProjectPath = Path.Combine(TempDirectory.Instance.DirectoryPath, "__MISC_RAZOR_PROJECT__"); var normalizedPath = FilePathNormalizer.Normalize(miscellaneousProjectPath); diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorConfigurationEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorConfigurationEndpoint.cs index 3e29bd90b04..1928c4af116 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorConfigurationEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorConfigurationEndpoint.cs @@ -6,16 +6,15 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts; using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer; -internal class RazorConfigurationEndpoint(RazorLSPOptionsMonitor optionsMonitor, IRazorLoggerFactory loggerFactory) +internal class RazorConfigurationEndpoint(RazorLSPOptionsMonitor optionsMonitor, ILoggerFactory loggerFactory) : IDidChangeConfigurationEndpoint, IOnInitialized { private readonly RazorLSPOptionsMonitor _optionsMonitor = optionsMonitor ?? throw new ArgumentNullException(nameof(optionsMonitor)); - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public bool MutatesSolutionState => true; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorDocumentMappingService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorDocumentMappingService.cs index 96cc594b905..61d7886acef 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorDocumentMappingService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorDocumentMappingService.cs @@ -5,14 +5,13 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer; internal sealed class RazorDocumentMappingService( IFilePathService filePathService, IDocumentContextFactory documentContextFactory, - IRazorLoggerFactory loggerFactory) - : AbstractRazorDocumentMappingService(filePathService, documentContextFactory, loggerFactory.CreateLogger()) + ILoggerFactory loggerFactory) + : AbstractRazorDocumentMappingService(filePathService, documentContextFactory, loggerFactory.GetOrCreateLogger()) { } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLSPOptionsMonitor.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLSPOptionsMonitor.cs index 65c969ca342..ff1d28611cc 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLSPOptionsMonitor.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLSPOptionsMonitor.cs @@ -5,43 +5,29 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; -using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Razor.LanguageServer; -internal class RazorLSPOptionsMonitor : IOptionsMonitor +internal class RazorLSPOptionsMonitor { private readonly IConfigurationSyncService _configurationService; - private readonly IOptionsMonitorCache _cache; - private event Action? OnChangeEvent; + private event Action? OnChangeEvent; private RazorLSPOptions _currentValue; - public RazorLSPOptionsMonitor(IConfigurationSyncService configurationService, IOptionsMonitorCache cache, RazorLSPOptions currentOptions) + public RazorLSPOptionsMonitor(IConfigurationSyncService configurationService, RazorLSPOptions currentOptions) { if (configurationService is null) { throw new ArgumentNullException(nameof(configurationService)); } - if (cache is null) - { - throw new ArgumentNullException(nameof(cache)); - } - _configurationService = configurationService; - _cache = cache; _currentValue = currentOptions; } - public RazorLSPOptions CurrentValue => Get(Options.DefaultName); - - public RazorLSPOptions Get(string name) - { - name ??= Options.DefaultName; - return _cache.GetOrAdd(name, () => _currentValue); - } + public RazorLSPOptions CurrentValue => _currentValue; - public IDisposable OnChange(Action listener) + public IDisposable OnChange(Action listener) { var disposable = new ChangeTrackerDisposable(this, listener); OnChangeEvent += disposable.OnChange; @@ -60,24 +46,21 @@ public virtual async Task UpdateAsync(CancellationToken cancellationToken = defa private void InvokeChanged() { - var name = Options.DefaultName; - _cache.TryRemove(name); - var options = Get(name); - OnChangeEvent?.Invoke(options, name); + OnChangeEvent?.Invoke(_currentValue); } internal class ChangeTrackerDisposable : IDisposable { - private readonly Action _listener; + private readonly Action _listener; private readonly RazorLSPOptionsMonitor _monitor; - public ChangeTrackerDisposable(RazorLSPOptionsMonitor monitor, Action listener) + public ChangeTrackerDisposable(RazorLSPOptionsMonitor monitor, Action listener) { _listener = listener; _monitor = monitor; } - public void OnChange(RazorLSPOptions options, string name) => _listener.Invoke(options, name); + public void OnChange(RazorLSPOptions options) => _listener.Invoke(options); public void Dispose() => _monitor.OnChangeEvent -= OnChange; } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.LoggerFactoryWrapper.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.LoggerFactoryWrapper.cs index 507d1d492ad..479e9d09797 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.LoggerFactoryWrapper.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.LoggerFactoryWrapper.cs @@ -2,36 +2,30 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer; internal partial class RazorLanguageServer { /// - /// Very small wrapper around the to add a prefix to the category name, so we can tell in the logs + /// Very small wrapper around the to add a prefix to the category name, so we can tell in the logs /// whether things are coming from the VS side, the LSP side, of our code. This is only temporary and will be removed when we move /// to cohosting as there will only be one side. /// - private sealed class LoggerFactoryWrapper(IRazorLoggerFactory loggerFactory) : IRazorLoggerFactory + private sealed class LoggerFactoryWrapper(ILoggerFactory loggerFactory) : ILoggerFactory { - private IRazorLoggerFactory _loggerFactory = loggerFactory; + private ILoggerFactory _loggerFactory = loggerFactory; - public void AddLoggerProvider(IRazorLoggerProvider provider) + public void AddLoggerProvider(ILoggerProvider provider) { _loggerFactory.AddLoggerProvider(provider); } - public ILogger CreateLogger(string categoryName) + public ILogger GetOrCreateLogger(string categoryName) { // Adding [LSP] to the start to identify the LSP server, as some of our services exist in the server, and in VS // It looks weird because the category is surround with square brackets, so this ends up being [LSP][Category] - return _loggerFactory.CreateLogger($"LSP][{categoryName}"); - } - - public void Dispose() - { - _loggerFactory.Dispose(); + return _loggerFactory.GetOrCreateLogger($"LSP][{categoryName}"); } } } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs index 51889eb080e..3f123b2749d 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer; internal partial class RazorLanguageServer : AbstractLanguageServer { private readonly JsonRpc _jsonRpc; - private readonly IRazorLoggerFactory _loggerFactory; + private readonly ILoggerFactory _loggerFactory; private readonly LanguageServerFeatureOptions? _featureOptions; private readonly ProjectSnapshotManagerDispatcher? _projectSnapshotManagerDispatcher; private readonly Action? _configureServer; @@ -51,7 +51,7 @@ internal partial class RazorLanguageServer : AbstractLanguageServer? configureServer, @@ -74,7 +74,7 @@ public RazorLanguageServer( Initialize(); } - private static ILspLogger CreateILspLogger(IRazorLoggerFactory loggerFactory, ITelemetryReporter telemetryReporter) + private static ILspLogger CreateILspLogger(ILoggerFactory loggerFactory, ITelemetryReporter telemetryReporter) { return new ClaspLoggingBridge(loggerFactory, telemetryReporter); } @@ -90,12 +90,11 @@ protected override IRequestExecutionQueue ConstructRequestE protected override ILspServices ConstructLspServices() { - var services = new ServiceCollection() - .AddOptions(); + var services = new ServiceCollection(); var loggerFactoryWrapper = new LoggerFactoryWrapper(_loggerFactory); // Wrap the logger factory so that we can add [LSP] to the start of all the categories - services.AddSingleton(loggerFactoryWrapper); + services.AddSingleton(loggerFactoryWrapper); if (_configureServer is not null) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorRequestContextFactory.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorRequestContextFactory.cs index 88f7b9ff3e3..956408de01f 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorRequestContextFactory.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorRequestContextFactory.cs @@ -9,7 +9,6 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CommonLanguageServerProtocol.Framework; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer; @@ -20,7 +19,7 @@ internal class RazorRequestContextFactory(ILspServices lspServices) : AbstractRe public override Task CreateRequestContextAsync(IQueueItem queueItem, IMethodHandler methodHandler, TRequestParams @params, CancellationToken cancellationToken) { - var logger = _lspServices.GetRequiredService().CreateLogger(); + var logger = _lspServices.GetRequiredService().GetOrCreateLogger(); VersionedDocumentContext? documentContext = null; var textDocumentHandler = methodHandler as ITextDocumentIdentifierHandler; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/RenameEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/RenameEndpoint.cs index b6ab0ce757b..9a86b6593b3 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/RenameEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/RenameEndpoint.cs @@ -20,7 +20,6 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Refactoring; @@ -33,12 +32,12 @@ internal sealed class RenameEndpoint( LanguageServerFeatureOptions languageServerFeatureOptions, IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : AbstractRazorDelegatingEndpoint( languageServerFeatureOptions, documentMappingService, clientConnection, - loggerFactory.CreateLogger()), ICapabilitiesProvider + loggerFactory.GetOrCreateLogger()), ICapabilitiesProvider { private readonly ProjectSnapshotManagerDispatcher _dispatcher = dispatcher; private readonly IProjectSnapshotManager _projectManager = projectManager; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/LSPCSharpSemanticTokensProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/LSPCSharpSemanticTokensProvider.cs index 5aa9f675810..2f749685e56 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/LSPCSharpSemanticTokensProvider.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/LSPCSharpSemanticTokensProvider.cs @@ -14,15 +14,14 @@ using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Razor.Workspaces.Protocol.SemanticTokens; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic; -internal class LSPCSharpSemanticTokensProvider(LanguageServerFeatureOptions languageServerFeatureOptions, IClientConnection clientConnection, IRazorLoggerFactory loggerFactory) : ICSharpSemanticTokensProvider +internal class LSPCSharpSemanticTokensProvider(LanguageServerFeatureOptions languageServerFeatureOptions, IClientConnection clientConnection, ILoggerFactory loggerFactory) : ICSharpSemanticTokensProvider { private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions; private readonly IClientConnection _clientConnection = clientConnection; - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public async Task GetCSharpSemanticTokensResponseAsync( VersionedDocumentContext documentContext, diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/RazorSemanticTokensInfoService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/RazorSemanticTokensInfoService.cs index b480c3b1198..4a2bd4da4e4 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/RazorSemanticTokensInfoService.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/RazorSemanticTokensInfoService.cs @@ -13,7 +13,7 @@ internal class RazorSemanticTokensInfoService( ISemanticTokensLegendService semanticTokensLegendService, ICSharpSemanticTokensProvider csharpSemanticTokensProvider, LanguageServerFeatureOptions languageServerFeatureOptions, - IRazorLoggerFactory loggerFactory) - : AbstractRazorSemanticTokensInfoService(documentMappingService, semanticTokensLegendService, csharpSemanticTokensProvider, languageServerFeatureOptions, loggerFactory.CreateLogger()) + ILoggerFactory loggerFactory) + : AbstractRazorSemanticTokensInfoService(documentMappingService, semanticTokensLegendService, csharpSemanticTokensProvider, languageServerFeatureOptions, loggerFactory.GetOrCreateLogger()) { } diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/SignatureHelp/SignatureHelpEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/SignatureHelp/SignatureHelpEndpoint.cs index f7cb1cab436..69439038b1c 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/SignatureHelp/SignatureHelpEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/SignatureHelp/SignatureHelpEndpoint.cs @@ -9,8 +9,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; using LS = Microsoft.VisualStudio.LanguageServer.Protocol; @@ -21,13 +19,13 @@ internal sealed class SignatureHelpEndpoint( LanguageServerFeatureOptions languageServerFeatureOptions, IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, - IOptionsMonitor optionsMonitor, - IRazorLoggerFactory loggerProvider) + RazorLSPOptionsMonitor optionsMonitor, + ILoggerFactory loggerProvider) : AbstractRazorDelegatingEndpoint( languageServerFeatureOptions, documentMappingService, clientConnection, - loggerProvider.CreateLogger()), + loggerProvider.GetOrCreateLogger()), ICapabilitiesProvider { protected override string CustomMessageTarget => CustomMessageNames.RazorSignatureHelpEndpointName; diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/WorkspaceSemanticTokensRefreshNotifier.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/WorkspaceSemanticTokensRefreshNotifier.cs index d71a0c57af1..4233dadff58 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/WorkspaceSemanticTokensRefreshNotifier.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/WorkspaceSemanticTokensRefreshNotifier.cs @@ -49,7 +49,7 @@ public void Dispose() _disposeTokenSource.Dispose(); } - private void HandleOptionsChange(RazorLSPOptions options, string _) + private void HandleOptionsChange(RazorLSPOptions options) { if (options.ColorBackground != _isColoringBackground) { diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/WrapWithTag/WrapWithTagEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/WrapWithTag/WrapWithTagEndpoint.cs index 9f1d91f7708..5f2c2d465f1 100644 --- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/WrapWithTag/WrapWithTagEndpoint.cs +++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/WrapWithTag/WrapWithTagEndpoint.cs @@ -13,7 +13,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.WrapWithTag; @@ -22,12 +21,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.WrapWithTag; internal class WrapWithTagEndpoint( IClientConnection clientConnection, IRazorDocumentMappingService razorDocumentMappingService, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : IRazorRequestHandler { private readonly IClientConnection _clientConnection = clientConnection ?? throw new ArgumentNullException(nameof(clientConnection)); private readonly IRazorDocumentMappingService _razorDocumentMappingService = razorDocumentMappingService ?? throw new ArgumentNullException(nameof(razorDocumentMappingService)); - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public bool MutatesSolutionState => false; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DocumentMapping/AbstractRazorDocumentMappingService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DocumentMapping/AbstractRazorDocumentMappingService.cs index 8ef20fec93f..5bcc6cbaba0 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DocumentMapping/AbstractRazorDocumentMappingService.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DocumentMapping/AbstractRazorDocumentMappingService.cs @@ -12,11 +12,11 @@ using Microsoft.AspNetCore.Razor.Language.Legacy; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.CodeAnalysis.Razor.DocumentMapping; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/LinePositionExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/LinePositionExtensions.cs index f8e544f3304..0e547fe85a1 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/LinePositionExtensions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/LinePositionExtensions.cs @@ -1,8 +1,8 @@ // 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.Razor.Logging; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.CodeAnalysis.Razor.Workspaces; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/PositionExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/PositionExtensions.cs index 9dc90a02fdd..767b310176a 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/PositionExtensions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/PositionExtensions.cs @@ -4,8 +4,8 @@ using System; using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.Razor.Language; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.CodeAnalysis.Razor.Workspaces; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/RazorSyntaxTreeExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/RazorSyntaxTreeExtensions.cs index 3d3b6498435..e7c3ad83dd5 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/RazorSyntaxTreeExtensions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/RazorSyntaxTreeExtensions.cs @@ -5,8 +5,8 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Razor.Language; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.CodeAnalysis.Razor.Workspaces; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/SourceTextExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/SourceTextExtensions.cs index b02579ee195..c4d4a1ed24e 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/SourceTextExtensions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/SourceTextExtensions.cs @@ -4,8 +4,8 @@ using System; using System.Diagnostics; using Microsoft.AspNetCore.Razor.Language; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; namespace Microsoft.CodeAnalysis.Razor.Workspaces; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/AbstractLoggerFactory.AggregateLogger.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/AbstractLoggerFactory.AggregateLogger.cs new file mode 100644 index 00000000000..57c9d638552 --- /dev/null +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/AbstractLoggerFactory.AggregateLogger.cs @@ -0,0 +1,44 @@ +// 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.Collections.Immutable; + +namespace Microsoft.CodeAnalysis.Razor.Logging; + +internal abstract partial class AbstractLoggerFactory +{ + private class AggregateLogger(ImmutableArray loggers) : ILogger + { + private ImmutableArray _loggers = loggers; + + public bool IsEnabled(LogLevel logLevel) + { + foreach (var logger in _loggers) + { + if (logger.IsEnabled(logLevel)) + { + return true; + } + } + + return false; + } + + public void Log(LogLevel logLevel, TState state, Exception? exception, Func formatter) + { + foreach (var logger in _loggers) + { + if (logger.IsEnabled(logLevel)) + { + logger.Log(logLevel, state, exception, formatter); + } + } + } + + internal void AddLogger(ILogger logger) + { + ImmutableInterlocked.Update(ref _loggers, (set, l) => set.Add(l), logger); + } + } +} diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/AbstractLoggerFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/AbstractLoggerFactory.cs new file mode 100644 index 00000000000..70ae45dbf27 --- /dev/null +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/AbstractLoggerFactory.cs @@ -0,0 +1,53 @@ +// 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.Collections.Immutable; +using Microsoft.AspNetCore.Razor.PooledObjects; + +#if !NET7_0_OR_GREATER +using System.Collections.Generic; +#endif + +namespace Microsoft.CodeAnalysis.Razor.Logging; + +internal abstract partial class AbstractLoggerFactory : ILoggerFactory +{ + private ImmutableDictionary _loggers; + private ImmutableArray _providers; + + protected AbstractLoggerFactory(ImmutableArray providers) + { + _providers = providers; + _loggers = ImmutableDictionary.Create(StringComparer.OrdinalIgnoreCase); + } + + public ILogger GetOrCreateLogger(string categoryName) + { + if (_loggers.TryGetValue(categoryName, out var logger)) + { + return logger; + } + + using var loggers = new PooledArrayBuilder(_providers.Length); + + foreach (var provider in _providers) + { + loggers.Add(provider.CreateLogger(categoryName)); + } + + var result = new AggregateLogger(loggers.DrainToImmutable()); + return ImmutableInterlocked.AddOrUpdate(ref _loggers, categoryName, result, (k, v) => v); + } + + public void AddLoggerProvider(ILoggerProvider provider) + { + if (ImmutableInterlocked.Update(ref _providers, (set, p) => set.Add(p), provider)) + { + foreach (var (category, logger) in _loggers) + { + logger.AddLogger(provider.CreateLogger(category)); + } + } + } +} diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/AbstractRazorLoggerFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/AbstractRazorLoggerFactory.cs deleted file mode 100644 index 857827b29e2..00000000000 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/AbstractRazorLoggerFactory.cs +++ /dev/null @@ -1,41 +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.Collections.Immutable; -using Microsoft.Extensions.Logging; - -namespace Microsoft.CodeAnalysis.Razor.Logging; - -internal abstract class AbstractRazorLoggerFactory : IRazorLoggerFactory -{ - private readonly ILoggerFactory _loggerFactory; - - protected AbstractRazorLoggerFactory(ImmutableArray providers) - { - _loggerFactory = LoggerFactory.Create(b => - { - // We let everything through, and expect individual loggers to control their own levels - b.AddFilter(level => true); - - foreach (var provider in providers) - { - b.AddProvider(provider); - } - }); - } - - public ILogger CreateLogger(string categoryName) - { - return _loggerFactory.CreateLogger(categoryName); - } - - public void AddLoggerProvider(IRazorLoggerProvider provider) - { - _loggerFactory.AddProvider(provider); - } - - public void Dispose() - { - _loggerFactory.Dispose(); - } -} diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILogger.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILogger.cs new file mode 100644 index 00000000000..a00d7b6a661 --- /dev/null +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILogger.cs @@ -0,0 +1,13 @@ +// 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.Logging; + +internal interface ILogger +{ + void Log(LogLevel logLevel, TState state, Exception? exception, Func formatter); + + bool IsEnabled(LogLevel logLevel); +} diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerExtensions.cs new file mode 100644 index 00000000000..9889495a28c --- /dev/null +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerExtensions.cs @@ -0,0 +1,151 @@ +// 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 Microsoft.AspNetCore.Razor.PooledObjects; + +namespace Microsoft.CodeAnalysis.Razor.Logging; + +internal static class ILoggerExtensions +{ + public static void LogTrace(this ILogger logger, string? message, params object?[] args) + { + Log(logger, LogLevel.Trace, exception: null, message, args); + } + + public static void LogDebug(this ILogger logger, string? message, params object?[] args) + { + Log(logger, LogLevel.Debug, exception: null, message, args); + } + + public static void LogInformation(this ILogger logger, string? message, params object?[] args) + { + Log(logger, LogLevel.Information, exception: null, message, args); + } + + public static void LogWarning(this ILogger logger, string? message, params object?[] args) + { + Log(logger, LogLevel.Warning, exception: null, message, args); + } + + public static void LogWarning(this ILogger logger, Exception exception, string? message, params object?[] args) + { + Log(logger, LogLevel.Warning, exception, message, args); + } + + public static void LogError(this ILogger logger, string? message, params object?[] args) + { + Log(logger, LogLevel.Error, exception: null, message, args); + } + + public static void LogError(this ILogger logger, Exception exception, string? message, params object?[] args) + { + Log(logger, LogLevel.Error, exception, message, args); + } + + public static void LogCritical(this ILogger logger, Exception exception, string? message, params object?[] args) + { + Log(logger, LogLevel.Critical, exception, message, args); + } + + private static void Log(ILogger logger, LogLevel level, Exception? exception, string? message, object?[] args) + { + logger.Log(level, (message, args), exception, FormatMessage); + } + + private static string FormatMessage((string? message, object?[] args) s, Exception? exception) + { + var (format, args) = s; + if (format is null) + { + return "[null]"; + } + + // from: https://github.com/dotnet/runtime/blob/ec4437be46d8b90bc9fa6740c556bd860d9fe5ab/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogValuesFormatter.cs + using var _ = StringBuilderPool.GetPooledObject(out var vsb); + var scanIndex = 0; + var endIndex = format.Length; + + var count = 0; + + while (scanIndex < endIndex) + { + var openBraceIndex = FindBraceIndex(format, '{', scanIndex, endIndex); + if (scanIndex == 0 && openBraceIndex == endIndex) + { + // No holes found. + return format; + } + + var closeBraceIndex = FindBraceIndex(format, '}', openBraceIndex, endIndex); + + if (closeBraceIndex == endIndex) + { + vsb.Append(format, scanIndex, endIndex - scanIndex); + scanIndex = endIndex; + } + else + { + // Format item syntax : { index[,alignment][ :formatString] }. + var formatDelimiterIndex = format.AsSpan(openBraceIndex, closeBraceIndex - openBraceIndex).IndexOfAny(',', ':'); + formatDelimiterIndex = formatDelimiterIndex < 0 ? closeBraceIndex : formatDelimiterIndex + openBraceIndex; + + vsb.Append(format, scanIndex, openBraceIndex - scanIndex + 1); + vsb.Append(count++); + vsb.Append(format, formatDelimiterIndex, closeBraceIndex - formatDelimiterIndex + 1); + + scanIndex = closeBraceIndex + 1; + } + } + + return string.Format(vsb.ToString(), args); + } + + private static int FindBraceIndex(string format, char brace, int startIndex, int endIndex) + { + // Example: {{prefix{{{Argument}}}suffix}}. + var braceIndex = endIndex; + var scanIndex = startIndex; + var braceOccurrenceCount = 0; + + while (scanIndex < endIndex) + { + if (braceOccurrenceCount > 0 && format[scanIndex] != brace) + { + if (braceOccurrenceCount % 2 == 0) + { + // Even number of '{' or '}' found. Proceed search with next occurrence of '{' or '}'. + braceOccurrenceCount = 0; + braceIndex = endIndex; + } + else + { + // An unescaped '{' or '}' found. + break; + } + } + else if (format[scanIndex] == brace) + { + if (brace == '}') + { + if (braceOccurrenceCount == 0) + { + // For '}' pick the first occurrence. + braceIndex = scanIndex; + } + } + else + { + // For '{' pick the last occurrence. + braceIndex = scanIndex; + } + + braceOccurrenceCount++; + } + + scanIndex++; + } + + return braceIndex; + } +} diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/IRazorLoggerFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerFactory.cs similarity index 58% rename from src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/IRazorLoggerFactory.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerFactory.cs index 03c0de5e3c8..fdf319368db 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/IRazorLoggerFactory.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerFactory.cs @@ -1,14 +1,11 @@ // 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 Microsoft.Extensions.Logging; - namespace Microsoft.CodeAnalysis.Razor.Logging; // Our version of ILoggerFactory, so that we're not MEF importing general use types -internal interface IRazorLoggerFactory : IDisposable +internal interface ILoggerFactory { - void AddLoggerProvider(IRazorLoggerProvider provider); - ILogger CreateLogger(string categoryName); + void AddLoggerProvider(ILoggerProvider provider); + ILogger GetOrCreateLogger(string categoryName); } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/IRazorLoggerFactoryExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerFactoryExtensions.cs similarity index 79% rename from src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/IRazorLoggerFactoryExtensions.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerFactoryExtensions.cs index 5cf892be690..db7ef6f6742 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/IRazorLoggerFactoryExtensions.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerFactoryExtensions.cs @@ -2,15 +2,14 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using System; -using Microsoft.Extensions.Logging; namespace Microsoft.CodeAnalysis.Razor.Logging; -internal static class IRazorLoggerFactoryExtensions +internal static class ILoggerFactoryExtensions { - public static ILogger CreateLogger(this IRazorLoggerFactory factory) + public static ILogger GetOrCreateLogger(this ILoggerFactory factory) { - return factory.CreateLogger(TrimTypeName(typeof(T).FullName)); + return factory.GetOrCreateLogger(TrimTypeName(typeof(T).FullName)); } private static string TrimTypeName(string name) diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/IRazorLoggerProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerProvider.cs similarity index 51% rename from src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/IRazorLoggerProvider.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerProvider.cs index 1763d269093..4b948c00935 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/IRazorLoggerProvider.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/ILoggerProvider.cs @@ -1,11 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -using Microsoft.Extensions.Logging; - namespace Microsoft.CodeAnalysis.Razor.Logging; -// Very very light wrapper for ILoggerProvider, so that we're not MEF importing general use types -internal interface IRazorLoggerProvider : ILoggerProvider +internal interface ILoggerProvider { + ILogger CreateLogger(string categoryName); } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/LogLevel.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/LogLevel.cs new file mode 100644 index 00000000000..a5d591f995e --- /dev/null +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Logging/LogLevel.cs @@ -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. + +namespace Microsoft.CodeAnalysis.Razor.Logging; + +internal enum LogLevel +{ + Trace, + Debug, + Information, + Warning, + Error, + Critical, + None +} diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj index 1270f1275c4..496bff9eab4 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj @@ -22,7 +22,6 @@ - diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs index a8046b2fed2..76a01fc54aa 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/SemanticTokens/AbstractRazorSemanticTokensInfoService.cs @@ -12,10 +12,10 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.CodeAnalysis.Razor.DocumentMapping; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; namespace Microsoft.CodeAnalysis.Razor.SemanticTokens; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Settings/ClientSettings.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Settings/ClientSettings.cs index 10379aeb4c4..568b7f38da7 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Settings/ClientSettings.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Settings/ClientSettings.cs @@ -2,7 +2,7 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using System; -using Microsoft.Extensions.Logging; +using Microsoft.CodeAnalysis.Razor.Logging; namespace Microsoft.CodeAnalysis.Razor.Settings; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor.CoreComponents/Microsoft.CodeAnalysis.Remote.Razor.CoreComponents.csproj b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor.CoreComponents/Microsoft.CodeAnalysis.Remote.Razor.CoreComponents.csproj index 990b86a5cc1..5fa47a1fc07 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor.CoreComponents/Microsoft.CodeAnalysis.Remote.Razor.CoreComponents.csproj +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor.CoreComponents/Microsoft.CodeAnalysis.Remote.Razor.CoreComponents.csproj @@ -28,7 +28,6 @@ <_PublishedFiles Include="$(PublishDir)**\Microsoft.CodeAnalysis.Razor.*" /> <_PublishedFiles Include="$(PublishDir)**\Microsoft.CodeAnalysis.Remote.Razor.*" Exclude="@(_ExcludedFiles)"/> <_PublishedFiles Include="$(PublishDir)**\Microsoft.AspNetCore.*" /> - <_PublishedFiles Include="$(PublishDir)**\Microsoft.Extensions.Logging.Abstractions.dll" /> <_PublishedFiles Include="$(PublishDir)**\Microsoft.Extensions.ObjectPool.dll" /> <_PublishedFiles Include="$(PublishDir)**\Microsoft.VisualStudio.LanguageServer.Protocol.*" /> diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DocumentMapping/RemoteDocumentMappingService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DocumentMapping/RemoteDocumentMappingService.cs index 1003ec0ca92..746868a1236 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DocumentMapping/RemoteDocumentMappingService.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DocumentMapping/RemoteDocumentMappingService.cs @@ -14,10 +14,10 @@ namespace Microsoft.CodeAnalysis.Remote.Razor.DocumentMapping; internal sealed class RemoteDocumentMappingService( IFilePathService filePathService, IDocumentContextFactory documentContextFactory, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : AbstractRazorDocumentMappingService( filePathService, documentContextFactory, - loggerFactory.CreateLogger()) + loggerFactory.GetOrCreateLogger()) { } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Logging/RemoteLoggerFactory.Logger.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Logging/RemoteLoggerFactory.Logger.cs index fd418a01aba..72eabb57b56 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Logging/RemoteLoggerFactory.Logger.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Logging/RemoteLoggerFactory.Logger.cs @@ -3,7 +3,7 @@ using System; using System.Diagnostics; -using Microsoft.Extensions.Logging; +using Microsoft.CodeAnalysis.Razor.Logging; namespace Microsoft.CodeAnalysis.Remote.Razor.Logging; @@ -11,11 +11,9 @@ internal partial class RemoteLoggerFactory { private class Logger(string categoryName) : ILogger { - public IDisposable BeginScope(TState state) => Scope.Instance; - public bool IsEnabled(LogLevel logLevel) => true; - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) + public void Log(LogLevel logLevel, TState state, Exception? exception, Func formatter) { if (s_traceSource is null) { diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Logging/RemoteLoggerFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Logging/RemoteLoggerFactory.cs index c4f1b3e2d39..b674aa56442 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Logging/RemoteLoggerFactory.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Logging/RemoteLoggerFactory.cs @@ -4,13 +4,12 @@ using System.Composition; using System.Diagnostics; using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.Extensions.Logging; namespace Microsoft.CodeAnalysis.Remote.Razor.Logging; -[Export(typeof(IRazorLoggerFactory)), Shared] +[Export(typeof(ILoggerFactory)), Shared] [method: ImportingConstructor] -internal partial class RemoteLoggerFactory() : IRazorLoggerFactory +internal partial class RemoteLoggerFactory() : ILoggerFactory { private static TraceSource? s_traceSource; @@ -19,12 +18,12 @@ internal static void Initialize(TraceSource traceSource) s_traceSource ??= traceSource; } - public void AddLoggerProvider(IRazorLoggerProvider provider) + public void AddLoggerProvider(ILoggerProvider provider) { throw new System.NotImplementedException(); } - public ILogger CreateLogger(string categoryName) + public ILogger GetOrCreateLogger(string categoryName) { return new Logger(categoryName); } diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/SemanticTokens/RazorSemanticTokensInfoService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/SemanticTokens/RazorSemanticTokensInfoService.cs index 61e60c540a7..9414fa0ec1f 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/SemanticTokens/RazorSemanticTokensInfoService.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/SemanticTokens/RazorSemanticTokensInfoService.cs @@ -7,7 +7,6 @@ using Microsoft.CodeAnalysis.Razor.SemanticTokens; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Remote.Razor.DocumentMapping; -using Microsoft.Extensions.Logging; namespace Microsoft.CodeAnalysis.Remote.Razor.SemanticTokens; @@ -18,12 +17,12 @@ internal class RazorSemanticTokensInfoService( ISemanticTokensLegendService semanticTokensLegendService, ICSharpSemanticTokensProvider csharpSemanticTokensProvider, LanguageServerFeatureOptions languageServerFeatureOptions, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : AbstractRazorSemanticTokensInfoService( documentMappingService, semanticTokensLegendService, -csharpSemanticTokensProvider, + csharpSemanticTokensProvider, languageServerFeatureOptions, - loggerFactory.CreateLogger()) + loggerFactory.GetOrCreateLogger()) { } diff --git a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Snippets/XmlSnippetParser.cs b/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Snippets/XmlSnippetParser.cs index e5aa193fa13..93f59342f81 100644 --- a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Snippets/XmlSnippetParser.cs +++ b/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Snippets/XmlSnippetParser.cs @@ -3,7 +3,7 @@ using System; using System.IO; -using Microsoft.Extensions.Logging; +using Microsoft.CodeAnalysis.Razor.Logging; namespace Microsoft.VisualStudio.Editor.Razor.Snippets; diff --git a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Telemetry/VSTelemetryReporter.cs b/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Telemetry/VSTelemetryReporter.cs index a79e2f23178..9069ebeb32a 100644 --- a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Telemetry/VSTelemetryReporter.cs +++ b/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/Telemetry/VSTelemetryReporter.cs @@ -5,7 +5,6 @@ using System.Collections.Immutable; using System.ComponentModel.Composition; using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.Telemetry; using StreamJsonRpc; @@ -17,13 +16,13 @@ internal class VSTelemetryReporter : TelemetryReporter private readonly Lazy _logger; [ImportingConstructor] - public VSTelemetryReporter(Lazy loggerFactory) + public VSTelemetryReporter(Lazy loggerFactory) // Get the DefaultSession for telemetry. This is set by VS with // TelemetryService.SetDefaultSession and provides the correct // appinsights keys etc : base(ImmutableArray.Create(TelemetryService.DefaultSession)) { - _logger = new Lazy(() => loggerFactory.Value.CreateLogger()); + _logger = new Lazy(() => loggerFactory.Value.GetOrCreateLogger()); } protected override bool HandleException(Exception exception, string? message, params object?[] @params) diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentAddListener.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentAddListener.cs index b2d2f99522a..dabad8707de 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentAddListener.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentAddListener.cs @@ -6,7 +6,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.Editor.Razor; using Microsoft.VisualStudio.LanguageServer.ContainedLanguage; using Microsoft.VisualStudio.Utilities; @@ -17,11 +16,11 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor; [Export(typeof(LSPDocumentChangeListener))] [ContentType(RazorConstants.RazorLSPContentTypeName)] [method: ImportingConstructor] -internal class CSharpVirtualDocumentAddListener(IRazorLoggerFactory loggerFactory) : LSPDocumentChangeListener +internal class CSharpVirtualDocumentAddListener(ILoggerFactory loggerFactory) : LSPDocumentChangeListener { private static readonly TimeSpan s_waitTimeout = TimeSpan.FromMilliseconds(500); - private readonly ILogger logger = loggerFactory.CreateLogger(); + private readonly ILogger logger = loggerFactory.GetOrCreateLogger(); private TaskCompletionSource? _tcs; private CancellationTokenSource? _cts; diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentFactory.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentFactory.cs index ca91e5bd102..79c2690a9d1 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentFactory.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/CSharpVirtualDocumentFactory.cs @@ -12,7 +12,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.Editor.Razor; using Microsoft.VisualStudio.LanguageServer.Client; using Microsoft.VisualStudio.LanguageServer.ContainedLanguage; @@ -49,7 +48,7 @@ public CSharpVirtualDocumentFactory( IFilePathService filePathService, IProjectSnapshotManager projectManager, LanguageServerFeatureOptions languageServerFeatureOptions, - IRazorLoggerFactory loggerFactory, + ILoggerFactory loggerFactory, ITelemetryReporter telemetryReporter) : base(contentTypeRegistry, textBufferFactory, textDocumentFactory, fileUriProvider) { @@ -57,7 +56,7 @@ public CSharpVirtualDocumentFactory( _filePathService = filePathService; _projectManager = projectManager; _languageServerFeatureOptions = languageServerFeatureOptions; - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); _telemetryReporter = telemetryReporter; } diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Cohost/CohostSemanticTokensRangeEndpoint.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Cohost/CohostSemanticTokensRangeEndpoint.cs index d4f1e0d9af8..e0d45041dd4 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Cohost/CohostSemanticTokensRangeEndpoint.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Cohost/CohostSemanticTokensRangeEndpoint.cs @@ -13,7 +13,6 @@ using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.SemanticTokens; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; using Microsoft.VisualStudio.LanguageServerClient.Razor.Extensions; @@ -28,13 +27,13 @@ internal sealed class CohostSemanticTokensRangeEndpoint( IOutOfProcSemanticTokensService semanticTokensInfoService, ISemanticTokensLegendService semanticTokensLegendService, ITelemetryReporter telemetryReporter, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : AbstractRazorCohostDocumentRequestHandler, ICapabilitiesProvider { private readonly IOutOfProcSemanticTokensService _semanticTokensInfoService = semanticTokensInfoService; private readonly ISemanticTokensLegendService _semanticTokensLegendService = semanticTokensLegendService; private readonly ITelemetryReporter _telemetryReporter = telemetryReporter; - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); protected override bool MutatesSolutionState => false; protected override bool RequiresLSPSolution => true; diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Cohost/CohostTextDocumentSyncHandler.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Cohost/CohostTextDocumentSyncHandler.cs index 6ba70e01f47..00cb875fd51 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Cohost/CohostTextDocumentSyncHandler.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Cohost/CohostTextDocumentSyncHandler.cs @@ -11,7 +11,6 @@ using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Remote; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.ContainedLanguage; using Microsoft.VisualStudio.LanguageServer.Protocol; using Microsoft.VisualStudio.Threading; @@ -24,12 +23,12 @@ internal class CohostTextDocumentSyncHandler( IRemoteClientProvider remoteClientProvider, LSPDocumentManager documentManager, JoinableTaskContext joinableTaskContext, - IRazorLoggerFactory loggerFactory) : IRazorCohostTextDocumentSyncHandler + ILoggerFactory loggerFactory) : IRazorCohostTextDocumentSyncHandler { private readonly IRemoteClientProvider _remoteClientProvider = remoteClientProvider; private readonly JoinableTaskContext _joinableTaskContext = joinableTaskContext; private readonly TrackingLSPDocumentManager _documentManager = documentManager as TrackingLSPDocumentManager ?? throw new InvalidOperationException("Expected TrackingLSPDocumentManager"); - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public async Task HandleAsync(int version, RazorCohostRequestContext context, CancellationToken cancellationToken) { diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Debugging/DefaultLSPBreakpointSpanProvider.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Debugging/DefaultLSPBreakpointSpanProvider.cs index 644d141b21c..703288d44ab 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Debugging/DefaultLSPBreakpointSpanProvider.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Debugging/DefaultLSPBreakpointSpanProvider.cs @@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.ContainedLanguage; using Microsoft.VisualStudio.LanguageServer.Protocol; using Newtonsoft.Json.Linq; @@ -25,7 +24,7 @@ internal class DefaultLSPBreakpointSpanProvider : LSPBreakpointSpanProvider [ImportingConstructor] public DefaultLSPBreakpointSpanProvider( LSPRequestInvoker requestInvoker, - Lazy loggerFactory) + Lazy loggerFactory) { if (requestInvoker is null) { @@ -38,7 +37,7 @@ public DefaultLSPBreakpointSpanProvider( } _requestInvoker = requestInvoker; - _logger = new Lazy(() => loggerFactory.Value.CreateLogger()); + _logger = new Lazy(() => loggerFactory.Value.GetOrCreateLogger()); } public async override Task GetBreakpointSpanAsync(LSPDocumentSnapshot documentSnapshot, Position position, CancellationToken cancellationToken) diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Debugging/DefaultLSPProximityExpressionsProvider.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Debugging/DefaultLSPProximityExpressionsProvider.cs index 0d1d2088bd9..a4c78791aae 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Debugging/DefaultLSPProximityExpressionsProvider.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Debugging/DefaultLSPProximityExpressionsProvider.cs @@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.ContainedLanguage; using Microsoft.VisualStudio.LanguageServer.Protocol; using Newtonsoft.Json.Linq; @@ -27,7 +26,7 @@ internal class DefaultLSPProximityExpressionsProvider : LSPProximityExpressionsP [ImportingConstructor] public DefaultLSPProximityExpressionsProvider( LSPRequestInvoker requestInvoker, - Lazy loggerFactory) + Lazy loggerFactory) { if (requestInvoker is null) { @@ -40,7 +39,7 @@ public DefaultLSPProximityExpressionsProvider( } _requestInvoker = requestInvoker; - _logger = new Lazy(() => loggerFactory.Value.CreateLogger()); + _logger = new Lazy(() => loggerFactory.Value.GetOrCreateLogger()); } public async override Task?> GetProximityExpressionsAsync(LSPDocumentSnapshot documentSnapshot, Position position, CancellationToken cancellationToken) diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Endpoints/Diagnostics.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Endpoints/Diagnostics.cs index b1cb8ab7777..0ebd683253d 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Endpoints/Diagnostics.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Endpoints/Diagnostics.cs @@ -4,10 +4,10 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Protocol.Diagnostics; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.ContainedLanguage; using Microsoft.VisualStudio.LanguageServer.Protocol; using Microsoft.VisualStudio.LanguageServerClient.Razor.Extensions; diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Endpoints/SemanticTokens.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Endpoints/SemanticTokens.cs index 0fc5f8b5b24..55d45b52b1a 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Endpoints/SemanticTokens.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Endpoints/SemanticTokens.cs @@ -6,9 +6,9 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces.Protocol.SemanticTokens; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServer.Protocol; using Newtonsoft.Json.Linq; using StreamJsonRpc; diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Endpoints/UpdateCSharpBuffer.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Endpoints/UpdateCSharpBuffer.cs index b285113eb74..54c6e9fbfdb 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Endpoints/UpdateCSharpBuffer.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Endpoints/UpdateCSharpBuffer.cs @@ -6,9 +6,9 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.LanguageServerClient.Razor.Extensions; using StreamJsonRpc; diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Extensions/RazorCohostRequestContextExtensions.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Extensions/RazorCohostRequestContextExtensions.cs index 98860f63f0b..03dd697637e 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Extensions/RazorCohostRequestContextExtensions.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Extensions/RazorCohostRequestContextExtensions.cs @@ -4,7 +4,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; -using Microsoft.Extensions.Logging; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.VisualStudio.LanguageServerClient.Razor.Cohost; using StreamJsonRpc; diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Logging/RazorLogHubLogger.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Logging/RazorLogHubLogger.cs index cf71b981655..d189760a7c5 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Logging/RazorLogHubLogger.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Logging/RazorLogHubLogger.cs @@ -4,7 +4,7 @@ using System; using System.Diagnostics; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; -using Microsoft.Extensions.Logging; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.VisualStudio.Editor.Razor.Logging; namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Logging; @@ -20,14 +20,12 @@ public RazorLogHubLogger(string categoryName, RazorLogHubTraceProvider traceProv _traceProvider = traceProvider; } - public IDisposable BeginScope(TState state) => Scope.Instance; - public bool IsEnabled(LogLevel logLevel) { return true; } - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) + public void Log(LogLevel logLevel, TState state, Exception? exception, Func formatter) { var traceSource = _traceProvider.TryGetTraceSource(); if (traceSource is null) diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Logging/RazorLogHubLoggerProvider.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Logging/RazorLogHubLoggerProvider.cs index 613fca9ba29..073ea1b19ee 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Logging/RazorLogHubLoggerProvider.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Logging/RazorLogHubLoggerProvider.cs @@ -3,13 +3,12 @@ using System.ComponentModel.Composition; using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.Editor.Razor.Logging; namespace Microsoft.VisualStudio.LanguageServerClient.Razor.Logging; -[Export(typeof(IRazorLoggerProvider))] -internal sealed class RazorLogHubLoggerProvider : IRazorLoggerProvider +[Export(typeof(ILoggerProvider))] +internal sealed class RazorLogHubLoggerProvider : ILoggerProvider { private readonly RazorLogHubTraceProvider _traceProvider; diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Microsoft.VisualStudio.LanguageServerClient.Razor.csproj b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Microsoft.VisualStudio.LanguageServerClient.Razor.csproj index c2f969db354..784476a0c21 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Microsoft.VisualStudio.LanguageServerClient.Razor.csproj +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Microsoft.VisualStudio.LanguageServerClient.Razor.csproj @@ -21,8 +21,6 @@ - - diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Options/OptionsStorage.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Options/OptionsStorage.cs index 213c7bf2e68..4d614dfe702 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Options/OptionsStorage.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/Options/OptionsStorage.cs @@ -6,8 +6,8 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Telemetry; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Settings; -using Microsoft.Extensions.Logging; using Microsoft.Internal.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Editor.Razor.Settings; using Microsoft.VisualStudio.Settings; diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorCustomMessageTarget.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorCustomMessageTarget.cs index aec678919ac..9f14812bf03 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorCustomMessageTarget.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorCustomMessageTarget.cs @@ -13,7 +13,6 @@ using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Protocol; using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.Editor.Razor.Settings; using Microsoft.VisualStudio.Editor.Razor.Snippets; using Microsoft.VisualStudio.LanguageServer.ContainedLanguage; @@ -55,7 +54,7 @@ public RazorCustomMessageTarget( LanguageServerFeatureOptions languageServerFeatureOptions, IProjectSnapshotManager projectManager, SnippetCache snippetCache, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) { if (documentManager is null) { @@ -84,7 +83,7 @@ public RazorCustomMessageTarget( _languageServerFeatureOptions = languageServerFeatureOptions ?? throw new ArgumentNullException(nameof(languageServerFeatureOptions)); _projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager)); _snippetCache = snippetCache ?? throw new ArgumentNullException(nameof(snippetCache)); - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.GetOrCreateLogger(); } private async Task GetProjectedRequestDetailsAsync(IDelegatedParams request, CancellationToken cancellationToken) diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorLanguageServerClient.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorLanguageServerClient.cs index 3949cf3aef6..3391ed3c9e4 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorLanguageServerClient.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/RazorLanguageServerClient.cs @@ -37,7 +37,7 @@ internal class RazorLanguageServerClient( RazorLanguageClientMiddleLayer middleLayer, LSPRequestInvoker requestInvoker, ProjectConfigurationFilePathStore projectConfigurationFilePathStore, - IRazorLoggerFactory razorLoggerFactory, + ILoggerFactory loggerFactory, RazorLogHubTraceProvider traceProvider, LanguageServerFeatureOptions languageServerFeatureOptions, ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher, @@ -61,7 +61,7 @@ internal class RazorLanguageServerClient( private readonly LanguageServerFeatureOptions _languageServerFeatureOptions = languageServerFeatureOptions ?? throw new ArgumentNullException(nameof(languageServerFeatureOptions)); private readonly VisualStudioHostServicesProvider _vsHostWorkspaceServicesProvider = vsHostWorkspaceServicesProvider ?? throw new ArgumentNullException(nameof(vsHostWorkspaceServicesProvider)); private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher ?? throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher)); - private readonly IRazorLoggerFactory _razorLoggerFactory = razorLoggerFactory ?? throw new ArgumentNullException(nameof(razorLoggerFactory)); + private readonly ILoggerFactory _loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); private readonly RazorLogHubTraceProvider _traceProvider = traceProvider ?? throw new ArgumentNullException(nameof(traceProvider)); private RazorLanguageServerWrapper? _server; @@ -108,7 +108,7 @@ public event AsyncEventHandler? StopAsync _server = RazorLanguageServerWrapper.Create( serverStream, serverStream, - _razorLoggerFactory, + _loggerFactory, _telemetryReporter, _projectSnapshotManagerDispatcher, ConfigureLanguageServer, diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/MemoryLoggerProvider.Logger.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/MemoryLoggerProvider.Logger.cs index 5dea7265f67..df626e240f4 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/MemoryLoggerProvider.Logger.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/MemoryLoggerProvider.Logger.cs @@ -2,7 +2,7 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using System; -using Microsoft.Extensions.Logging; +using Microsoft.CodeAnalysis.Razor.Logging; namespace Microsoft.VisualStudio.LanguageServices.Razor.Logging; @@ -13,13 +13,10 @@ private class Logger(Buffer buffer, string categoryName) : ILogger private readonly Buffer _buffer = buffer; private readonly string _categoryName = categoryName; - public IDisposable BeginScope(TState state) - => Scope.Instance; - public bool IsEnabled(LogLevel logLevel) => true; - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) + public void Log(LogLevel logLevel, TState state, Exception? exception, Func formatter) { _buffer.Append($"{DateTime.Now:h:mm:ss.fff} [{_categoryName}] {formatter(state, exception)}"); if (exception is not null) diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/MemoryLoggerProvider.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/MemoryLoggerProvider.cs index 29b149c721b..c5473efa336 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/MemoryLoggerProvider.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/MemoryLoggerProvider.cs @@ -3,13 +3,12 @@ using System.ComponentModel.Composition; using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.Extensions.Logging; namespace Microsoft.VisualStudio.LanguageServices.Razor.Logging; -[Export(typeof(IRazorLoggerProvider))] +[Export(typeof(ILoggerProvider))] [method: ImportingConstructor] -internal partial class MemoryLoggerProvider() : IRazorLoggerProvider +internal partial class MemoryLoggerProvider() : ILoggerProvider { // How many messages will the buffer contain private const int BufferSize = 5000; diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/OutputWindowLoggerProvider.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/OutputWindowLoggerProvider.cs index 71c9bae068f..0b35db20a6c 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/OutputWindowLoggerProvider.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/OutputWindowLoggerProvider.cs @@ -6,7 +6,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.Editor.Razor; using Microsoft.VisualStudio.Editor.Razor.Settings; using Microsoft.VisualStudio.Shell; @@ -15,14 +14,14 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Logging; -[Export(typeof(IRazorLoggerProvider))] +[Export(typeof(ILoggerProvider))] [method: ImportingConstructor] internal class OutputWindowLoggerProvider( // Anything this class imports would have a circular dependency if they tried to log anything, // or used anything that does logging, so make sure everything of ours is imported lazily Lazy clientSettingsManager, JoinableTaskContext joinableTaskContext) - : IRazorLoggerProvider + : ILoggerProvider { private readonly Lazy _clientSettingsManager = clientSettingsManager; private readonly OutputPane _outputPane = new OutputPane(joinableTaskContext); @@ -50,17 +49,12 @@ public OutputPaneLogger(string categoryName, OutputPane outputPane, IClientSetti _clientSettingsManager = clientSettingsManager; } - public IDisposable BeginScope(TState state) - { - return Scope.Instance; - } - public bool IsEnabled(LogLevel logLevel) { return logLevel >= _clientSettingsManager.GetClientSettings().AdvancedSettings.LogLevel; } - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) + public void Log(LogLevel logLevel, TState state, Exception? exception, Func formatter) { if (IsEnabled(logLevel)) { diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/VisualStudioRazorLoggerFactory.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/VisualStudioLoggerFactory.cs similarity index 66% rename from src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/VisualStudioRazorLoggerFactory.cs rename to src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/VisualStudioLoggerFactory.cs index e54bdd35892..1ab3ed7c87a 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/VisualStudioRazorLoggerFactory.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/VisualStudioLoggerFactory.cs @@ -8,9 +8,9 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Logging; -[Export(typeof(IRazorLoggerFactory))] +[Export(typeof(ILoggerFactory))] [method: ImportingConstructor] -internal sealed class VisualStudioRazorLoggerFactory([ImportMany] IEnumerable providers) - : AbstractRazorLoggerFactory(providers.ToImmutableArray()) +internal sealed class VisualStudioLoggerFactory([ImportMany] IEnumerable providers) + : AbstractLoggerFactory(providers.ToImmutableArray()) { } diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Remote/OutOfProcSemanticTokensService.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Remote/OutOfProcSemanticTokensService.cs index a391bed8d5b..c8107a64037 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Remote/OutOfProcSemanticTokensService.cs +++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Remote/OutOfProcSemanticTokensService.cs @@ -9,18 +9,17 @@ using Microsoft.CodeAnalysis.Razor.Remote; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.Editor.Razor.Settings; namespace Microsoft.CodeAnalysis.Remote.Razor; [Export(typeof(IOutOfProcSemanticTokensService))] [method: ImportingConstructor] -internal class OutOfProcSemanticTokensService(IRemoteClientProvider remoteClientProvider, IClientSettingsManager clientSettingsManager, IRazorLoggerFactory loggerFactory) : IOutOfProcSemanticTokensService +internal class OutOfProcSemanticTokensService(IRemoteClientProvider remoteClientProvider, IClientSettingsManager clientSettingsManager, ILoggerFactory loggerFactory) : IOutOfProcSemanticTokensService { private readonly IRemoteClientProvider _remoteClientProvider = remoteClientProvider; private readonly IClientSettingsManager _clientSettingsManager = clientSettingsManager; - private readonly ILogger _logger = loggerFactory.CreateLogger(); + private readonly ILogger _logger = loggerFactory.GetOrCreateLogger(); public async ValueTask GetSemanticTokensDataAsync(TextDocument razorDocument, LinePositionSpan span, Guid correlationId, CancellationToken cancellationToken) { diff --git a/src/Razor/src/Microsoft.VisualStudio.RazorExtension/AssemblyBindingRedirects.cs b/src/Razor/src/Microsoft.VisualStudio.RazorExtension/AssemblyBindingRedirects.cs index 56e2a00ad86..9de502ed62a 100644 --- a/src/Razor/src/Microsoft.VisualStudio.RazorExtension/AssemblyBindingRedirects.cs +++ b/src/Razor/src/Microsoft.VisualStudio.RazorExtension/AssemblyBindingRedirects.cs @@ -3,20 +3,6 @@ using Microsoft.VisualStudio.Shell; -[assembly: ProvideBindingRedirection( - AssemblyName = "Microsoft.Extensions.Logging.Abstractions", - GenerateCodeBase = true, - PublicKeyToken = "adb9793829ddae60", - OldVersionLowerBound = "0.0.0.0", - OldVersionUpperBound = "6.0.0.0", - NewVersion = "6.0.0.0")] -[assembly: ProvideBindingRedirection( - AssemblyName = "Microsoft.Extensions.Logging", - GenerateCodeBase = true, - PublicKeyToken = "adb9793829ddae60", - OldVersionLowerBound = "0.0.0.0", - OldVersionUpperBound = "6.0.0.0", - NewVersion = "6.0.0.0")] [assembly: ProvideBindingRedirection( AssemblyName = "Microsoft.Extensions.DependencyInjection", GenerateCodeBase = true, @@ -38,13 +24,6 @@ OldVersionLowerBound = "0.0.0.0", OldVersionUpperBound = "8.0.0.0", NewVersion = "8.0.0.0")] -[assembly: ProvideBindingRedirection( - AssemblyName = "Microsoft.Extensions.Options", - GenerateCodeBase = true, - PublicKeyToken = "adb9793829ddae60", - OldVersionLowerBound = "0.0.0.0", - OldVersionUpperBound = "6.0.0.0", - NewVersion = "6.0.0.0")] [assembly: ProvideBindingRedirection( AssemblyName = "Microsoft.Extensions.Configuration.Abstractions", GenerateCodeBase = true, diff --git a/src/Razor/src/Microsoft.VisualStudio.RazorExtension/AssemblyCodeBases.cs b/src/Razor/src/Microsoft.VisualStudio.RazorExtension/AssemblyCodeBases.cs index 1fbe118454a..797a3a07ed6 100644 --- a/src/Razor/src/Microsoft.VisualStudio.RazorExtension/AssemblyCodeBases.cs +++ b/src/Razor/src/Microsoft.VisualStudio.RazorExtension/AssemblyCodeBases.cs @@ -4,13 +4,10 @@ using Microsoft.VisualStudio.Shell; [assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\Microsoft.Extensions.ObjectPool.dll")] -[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\Microsoft.Extensions.Options.dll")] [assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\Microsoft.Extensions.Primitives.dll")] [assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\Microsoft.Extensions.DependencyInjection.dll")] [assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\Microsoft.Extensions.DependencyInjection.Abstractions.dll")] [assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\Microsoft.Extensions.Configuration.dll")] [assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\Microsoft.Extensions.Configuration.Abstractions.dll")] -[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\Microsoft.Extensions.Logging.dll")] -[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\Microsoft.Extensions.Logging.Abstractions.dll")] [assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.IO.Pipelines.dll")] [assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.Threading.Channels.dll")] diff --git a/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Microsoft.VisualStudio.RazorExtension.csproj b/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Microsoft.VisualStudio.RazorExtension.csproj index 684f2cd4cda..9745b7bcdc4 100644 --- a/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Microsoft.VisualStudio.RazorExtension.csproj +++ b/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Microsoft.VisualStudio.RazorExtension.csproj @@ -137,14 +137,11 @@ *************************************************************************************************************************************** --> - - - diff --git a/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Options/AdvancedOptionPage.cs b/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Options/AdvancedOptionPage.cs index 552e7539e6d..fdddd567f96 100644 --- a/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Options/AdvancedOptionPage.cs +++ b/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Options/AdvancedOptionPage.cs @@ -3,8 +3,8 @@ using System; using System.Runtime.InteropServices; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Settings; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.ComponentModelHost; using Microsoft.VisualStudio.LanguageServerClient.Razor.Options; using Microsoft.VisualStudio.Shell; diff --git a/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Options/Readme.md b/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Options/Readme.md index 0dbb322f4d8..85b1b0258c1 100644 --- a/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Options/Readme.md +++ b/src/Razor/src/Microsoft.VisualStudio.RazorExtension/Options/Readme.md @@ -9,4 +9,4 @@ These are the steps needed to add a new option: 3. Add a property with `LocCategory`, `LocDescription`, and `LocDisplayName`, with the argument being the `nameof` operator on the resource accessor. 4. Add the property to the `ClientAdvancedSettings` record and update `OptionsStorage.GetAdvancedSettings` to appropriately construct the type. 5. Add the appropriate setting to `RazorLSPOptions` if it needs to be used on the LSP side. This represents the LSP Server understanding of any client side settings that need to be enabled. There is a constructor that takes `ClientSettings` and applies to properties as needed. -6. In whatever place you need the option, import an `IOptionsMonitor` to get the current value as needed. \ No newline at end of file +6. In whatever place you need the option, import an `RazorLSPOptionsMonitor` to get the current value as needed. \ No newline at end of file diff --git a/src/Razor/src/Microsoft.VisualStudio.RazorExtension/source.extension.vsixmanifest b/src/Razor/src/Microsoft.VisualStudio.RazorExtension/source.extension.vsixmanifest index a91565b64d7..b73de451278 100644 --- a/src/Razor/src/Microsoft.VisualStudio.RazorExtension/source.extension.vsixmanifest +++ b/src/Razor/src/Microsoft.VisualStudio.RazorExtension/source.extension.vsixmanifest @@ -33,14 +33,11 @@ - - - diff --git a/src/Razor/src/rzls/LoggerFactory.cs b/src/Razor/src/rzls/LoggerFactory.cs index 0f2b028d731..d4c5d8425ff 100644 --- a/src/Razor/src/rzls/LoggerFactory.cs +++ b/src/Razor/src/rzls/LoggerFactory.cs @@ -6,7 +6,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer; -internal sealed class LoggerFactory(ImmutableArray providers) - : AbstractRazorLoggerFactory(providers) +internal sealed class LoggerFactory(ImmutableArray providers) + : AbstractLoggerFactory(providers) { } diff --git a/src/Razor/src/rzls/LoggerProvider.cs b/src/Razor/src/rzls/LoggerProvider.cs index c945bb8b571..768c713a454 100644 --- a/src/Razor/src/rzls/LoggerProvider.cs +++ b/src/Razor/src/rzls/LoggerProvider.cs @@ -3,11 +3,10 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer; -internal class LoggerProvider(LogLevel logLevel, IClientConnection clientConnection) : IRazorLoggerProvider +internal class LoggerProvider(LogLevel logLevel, IClientConnection clientConnection) : ILoggerProvider { private readonly LogLevel _logLevel = logLevel; private readonly IClientConnection _clientConnection = clientConnection; diff --git a/src/Razor/src/rzls/Program.cs b/src/Razor/src/rzls/Program.cs index a5299e284ab..478b32cd24b 100644 --- a/src/Razor/src/rzls/Program.cs +++ b/src/Razor/src/rzls/Program.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Telemetry; -using Microsoft.Extensions.Logging; +using Microsoft.CodeAnalysis.Razor.Logging; namespace Microsoft.AspNetCore.Razor.LanguageServer; @@ -92,7 +92,7 @@ public static async Task Main(string[] args) var loggerProvider = new LoggerProvider(logLevel, clientConnection); loggerFactory.AddLoggerProvider(loggerProvider); - loggerFactory.CreateLogger("RZLS").LogInformation("Razor Language Server started successfully."); + loggerFactory.GetOrCreateLogger("RZLS").LogInformation("Razor Language Server started successfully."); await server.WaitForExitAsync().ConfigureAwait(true); } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/AutoClosingTagOnAutoInsertProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/AutoClosingTagOnAutoInsertProviderTest.cs index e4c2d51b252..62dfbe5e0c6 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/AutoClosingTagOnAutoInsertProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/AutoClosingTagOnAutoInsertProviderTest.cs @@ -5,7 +5,6 @@ using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Test.Common; -using Microsoft.Extensions.Options; using Moq; using Xunit; using Xunit.Abstractions; @@ -950,10 +949,10 @@ public void OnTypeCloseAngle_AutoInsertDisabled_Noops() internal override IOnAutoInsertProvider CreateProvider() { - var optionsMonitor = new Mock>(MockBehavior.Strict); - optionsMonitor.SetupGet(o => o.CurrentValue).Returns(Options); + var configService = StrictMock.Of(); + var optionsMonitor = new RazorLSPOptionsMonitor(configService, Options); - var provider = new AutoClosingTagOnAutoInsertProvider(optionsMonitor.Object, LoggerFactory); + var provider = new AutoClosingTagOnAutoInsertProvider(optionsMonitor, LoggerFactory); return provider; } } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/CloseTextTagOnAutoInsertProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/CloseTextTagOnAutoInsertProviderTest.cs index 6d0c0c9e8ca..53d858846da 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/CloseTextTagOnAutoInsertProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/AutoInsert/CloseTextTagOnAutoInsertProviderTest.cs @@ -2,7 +2,7 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; -using Microsoft.Extensions.Options; +using Microsoft.AspNetCore.Razor.Test.Common; using Moq; using Xunit; using Xunit.Abstractions; @@ -41,10 +41,10 @@ public void OnTypeCloseAngle_OutsideRazorBlock_DoesNotCloseTextTag() internal override IOnAutoInsertProvider CreateProvider() { - var optionsMonitor = new Mock>(MockBehavior.Strict); - optionsMonitor.SetupGet(o => o.CurrentValue).Returns(RazorLSPOptions.Default); - var provider = new CloseTextTagOnAutoInsertProvider(optionsMonitor.Object, LoggerFactory); + var configService = StrictMock.Of(); + var optionsMonitor = new RazorLSPOptionsMonitor(configService, RazorLSPOptions.Default); + var provider = new CloseTextTagOnAutoInsertProvider(optionsMonitor, LoggerFactory); return provider; } } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/CompletionListProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/CompletionListProviderTest.cs index 18e169b3dfe..e3f63cfb270 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/CompletionListProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/CompletionListProviderTest.cs @@ -105,7 +105,7 @@ private class TestRazorCompletionListProvider : RazorCompletionListProvider public TestRazorCompletionListProvider( VSInternalCompletionList completionList, IEnumerable triggerCharacters, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : base(completionFactsService: null, completionListCache: null, loggerFactory) { _completionList = completionList; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/TestDelegatedCompletionListProvider.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/TestDelegatedCompletionListProvider.cs index ce8662bc153..bb8dee4338e 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/TestDelegatedCompletionListProvider.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/Delegation/TestDelegatedCompletionListProvider.cs @@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Razor.Test.Common.Workspaces; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Protocol; -using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.VisualStudio.LanguageServer.Protocol; namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion.Delegation; @@ -24,7 +23,7 @@ internal class TestDelegatedCompletionListProvider : DelegatedCompletionListProv private TestDelegatedCompletionListProvider( DelegatedCompletionResponseRewriter[] responseRewriters, CompletionRequestResponseFactory completionFactory, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : base( responseRewriters, new RazorDocumentMappingService(new LSPFilePathService(TestLanguageServerFeatureOptions.Instance), new TestDocumentContextFactory(), loggerFactory), @@ -38,13 +37,13 @@ private TestDelegatedCompletionListProvider( } public static TestDelegatedCompletionListProvider Create( - IRazorLoggerFactory loggerFactory, + ILoggerFactory loggerFactory, params DelegatedCompletionResponseRewriter[] responseRewriters) => Create(delegatedCompletionList: null, loggerFactory, responseRewriters: responseRewriters); public static TestDelegatedCompletionListProvider Create( CSharpTestLspServer csharpServer, - IRazorLoggerFactory loggerFactory, + ILoggerFactory loggerFactory, CancellationToken cancellationToken, params DelegatedCompletionResponseRewriter[] responseRewriters) { @@ -55,7 +54,7 @@ public static TestDelegatedCompletionListProvider Create( public static TestDelegatedCompletionListProvider Create( VSInternalCompletionList delegatedCompletionList, - IRazorLoggerFactory loggerFactory, + ILoggerFactory loggerFactory, params DelegatedCompletionResponseRewriter[] responseRewriters) { delegatedCompletionList ??= new VSInternalCompletionList() @@ -68,7 +67,7 @@ public static TestDelegatedCompletionListProvider Create( } public static TestDelegatedCompletionListProvider CreateWithNullResponse( - IRazorLoggerFactory loggerFactory, + ILoggerFactory loggerFactory, params DelegatedCompletionResponseRewriter[] responseRewriters) { var requestResponseFactory = new StaticCompletionRequestResponseFactory(null); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/RazorCompletionListProviderTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/RazorCompletionListProviderTest.cs index d5b73c67538..e21f59116c0 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/RazorCompletionListProviderTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/RazorCompletionListProviderTest.cs @@ -9,13 +9,11 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Components; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; using Microsoft.CodeAnalysis.Razor.Completion; using Microsoft.CodeAnalysis.Razor.Tooltip; using Microsoft.CodeAnalysis.Testing; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; using Newtonsoft.Json; using Xunit; @@ -58,7 +56,7 @@ public RazorCompletionListProviderTest(ITestOutputHelper testOutput) _defaultCompletionContext = new VSInternalCompletionContext(); } - private static IEnumerable GetCompletionProviders(IOptionsMonitor optionsMonitor = null) + private static IEnumerable GetCompletionProviders(RazorLSPOptionsMonitor optionsMonitor = null) { // Working around strong naming restriction. var tagHelperCompletionService = new LspTagHelperCompletionService(); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Definition/DefinitionEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Definition/DefinitionEndpointTest.cs index fcd4b1e2acb..400b8cc671c 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Definition/DefinitionEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Definition/DefinitionEndpointTest.cs @@ -365,7 +365,7 @@ private async Task VerifyOriginTagHelperBindingAsync(string content, string tagH var documentContext = CreateDocumentContext(new Uri(@"C:\file.razor"), documentSnapshot); var (descriptor, attributeDescriptor) = await DefinitionEndpoint.GetOriginTagHelperBindingAsync( - documentContext, position, ignoreAttributes, LoggerFactory.CreateLogger("RazorDefinitionEndpoint"), DisposalToken); + documentContext, position, ignoreAttributes, LoggerFactory.GetOrCreateLogger("RazorDefinitionEndpoint"), DisposalToken); if (tagHelperDescriptorName is null) { diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorDiagnosticsPublisherTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorDiagnosticsPublisherTest.cs index bb11c704bd2..bc42e3d2239 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorDiagnosticsPublisherTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorDiagnosticsPublisherTest.cs @@ -546,7 +546,7 @@ public TestRazorDiagnosticsPublisher( LanguageServerFeatureOptions options, RazorTranslateDiagnosticsService razorTranslateDiagnosticsService, IDocumentContextFactory documentContextFactory, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : base(dispatcher, clientConnection, options, new Lazy(() => razorTranslateDiagnosticsService), new Lazy(() => documentContextFactory), diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorTranslateDiagnosticsEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorTranslateDiagnosticsEndpointTest.cs index ba7443c3507..abafd310f66 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorTranslateDiagnosticsEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Diagnostics/RazorTranslateDiagnosticsEndpointTest.cs @@ -1226,7 +1226,7 @@ class TestRazorDiagnosticsServiceWithRazorDiagnostic : RazorTranslateDiagnostics { public TestRazorDiagnosticsServiceWithRazorDiagnostic( IRazorDocumentMappingService documentMappingService, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : base(documentMappingService, loggerFactory) { } @@ -1241,7 +1241,7 @@ class TestRazorDiagnosticsServiceWithoutRazorDiagnostic : RazorTranslateDiagnost { public TestRazorDiagnosticsServiceWithoutRazorDiagnostic( IRazorDocumentMappingService documentMappingService, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : base(documentMappingService, loggerFactory) { } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/TestRazorFormattingService.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/TestRazorFormattingService.cs index 7f26ad497f5..648e368f8a8 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/TestRazorFormattingService.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting/TestRazorFormattingService.cs @@ -17,7 +17,7 @@ internal static class TestRazorFormattingService #pragma warning disable IDE0060 // Remove unused parameter public static Task CreateWithFullSupportAsync( - IRazorLoggerFactory loggerFactory, + ILoggerFactory loggerFactory, RazorCodeDocument? codeDocument = null, IDocumentSnapshot? documentSnapshot = null, RazorLSPOptions? razorLSPOptions = null) diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingLanguageServerClient.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingLanguageServerClient.cs index 0a011fed00f..feec41038d3 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingLanguageServerClient.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingLanguageServerClient.cs @@ -27,10 +27,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; -internal class FormattingLanguageServerClient(IRazorLoggerFactory loggerFactory) : IClientConnection +internal class FormattingLanguageServerClient(ILoggerFactory loggerFactory) : IClientConnection { private readonly Dictionary _documents = []; - private readonly IRazorLoggerFactory _loggerFactory = loggerFactory; + private readonly ILoggerFactory _loggerFactory = loggerFactory; public InitializeResult ServerSettings => throw new NotImplementedException(); 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 d7a873f6d12..87a6a39e3e1 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 @@ -13,8 +13,6 @@ using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; -using Microsoft.CodeAnalysis.Razor.Workspaces; -using Microsoft.Extensions.Options; using Moq; namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; @@ -22,7 +20,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting; internal static class TestRazorFormattingService { public static async Task CreateWithFullSupportAsync( - IRazorLoggerFactory loggerFactory, + ILoggerFactory loggerFactory, ProjectSnapshotManagerDispatcher dispatcher, RazorCodeDocument? codeDocument = null, IDocumentSnapshot? documentSnapshot = null, @@ -51,11 +49,8 @@ await dispatcher.RunAsync(() => .Setup(c => c.GetLatestOptionsAsync(It.IsAny())) .Returns(Task.FromResult(razorLSPOptions)); - var optionsMonitorCache = new OptionsCache(); - var optionsMonitor = TestRazorLSPOptionsMonitor.Create( - configurationSyncService.Object, - optionsMonitorCache); + configurationSyncService.Object); if (razorLSPOptions is not null) { diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverServiceTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverServiceTest.cs index 380b09a63ae..13def471594 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverServiceTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Hover/HoverServiceTest.cs @@ -4,7 +4,6 @@ #nullable disable using System; -using System.Collections.Immutable; using System.Linq; using System.Threading; using System.Threading.Tasks; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/MonitorProjectConfigurationFilePathEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/MonitorProjectConfigurationFilePathEndpointTest.cs index 5875ed79cb7..cef7985d118 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/MonitorProjectConfigurationFilePathEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/MonitorProjectConfigurationFilePathEndpointTest.cs @@ -486,7 +486,7 @@ private class TestMonitorProjectConfigurationFilePathEndpoint( ProjectSnapshotManagerDispatcher dispatcher, WorkspaceDirectoryPathResolver workspaceDirectoryPathResolver, IEnumerable listeners, - IRazorLoggerFactory loggerFactory, + ILoggerFactory loggerFactory, IProjectSnapshotManager projectManager, LanguageServerFeatureOptions? options = null) : MonitorProjectConfigurationFilePathEndpoint( projectManager, diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationFileChangeDetectorTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationFileChangeDetectorTest.cs index 694026852e7..f5a51853e70 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationFileChangeDetectorTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectConfigurationFileChangeDetectorTest.cs @@ -83,7 +83,7 @@ public TestProjectConfigurationFileChangeDetector( ProjectSnapshotManagerDispatcher dispatcher, IEnumerable listeners, IReadOnlyList existingConfigurationFiles, - IRazorLoggerFactory loggerFactory) + ILoggerFactory loggerFactory) : base(dispatcher, listeners, TestLanguageServerFeatureOptions.Instance, loggerFactory) { _cancellationTokenSource = cancellationTokenSource; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorConfigurationEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorConfigurationEndpointTest.cs index 272111a62fb..c044d347085 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorConfigurationEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorConfigurationEndpointTest.cs @@ -5,8 +5,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; using Moq; using Xunit; @@ -16,15 +14,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer; public class RazorConfigurationEndpointTest : LanguageServerTestBase { - private readonly IOptionsMonitorCache _cache; private readonly IConfigurationSyncService _configurationService; public RazorConfigurationEndpointTest(ITestOutputHelper testOutput) : base(testOutput) { - var services = new ServiceCollection().AddOptions(); - _cache = services.BuildServiceProvider().GetRequiredService>(); - var configServiceMock = new Mock(MockBehavior.Strict); configServiceMock .Setup(c => c.GetLatestOptionsAsync(It.IsAny())) @@ -37,7 +31,7 @@ public RazorConfigurationEndpointTest(ITestOutputHelper testOutput) public async Task Handle_UpdatesOptions() { // Arrange - var optionsMonitor = TestRazorLSPOptionsMonitor.Create(_configurationService, _cache); + var optionsMonitor = TestRazorLSPOptionsMonitor.Create(_configurationService); var endpoint = new RazorConfigurationEndpoint(optionsMonitor, LoggerFactory); var request = new DidChangeConfigurationParams(); var requestContext = CreateRazorRequestContext(documentContext: null); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLSPOptionsMonitorTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLSPOptionsMonitorTest.cs index a20f6a0556c..923c290ca46 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLSPOptionsMonitorTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorLSPOptionsMonitorTest.cs @@ -6,8 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.AspNetCore.Razor.Test.Common; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; using Moq; using Xunit; using Xunit.Abstractions; @@ -16,13 +14,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer; public class RazorLSPOptionsMonitorTest : ToolingTestBase { - private readonly IOptionsMonitorCache _cache; - public RazorLSPOptionsMonitorTest(ITestOutputHelper testOutput) : base(testOutput) { - var services = new ServiceCollection().AddOptions(); - _cache = services.BuildServiceProvider().GetRequiredService>(); } [Fact] @@ -33,7 +27,7 @@ public async Task UpdateAsync_Invokes_OnChangeRegistration() var configService = Mock.Of( f => f.GetLatestOptionsAsync(DisposalToken) == Task.FromResult(expectedOptions), MockBehavior.Strict); - var optionsMonitor = new RazorLSPOptionsMonitor(configService, _cache, RazorLSPOptions.Default); + var optionsMonitor = new RazorLSPOptionsMonitor(configService, RazorLSPOptions.Default); var called = false; // Act & Assert @@ -55,7 +49,7 @@ public async Task UpdateAsync_DoesNotInvoke_OnChangeRegistration_AfterDispose() var configService = Mock.Of( f => f.GetLatestOptionsAsync(DisposalToken) == Task.FromResult(expectedOptions), MockBehavior.Strict); - var optionsMonitor = new RazorLSPOptionsMonitor(configService, _cache, RazorLSPOptions.Default); + var optionsMonitor = new RazorLSPOptionsMonitor(configService, RazorLSPOptions.Default); var called = false; var onChangeToken = optionsMonitor.OnChange(options => called = true); @@ -82,7 +76,7 @@ public async Task UpdateAsync_ConfigReturnsNull_DoesNotInvoke_OnChangeRegistrati Mock.Get(configService) .Setup(s => s.GetLatestOptionsAsync(DisposalToken)) .ReturnsAsync(value: null); - var optionsMonitor = new RazorLSPOptionsMonitor(configService, _cache, RazorLSPOptions.Default); + var optionsMonitor = new RazorLSPOptionsMonitor(configService, RazorLSPOptions.Default); var called = false; var onChangeToken = optionsMonitor.OnChange(options => called = true); @@ -101,7 +95,7 @@ public void InitializedOptionsAreCurrent() var configService = Mock.Of( f => f.GetLatestOptionsAsync(DisposalToken) == Task.FromResult(expectedOptions), MockBehavior.Strict); - var optionsMonitor = new RazorLSPOptionsMonitor(configService, _cache, expectedOptions); + var optionsMonitor = new RazorLSPOptionsMonitor(configService, expectedOptions); // Act & Assert Assert.Same(expectedOptions, optionsMonitor.CurrentValue); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/RazorSemanticTokensRefreshEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/RazorSemanticTokensRefreshEndpointTest.cs index 8b915342066..5211453c5da 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/RazorSemanticTokensRefreshEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/RazorSemanticTokensRefreshEndpointTest.cs @@ -13,7 +13,6 @@ using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces.Protocol.SemanticTokens; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; using Moq; using Xunit; @@ -62,11 +61,8 @@ private static RazorLSPOptionsMonitor GetOptionsMonitor() .Setup(c => c.GetLatestOptionsAsync(It.IsAny())) .Returns(Task.FromResult(options)); - var optionsMonitorCache = new OptionsCache(); - var optionsMonitor = TestRazorLSPOptionsMonitor.Create( - configurationSyncService.Object, - optionsMonitorCache); + configurationSyncService.Object); return optionsMonitor; } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/SemanticTokensTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/SemanticTokensTest.cs index 2027d8e6061..bef1fa86c72 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/SemanticTokensTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/SemanticTokensTest.cs @@ -27,7 +27,6 @@ using Microsoft.CodeAnalysis.Razor.Workspaces.Protocol.SemanticTokens; using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; using Moq; using Xunit; @@ -992,11 +991,8 @@ private async Task CreateServiceAsync( .Setup(c => c.GetLatestOptionsAsync(It.IsAny())) .Returns(Task.FromResult(options)); - var optionsMonitorCache = new OptionsCache(); - var optionsMonitor = TestRazorLSPOptionsMonitor.Create( - configurationSyncService.Object, - optionsMonitorCache); + configurationSyncService.Object); await optionsMonitor.UpdateAsync(CancellationToken.None); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/SignatureHelp/SignatureHelpEndpointTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/SignatureHelp/SignatureHelpEndpointTest.cs index 90dd4b68932..a04ee0e851e 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/SignatureHelp/SignatureHelpEndpointTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/SignatureHelp/SignatureHelpEndpointTest.cs @@ -6,12 +6,10 @@ using System; using System.Collections.Immutable; using System.Threading.Tasks; -using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis.Razor.ProjectSystem; using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; using Xunit; using Xunit.Abstractions; @@ -93,7 +91,7 @@ private Task VerifySignatureHelpAsync(string input, params string[] signatures) return VerifySignatureHelpWithContextAndOptionsAsync(input, optionsMonitor: null, signatureHelpContext: null, signatures); } - private async Task VerifySignatureHelpWithContextAndOptionsAsync(string input, IOptionsMonitor optionsMonitor = null, SignatureHelpContext signatureHelpContext = null, params string[] signatures) + private async Task VerifySignatureHelpWithContextAndOptionsAsync(string input, RazorLSPOptionsMonitor optionsMonitor = null, SignatureHelpContext signatureHelpContext = null, params string[] signatures) { // Arrange TestFileMarkupParser.GetPositionAndSpans(input, out var output, out int cursorPosition, out ImmutableArray _); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestRazorLSPOptionsMonitor.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestRazorLSPOptionsMonitor.cs index 1ca6453676f..497c71c42b9 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestRazorLSPOptionsMonitor.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestRazorLSPOptionsMonitor.cs @@ -5,21 +5,18 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Razor.LanguageServer; internal class TestRazorLSPOptionsMonitor : RazorLSPOptionsMonitor { - private readonly IConfigurationSyncService _configuruationSyncService; + private readonly IConfigurationSyncService _configurationSyncService; private TestRazorLSPOptionsMonitor( - IConfigurationSyncService configurationService, - IOptionsMonitorCache cache) - : base(configurationService, cache, RazorLSPOptions.Default) + IConfigurationSyncService configurationService) + : base(configurationService, RazorLSPOptions.Default) { - _configuruationSyncService = configurationService; + _configurationSyncService = configurationService; } public bool Called { get; private set; } @@ -32,7 +29,7 @@ public override Task UpdateAsync(CancellationToken cancellationToken) public Task UpdateAsync(RazorLSPOptions options, CancellationToken cancellationToken) { - if (_configuruationSyncService is not ConfigurationSyncService configurationSyncService) + if (_configurationSyncService is not ConfigurationSyncService configurationSyncService) { throw new InvalidOperationException(); } @@ -42,13 +39,11 @@ public Task UpdateAsync(RazorLSPOptions options, CancellationToken cancellationT } public static TestRazorLSPOptionsMonitor Create( - IConfigurationSyncService? configurationService = null, - IOptionsMonitorCache? cache = null) + IConfigurationSyncService? configurationService = null) { configurationService ??= new ConfigurationSyncService(); - cache ??= new ServiceCollection().AddOptions().BuildServiceProvider().GetRequiredService>(); - return new(configurationService, cache); + return new(configurationService); } private class ConfigurationSyncService : IConfigurationSyncService diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/WorkspaceSemanticTokensRefreshNotifierTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/WorkspaceSemanticTokensRefreshNotifierTest.cs index fb3151c2f5e..3cf9d0fbc02 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/WorkspaceSemanticTokensRefreshNotifierTest.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/WorkspaceSemanticTokensRefreshNotifierTest.cs @@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Test; using Microsoft.AspNetCore.Razor.Test.Common; using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; using Moq; using Xunit; @@ -106,11 +105,8 @@ private static TestRazorLSPOptionsMonitor GetOptionsMonitor(bool withCSharpBackg .Setup(c => c.GetLatestOptionsAsync(It.IsAny())) .Returns(Task.FromResult(options)); - var optionsMonitorCache = new OptionsCache(); - var optionsMonitor = TestRazorLSPOptionsMonitor.Create( - configurationSyncService.Object, - optionsMonitorCache); + configurationSyncService.Object); return optionsMonitor; } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Editor_NetFx/TestTelemetryReporter.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Editor_NetFx/TestTelemetryReporter.cs index de1971698b7..9abccfc5549 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Editor_NetFx/TestTelemetryReporter.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Editor_NetFx/TestTelemetryReporter.cs @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.Editor.Razor.Test.Shared; -internal class TestTelemetryReporter(IRazorLoggerFactory loggerFactory) : VSTelemetryReporter(new Lazy(() => loggerFactory)) +internal class TestTelemetryReporter(ILoggerFactory loggerFactory) : VSTelemetryReporter(new Lazy(() => loggerFactory)) { public List Events { get; } = []; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/LanguageServer/LanguageServerTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/LanguageServer/LanguageServerTestBase.cs index 1fea3218b7d..15ac2df8687 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/LanguageServer/LanguageServerTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/LanguageServer/LanguageServerTestBase.cs @@ -21,11 +21,11 @@ using Microsoft.CodeAnalysis.Razor.Workspaces; using Microsoft.CodeAnalysis.Text; using Microsoft.CommonLanguageServerProtocol.Framework; -using Microsoft.Extensions.Options; using Microsoft.VisualStudio.LanguageServer.Protocol; using Moq; using Newtonsoft.Json; using Xunit.Abstractions; +using static Nerdbank.Streams.MultiplexingStream; namespace Microsoft.AspNetCore.Razor.Test.Common.LanguageServer; @@ -130,11 +130,13 @@ internal static VersionedDocumentContext CreateDocumentContext(Uri uri, IDocumen return new VersionedDocumentContext(uri, snapshot, projectContext: null, version: 0); } - internal static IOptionsMonitor GetOptionsMonitor(bool enableFormatting = true, bool autoShowCompletion = true, bool autoListParams = true, bool formatOnType = true, bool autoInsertAttributeQuotes = true, bool colorBackground = false, bool codeBlockBraceOnNextLine = false, bool commitElementsWithSpace = true) + internal static RazorLSPOptionsMonitor GetOptionsMonitor(bool enableFormatting = true, bool autoShowCompletion = true, bool autoListParams = true, bool formatOnType = true, bool autoInsertAttributeQuotes = true, bool colorBackground = false, bool codeBlockBraceOnNextLine = false, bool commitElementsWithSpace = true) { - var monitor = new Mock>(MockBehavior.Strict); - monitor.SetupGet(m => m.CurrentValue).Returns(new RazorLSPOptions(enableFormatting, true, InsertSpaces: true, TabSize: 4, autoShowCompletion, autoListParams, formatOnType, autoInsertAttributeQuotes, colorBackground, codeBlockBraceOnNextLine, commitElementsWithSpace)); - return monitor.Object; + var configService = StrictMock.Of(); + + var options = new RazorLSPOptions(enableFormatting, true, InsertSpaces: true, TabSize: 4, autoShowCompletion, autoListParams, formatOnType, autoInsertAttributeQuotes, colorBackground, codeBlockBraceOnNextLine, commitElementsWithSpace); + var optionsMonitor = new RazorLSPOptionsMonitor(configService, options); + return optionsMonitor; } private class ThrowingRazorSpanMappingService : IRazorSpanMappingService diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Logging/TestOutputLogger.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Logging/TestOutputLogger.cs index 203c1f8798b..18cfb6a7103 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Logging/TestOutputLogger.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Logging/TestOutputLogger.cs @@ -4,11 +4,11 @@ using System; using System.Collections.Generic; using System.Text; -using Microsoft.Extensions.Logging; +using Microsoft.CodeAnalysis.Razor.Logging; namespace Microsoft.AspNetCore.Razor.Test.Common.Logging; -public partial class TestOutputLogger : ILogger +internal partial class TestOutputLogger : ILogger { [ThreadStatic] private static StringBuilder? g_builder; @@ -28,13 +28,10 @@ public TestOutputLogger( LogLevel = logLevel; } - public IDisposable BeginScope(TState state) - => NoOpDisposable.Instance; - public bool IsEnabled(LogLevel logLevel) => logLevel >= LogLevel; - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) + public void Log(LogLevel logLevel, TState state, Exception? exception, Func formatter) { if (!IsEnabled(logLevel) || _provider.TestOutputHelper is null) { diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Logging/TestOutputLoggerFactory.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Logging/TestOutputLoggerFactory.cs index 3a6128ee160..b9af1ce005d 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Logging/TestOutputLoggerFactory.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Logging/TestOutputLoggerFactory.cs @@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Razor.Test.Common.Logging; internal sealed class TestOutputLoggerFactory(ITestOutputHelper output) - : AbstractRazorLoggerFactory([new TestOutputLoggerProvider(output)]) + : AbstractLoggerFactory([new TestOutputLoggerProvider(output)]) { } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Logging/TestOutputLoggerProvider.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Logging/TestOutputLoggerProvider.cs index 021a4b4b70c..dbaf065d7fb 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Logging/TestOutputLoggerProvider.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Logging/TestOutputLoggerProvider.cs @@ -2,12 +2,11 @@ // Licensed under the MIT license. See License.txt in the project root for license information. using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.Extensions.Logging; using Xunit.Abstractions; namespace Microsoft.AspNetCore.Razor.Test.Common.Logging; -public class TestOutputLoggerProvider(ITestOutputHelper output) : IRazorLoggerProvider +internal class TestOutputLoggerProvider(ITestOutputHelper output) : ILoggerProvider { private ITestOutputHelper? _output = output; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Microsoft.AspNetCore.Razor.Test.Common.Tooling.csproj b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Microsoft.AspNetCore.Razor.Test.Common.Tooling.csproj index 6794aba3522..e5cf60a2a4a 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Microsoft.AspNetCore.Razor.Test.Common.Tooling.csproj +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Microsoft.AspNetCore.Razor.Test.Common.Tooling.csproj @@ -44,7 +44,6 @@ - diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ToolingTestBase.TestErrorReporter.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ToolingTestBase.TestErrorReporter.cs index e17c4ff0173..b35f9fe9c89 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ToolingTestBase.TestErrorReporter.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ToolingTestBase.TestErrorReporter.cs @@ -4,8 +4,8 @@ using System; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.ProjectSystem; -using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Razor.Test.Common; diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ToolingTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ToolingTestBase.cs index 8781138a669..62aad490481 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ToolingTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/ToolingTestBase.cs @@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Razor.Test.Common.Logging; using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.Logging; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.Threading; using Xunit; using Xunit.Abstractions; @@ -24,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.Test.Common; /// test thread as the main thread. /// A that signals when the test has finished running /// and xUnit disposes the test class. -/// An implementation that writes to an xUnit +/// An implementation that writes to an xUnit /// . /// An easy way to register objects that should be disposed /// when the test completes. @@ -69,17 +68,17 @@ static ToolingTestBase() protected CancellationToken DisposalToken { get; } /// - /// An that creates instances that + /// An that creates instances that /// write to xUnit's for the currently running test. /// - internal IRazorLoggerFactory LoggerFactory { get; } + internal ILoggerFactory LoggerFactory { get; } private ILogger? _logger; /// /// An for the currently running test. /// - private protected ILogger Logger => _logger ??= LoggerFactory.CreateLogger(GetType().Name); + private protected ILogger Logger => _logger ??= LoggerFactory.GetOrCreateLogger(GetType().Name); private protected IErrorReporter ErrorReporter => _errorReporter ??= new TestErrorReporter(Logger); @@ -145,7 +144,6 @@ async Task IAsyncLifetime.DisposeAsync() _disposalTokenSource.Dispose(); } - LoggerFactory.Dispose(); JoinableTaskContext.Dispose(); } diff --git a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/AbstractRazorEditorTest.cs b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/AbstractRazorEditorTest.cs index c14ee5058b4..0371fbbf563 100644 --- a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/AbstractRazorEditorTest.cs +++ b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/AbstractRazorEditorTest.cs @@ -9,7 +9,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.Extensions.Logging; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.Internal.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Settings; using Microsoft.VisualStudio.Shell; diff --git a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/OutputInProcess.cs b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/OutputInProcess.cs index 3c14398afd3..5d4e6a5a477 100644 --- a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/OutputInProcess.cs +++ b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/OutputInProcess.cs @@ -4,8 +4,7 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.VisualStudio.Razor.IntegrationTests.Extensions; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; @@ -109,4 +108,18 @@ static IVsTextView OutputWindowPaneToIVsTextView(EnvDTE.OutputWindowPane outputW return textView; } } + + private class NullLogger : ILogger + { + public static ILogger Instance { get; } = new NullLogger(); + + public bool IsEnabled(LogLevel logLevel) + { + return false; + } + + public void Log(LogLevel logLevel, TState state, Exception? exception, Func formatter) + { + } + } } diff --git a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/LogIntegrationTestAttribute.cs b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/LogIntegrationTestAttribute.cs index b5beddf9fe8..80df1dc4c4a 100644 --- a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/LogIntegrationTestAttribute.cs +++ b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/LogIntegrationTestAttribute.cs @@ -23,7 +23,7 @@ public override void After(MethodInfo methodUnderTest) // private static ILogger GetLogger(string testName) // { // var componentModel = ServiceProvider.GlobalProvider.GetService(); - // var loggerFactory = componentModel.GetService(); + // var loggerFactory = componentModel.GetService(); // return loggerFactory.CreateLogger(testName); // } }