Skip to content

Commit

Permalink
Fix tests that instantiate webtools types that require clasp binary
Browse files Browse the repository at this point in the history
  • Loading branch information
dibarbet committed Mar 22, 2024
1 parent bbe0b53 commit 1b322ac
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<ItemGroup>
<!-- Need this reference to avoid 'The C# language is not supported' error during formatting. -->
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion)" />
<PackageReference Include="Microsoft.CommonLanguageServerProtocol.Framework" Version="$(MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion)" />
<PackageReference Include="Microsoft.CommonLanguageServerProtocol.Framework" Version="$(MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsPackageVersion)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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;
Expand Down Expand Up @@ -240,8 +242,27 @@ public static ApplyFormatEditsHandler New(
BufferManager bufferManager,
ILspLogger logger)
{
var instance = CreateInstance(Type, textBufferFactoryService, bufferManager.Instance, logger);
var instance = CreateInstance(Type, textBufferFactoryService, bufferManager.Instance, new LegacyClaspILspLogger(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
{
public void LogEndContext(string message, params object[] @params) => logger.LogEndContext(message, @params);

public void LogError(string message, params object[] @params) => logger.LogError(message, @params);

public void LogException(Exception exception, string? message = null, params object[] @params) => logger.LogException(exception, message, @params);

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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
<!-- 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>
Expand All @@ -29,6 +41,17 @@
<PackageReference Include="Microsoft.WebTools.Shared" Version="$(MicrosoftWebToolsSharedPackageVersion)" />
</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" />
Expand Down

0 comments on commit 1b322ac

Please sign in to comment.