Bump WebTools and remove legacy CLaSP package

This commit is contained in:
David Wengier 2024-08-30 14:55:54 +10:00
Родитель 21c7674ac4
Коммит 8dc0e5a518
4 изменённых файлов: 50 добавлений и 45 удалений

Просмотреть файл

@ -5,7 +5,7 @@
here should be _ prefixed to indicate that they are not meant to be used outside this file.
-->
<PropertyGroup>
<_MicrosoftWebToolsPackageVersion>17.9.67-preview-0001</_MicrosoftWebToolsPackageVersion>
<_MicrosoftWebToolsPackageVersion>17.11.11-preview-0001</_MicrosoftWebToolsPackageVersion>
<_MicrosoftVisualStudioShellPackagesVersion>17.11.39721</_MicrosoftVisualStudioShellPackagesVersion>
<_MicrosoftVisualStudioPackagesVersion>17.11.191</_MicrosoftVisualStudioPackagesVersion>
<_VisualStudioLanguageServerProtocolVersion>17.12.1-preview</_VisualStudioLanguageServerProtocolVersion>

Просмотреть файл

@ -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<ITextBufferFactoryService>();
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

Просмотреть файл

@ -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);
}
/// <summary>
/// Wraps the razor logger (from the clasp source package) into the binary clasp logger that webtools uses.
/// </summary>
/// <param name="logger"></param>
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>(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<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> 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);
}
}
}
}

Просмотреть файл

@ -6,18 +6,6 @@
<!-- To generate baselines, run tests with /p:GenerateBaselines=true -->
<DefineConstants Condition="'$(GenerateBaselines)'=='true'">$(DefineConstants);GENERATE_BASELINES</DefineConstants>
<DefineConstants>$(DefineConstants);__RemoveThisBitTo__GENERATE_BASELINES</DefineConstants>
<!--
Some tests instantiate and run handlers from the webtools packages.
However, the webtools packages currently require the binary version of clasp (they haven't been updated yet).
In order to run them, we need to ensure that the clasp binary version is available. Below we use the PackageDownload
feature to download the package and include it in the output (we can't use a package reference because it would conflict with the source package version).
We also reference the package in this project using an alias - some of the webtools types we instantiate take clasp binary types as parameter, which we have to create.
This should be removed once we can upgrade to new webtools package versions that use the source package version of clasp.
-->
<LegacyClaspVersion>4.7.0-1.23178.15</LegacyClaspVersion>
</PropertyGroup>
<ItemGroup>
@ -35,19 +23,9 @@
<PackageReference Include="Microsoft.VisualStudio.Shell.Framework" />
<PackageReference Include="Microsoft.VisualStudio.Web" />
<PackageReference Include="Microsoft.WebTools.Shared" />
<PackageReference Include="Microsoft.Extensions.Logging" />
</ItemGroup>
<!-- Ensure the legacy clasp binary package is available downloaded so we can drop it in the output folder. -->
<ItemGroup>
<PackageDownload Include="Microsoft.CommonLanguageServerProtocol.Framework" Version="[$(LegacyClaspVersion)]" />
</ItemGroup>
<ItemGroup>
<Reference Include="$(NuGetPackageRoot)\microsoft.commonlanguageserverprotocol.framework\$(LegacyClaspVersion)\lib\netstandard2.0\Microsoft.CommonLanguageServerProtocol.Framework.dll">
<Private>true</Private>
<Aliases>LegacyClasp</Aliases>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Razor.LanguageServer\Microsoft.AspNetCore.Razor.LanguageServer.csproj" />
<ProjectReference Include="..\Microsoft.AspNetCore.Razor.Test.Common.Tooling\Microsoft.AspNetCore.Razor.Test.Common.Tooling.csproj" />