diff --git a/Directory.Packages.props b/Directory.Packages.props index 8bfc1b8a0f..19c6deb856 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -5,7 +5,7 @@ here should be _ prefixed to indicate that they are not meant to be used outside this file. --> - <_MicrosoftWebToolsPackageVersion>17.9.67-preview-0001 + <_MicrosoftWebToolsPackageVersion>17.11.11-preview-0001 <_MicrosoftVisualStudioShellPackagesVersion>17.11.39721 <_MicrosoftVisualStudioPackagesVersion>17.11.191 <_VisualStudioLanguageServerProtocolVersion>17.12.1-preview 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 5c77e198d4..66dc964784 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 @@ -102,12 +102,12 @@ internal class FormattingLanguageServerClient(ILoggerFactory loggerFactory) : IC if (!contentTypeService.ContentTypes.Any(t => t.TypeName == HtmlContentTypeDefinition.HtmlContentType)) { - contentTypeService.AddContentType(HtmlContentTypeDefinition.HtmlContentType, new[] { StandardContentTypeNames.Text }); + contentTypeService.AddContentType(HtmlContentTypeDefinition.HtmlContentType, [StandardContentTypeNames.Text]); } var textBufferFactoryService = (ITextBufferFactoryService3)exportProvider.GetExportedValue(); var bufferManager = WebTools.BufferManager.New(contentTypeService, textBufferFactoryService, []); - var logger = new ClaspLoggingBridge(_loggerFactory); + var logger = _loggerFactory.GetOrCreateLogger("ApplyFormattedEditsHandler"); var applyFormatEditsHandler = WebTools.ApplyFormatEditsHandler.New(textBufferFactoryService, bufferManager, logger); // Make sure the buffer manager knows about the source document diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/WebTools.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/WebTools.cs index e29535214f..ec0430afe1 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/WebTools.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/WebTools.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT license. See License.txt in the project root for license information. -extern alias LegacyClasp; - using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -10,7 +8,8 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.PooledObjects; -using Microsoft.CommonLanguageServerProtocol.Framework; +using Microsoft.CodeAnalysis.Razor.Logging; +using Microsoft.VisualStudio.Settings.Internal; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Utilities; using Microsoft.WebTools.Languages.Shared.Editor.Composition; @@ -32,6 +31,7 @@ internal static class WebTools private const string ApplyFormatEditsParamTypeName = "Microsoft.WebTools.Languages.Shared.Editor.LanguageServer.ContainedLanguage.ApplyFormatEditsParam"; private const string ApplyFormatEditsResponseTypeName = "Microsoft.WebTools.Languages.Shared.Editor.LanguageServer.ContainedLanguage.ApplyFormatEditsResponse"; private const string TextChangeTypeName = "Microsoft.WebTools.Languages.Shared.Editor.EditorHelpers.TextChange"; + private const string LspLoggerTypeName = "Microsoft.WebTools.Languages.LanguageServer.Server.Shared.Clasp.LspLogger"; private static Assembly? s_serverAssembly; private static Assembly? s_editorAssembly; @@ -240,29 +240,56 @@ internal static class WebTools public static ApplyFormatEditsHandler New( ITextBufferFactoryService3 textBufferFactoryService, BufferManager bufferManager, - ILspLogger logger) + ILogger logger) { - var instance = CreateInstance(Type, textBufferFactoryService, bufferManager.Instance, new LegacyClaspILspLogger(logger)); + var instance = CreateInstance(Type, textBufferFactoryService, bufferManager.Instance, LspLogger.New(logger).Instance); + return new(instance); + } + } + + public sealed class LspLogger(object instance) : ReflectedObject(instance) + { + private static Type? s_type; + + public static Type Type + => s_type ?? InterlockedOperations.Initialize(ref s_type, + WebTools.GetType(ServerAssembly, LspLoggerTypeName)); + + public static RequestContext New(ILogger logger) + { + var instance = CreateInstance(Type, new MicrosoftExtensionsLoggerWrapper(logger)); return new(instance); } - /// - /// Wraps the razor logger (from the clasp source package) into the binary clasp logger that webtools uses. - /// - /// - private class LegacyClaspILspLogger(ILspLogger logger) : LegacyClasp.Microsoft.CommonLanguageServerProtocol.Framework.ILspLogger + private class MicrosoftExtensionsLoggerWrapper(ILogger logger) : Microsoft.Extensions.Logging.ILogger { - public void LogEndContext(string message, params object[] @params) => logger.LogEndContext(message, @params); + public IDisposable? BeginScope(TState state) where TState : notnull + { + return NoOpDisposable.Instance; + } - public void LogError(string message, params object[] @params) => logger.LogError(message, @params); + public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) + { + return true; + } - public void LogException(Exception exception, string? message = null, params object[] @params) => logger.LogException(exception, message, @params); + public void Log(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state, Exception? exception, Func formatter) + { + var message = formatter(state, exception); + var level = logLevel switch + { + Microsoft.Extensions.Logging.LogLevel.Trace => LogLevel.Trace, + Microsoft.Extensions.Logging.LogLevel.Debug => LogLevel.Debug, + Microsoft.Extensions.Logging.LogLevel.Information => LogLevel.Information, + Microsoft.Extensions.Logging.LogLevel.Warning => LogLevel.Warning, + Microsoft.Extensions.Logging.LogLevel.Error => LogLevel.Error, + Microsoft.Extensions.Logging.LogLevel.Critical => LogLevel.Critical, + Microsoft.Extensions.Logging.LogLevel.None => LogLevel.None, + _ => throw new NotImplementedException() + }; - public void LogInformation(string message, params object[] @params) => logger.LogInformation(message, @params); - - public void LogStartContext(string message, params object[] @params) => logger.LogStartContext(message, @params); - - public void LogWarning(string message, params object[] @params) => logger.LogWarning(message, @params); + logger.Log(level, message); + } } } } diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Microsoft.AspNetCore.Razor.LanguageServer.Test.csproj b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Microsoft.AspNetCore.Razor.LanguageServer.Test.csproj index ab200262e8..b50276628e 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Microsoft.AspNetCore.Razor.LanguageServer.Test.csproj +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Microsoft.AspNetCore.Razor.LanguageServer.Test.csproj @@ -6,18 +6,6 @@ $(DefineConstants);GENERATE_BASELINES $(DefineConstants);__RemoveThisBitTo__GENERATE_BASELINES - - - 4.7.0-1.23178.15 @@ -35,19 +23,9 @@ + - - - - - - - - true - LegacyClasp - - - +