Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Razor EA For Roslyn #11510

Merged
merged 46 commits into from
Mar 27, 2025
Merged
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9abb389
Move naming
ryzngard Jan 28, 2025
e4cb0ac
Fix build
ryzngard Jan 28, 2025
3ef44b4
Remove ProjectEngineHost project by moving things into
ryzngard Jan 28, 2025
315658b
Update resource files
ryzngard Feb 11, 2025
590367c
Fix compilation
ryzngard Feb 12, 2025
1413236
Bump local packages
ryzngard Feb 14, 2025
a3eeb9f
Respond to changes in roslyn EA
ryzngard Feb 19, 2025
0f09a56
Merge branch 'main' into remove_razor_ea
ryzngard Feb 19, 2025
2a57a43
Nullability and usings
ryzngard Feb 19, 2025
fdacf95
Remove local nuget
ryzngard Feb 19, 2025
059341f
Final changes
ryzngard Feb 21, 2025
404c321
Compiling and ready for testing. Still failing
ryzngard Feb 22, 2025
f265359
Merge branch 'main' into remove_razor_ea
ryzngard Feb 23, 2025
46a9970
Merge branch 'main' into remove_razor_ea
ryzngard Mar 12, 2025
4c4871b
Don't export stateless service
ryzngard Mar 12, 2025
1eb80e6
Merge branch 'main' into remove_razor_ea
ryzngard Mar 14, 2025
f964da7
Remove using
ryzngard Mar 14, 2025
5bce5e4
Working...
ryzngard Mar 20, 2025
5cc494e
Package the extension into a nupkg
ryzngard Mar 20, 2025
24381ea
Remove Nuget.config changes
ryzngard Mar 21, 2025
951f9ea
Update layering doc and undo unnecessary changes
ryzngard Mar 21, 2025
87517c1
Remove file that was meant to be removed...
ryzngard Mar 21, 2025
26ff153
change to sealed class
ryzngard Mar 21, 2025
9c18bad
Rename files
ryzngard Mar 21, 2025
21fb54c
Remove file
ryzngard Mar 21, 2025
d1c4f2b
Fix namespaces
ryzngard Mar 21, 2025
d9a7e5a
Remove test project and merge into workspaces
ryzngard Mar 21, 2025
24efc13
Remove last references to Microsoft.CodeAnalysis.Razor.ProjectEngineHost
ryzngard Mar 21, 2025
1f654eb
Restore PrivateAssets
ryzngard Mar 21, 2025
138491f
Merge branch 'main' into remove_razor_ea
ryzngard Mar 21, 2025
9c1bfd6
Add back UrlDecoderTests
ryzngard Mar 21, 2025
bd88e39
Use collection expressions
ryzngard Mar 21, 2025
7cda646
Remove unused type
ryzngard Mar 24, 2025
003e335
Merge branch 'remove_razor_ea' of https://github.com/ryzngard/razor i…
ryzngard Mar 24, 2025
76ee9d5
Remove duplicated types
ryzngard Mar 24, 2025
f7a49db
Reuse types
ryzngard Mar 25, 2025
6c7b39b
Fix HashSet usage and null out when done
ryzngard Mar 25, 2025
be26139
Allow multiple updates to be applied since we allow that in the vs co…
ryzngard Mar 25, 2025
39a5c88
Consolidate code
ryzngard Mar 25, 2025
8758737
Handle null response
ryzngard Mar 25, 2025
ba48169
Use real versions
ryzngard Mar 26, 2025
b70298f
Update namespaces
ryzngard Mar 26, 2025
6fa2618
Update Version.details.xml
ryzngard Mar 26, 2025
9d86df7
Update with darc and fix source build
ryzngard Mar 26, 2025
91ba66c
Skip failing test
ryzngard Mar 26, 2025
e812dab
Unblock for now
ryzngard Mar 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Respond to changes in roslyn EA
ryzngard committed Feb 19, 2025
commit a3eeb9f49618b6fd18433cfb4002d5df32725689
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;

@@ -20,7 +21,6 @@ internal sealed class DefaultDynamicDocumentContainer(IDocumentSnapshot document
{
private readonly IDocumentSnapshot _documentSnapshot = documentSnapshot ?? throw new ArgumentNullException(nameof(documentSnapshot));
private RazorDocumentExcerptService? _excerptService;
private RazorSpanMappingService? _spanMappingService;
private RazorMappingService? _mappingService;

public string FilePath => _documentSnapshot.FilePath;
@@ -37,11 +37,7 @@ public TextLoader GetTextLoader(string filePath)

public IRazorDocumentExcerptServiceImplementation GetExcerptService()
=> _excerptService ?? InterlockedOperations.Initialize(ref _excerptService,
new RazorDocumentExcerptService(_documentSnapshot, GetSpanMappingService()));

public IRazorSpanMappingService GetSpanMappingService()
=> _spanMappingService ?? InterlockedOperations.Initialize(ref _spanMappingService,
new RazorSpanMappingService(_documentSnapshot));
new RazorDocumentExcerptService(_documentSnapshot, GetMappingService()));

public IRazorDocumentPropertiesService GetDocumentPropertiesService()
{
@@ -52,7 +48,7 @@ public IRazorDocumentPropertiesService GetDocumentPropertiesService()
return null!;
}

public IRazorMappingService? GetMappingService()
public IRazorMappingService GetMappingService()
=> _mappingService ?? InterlockedOperations.Initialize(ref _mappingService,
new RazorMappingService(_documentSnapshot, NoOpTelemetryReporter.Instance, loggerFactory));
}
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;

namespace Microsoft.VisualStudio.Razor.DynamicFiles;

@@ -16,8 +17,7 @@ internal interface IDynamicDocumentContainer

TextLoader GetTextLoader(string filePath);

IRazorSpanMappingService? GetSpanMappingService();
IRazorMappingService? GetMappingService();
IRazorMappingService GetMappingService();
IRazorDocumentExcerptServiceImplementation? GetExcerptService();
IRazorDocumentPropertiesService GetDocumentPropertiesService();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;

namespace Microsoft.VisualStudio.Razor.DynamicFiles;

Original file line number Diff line number Diff line change
@@ -10,17 +10,18 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.VisualStudio.Razor.DynamicFiles;

internal class RazorDocumentExcerptService(
IDocumentSnapshot document,
IRazorSpanMappingService mappingService) : DocumentExcerptService
IRazorMappingService mappingService) : DocumentExcerptService
{
private readonly IDocumentSnapshot _document = document;
private readonly IRazorSpanMappingService _mappingService = mappingService;
private readonly IRazorMappingService _mappingService = mappingService;

internal override async Task<ExcerptResultInternal?> TryGetExcerptInternalAsync(
Document document,
Original file line number Diff line number Diff line change
@@ -2,15 +2,15 @@
// Licensed under the MIT license. See License.txt in the project root for license information.

using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;

namespace Microsoft.VisualStudio.Razor.DynamicFiles;

internal class RazorDocumentServiceProvider(IDynamicDocumentContainer? documentContainer) : IRazorDocumentServiceProvider, IRazorDocumentOperationService
internal class RazorDocumentServiceProvider(IDynamicDocumentContainer? documentContainer) : IRazorDocumentServiceProvider
{
private readonly IDynamicDocumentContainer? _documentContainer = documentContainer;
private readonly object _lock = new object();

private IRazorSpanMappingService? _spanMappingService;
private IRazorDocumentExcerptServiceImplementation? _documentExcerptService;
private IRazorDocumentPropertiesService? _documentPropertiesService;
private IRazorMappingService? _mappingService;
@@ -33,19 +33,6 @@ public RazorDocumentServiceProvider()

var serviceType = typeof(TService);

if (serviceType == typeof(IRazorSpanMappingService))
{
if (_spanMappingService is null)
{
lock (_lock)
{
_spanMappingService ??= _documentContainer.GetSpanMappingService();
}
}

return (TService?)_spanMappingService;
}

if (serviceType == typeof(IRazorDocumentExcerptServiceImplementation))
{
if (_documentExcerptService is null)
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

using System;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;

namespace Microsoft.VisualStudio.Razor.DynamicFiles;

Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Workspaces;
@@ -59,6 +60,11 @@ public RazorDynamicFileInfoProvider(

public event EventHandler<string>? Updated;

public Task EnsureInitializedAsync(Func<CancellationToken, Task<IRazorClientLanguageServerManager>> getLanguageServerManager, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

// Called by us to update LSP document entries
public void UpdateLSPFileInfo(Uri documentUri, IDynamicDocumentContainer documentContainer)
{
@@ -168,10 +174,9 @@ public void PromoteBackgroundDocument(Uri documentUri, IRazorDocumentPropertiesS
// server to recognize the document.
var documentServiceProvider = associatedEntry.Current.DocumentServiceProvider;
var excerptService = documentServiceProvider.GetService<IRazorDocumentExcerptServiceImplementation>();
var spanMappingService = documentServiceProvider.GetService<IRazorSpanMappingService>();
var mappingService = documentServiceProvider.GetService<IRazorMappingService>();
var emptyContainer = new PromotedDynamicDocumentContainer(
documentUri, propertiesService, excerptService, spanMappingService, mappingService, associatedEntry.Current.TextLoader);
documentUri, propertiesService, excerptService, mappingService, associatedEntry.Current.TextLoader);

lock (associatedEntry.Lock)
{
@@ -236,7 +241,7 @@ public void SuppressDocument(ProjectKey projectKey, string documentFilePath)
}
}

public Task<RazorDynamicFileInfo?> GetDynamicFileInfoAsync(ProjectId projectId, string? projectFilePath, string filePath, CancellationToken cancellationToken)
public Task<IRazorDynamicFileInfo?> GetDynamicFileInfoAsync(ProjectId projectId, string? projectFilePath, string filePath, CancellationToken cancellationToken)
{
if (projectFilePath is null)
{
@@ -253,15 +258,15 @@ public void SuppressDocument(ProjectKey projectKey, string documentFilePath)
var projectKey = TryFindProjectKeyForProjectId(projectId);
if (projectKey is not { } razorProjectKey)
{
return SpecializedTasks.Null<RazorDynamicFileInfo>();
return SpecializedTasks.Null<IRazorDynamicFileInfo>();
}

_fallbackProjectManager.DynamicFileAdded(projectId, razorProjectKey, projectFilePath, filePath, cancellationToken);

var key = new Key(projectId, filePath);
var entry = _entries.GetOrAdd(key, _createEmptyEntry);

return Task.FromResult<RazorDynamicFileInfo?>(entry.Current);
return Task.FromResult<IRazorDynamicFileInfo?>(entry.Current);
}

public Task RemoveDynamicFileInfoAsync(ProjectId projectId, string? projectFilePath, string filePath, CancellationToken cancellationToken)
@@ -465,15 +470,13 @@ private sealed class PromotedDynamicDocumentContainer(
Uri documentUri,
IRazorDocumentPropertiesService documentPropertiesService,
IRazorDocumentExcerptServiceImplementation? documentExcerptService,
IRazorSpanMappingService? spanMappingService,
IRazorMappingService? mappingService,
IRazorMappingService mappingService,
TextLoader textLoader) : IDynamicDocumentContainer
{
private readonly Uri _documentUri = documentUri;
private readonly IRazorDocumentPropertiesService _documentPropertiesService = documentPropertiesService;
private readonly IRazorDocumentExcerptServiceImplementation? _documentExcerptService = documentExcerptService;
private readonly IRazorSpanMappingService? _spanMappingService = spanMappingService;
private readonly IRazorMappingService? _mappingService = mappingService;
private readonly IRazorMappingService _mappingService = mappingService;
private readonly TextLoader _textLoader = textLoader;

public string FilePath => _documentUri.LocalPath;
@@ -489,11 +492,9 @@ public void SetSupportsDiagnostics(bool value)

public IRazorDocumentExcerptServiceImplementation? GetExcerptService() => _documentExcerptService;

public IRazorSpanMappingService? GetSpanMappingService() => _spanMappingService;

public TextLoader GetTextLoader(string filePath) => _textLoader;

public IRazorMappingService? GetMappingService() => _mappingService;
public IRazorMappingService GetMappingService() => _mappingService;
}

public class TestAccessor
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.DocumentMapping;
using Microsoft.CodeAnalysis.Razor.Logging;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.ContainedLanguage;
using Microsoft.VisualStudio.Razor.DynamicFiles;
@@ -16,12 +17,12 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient;

internal sealed class CSharpDocumentExcerptService : DocumentExcerptService
{
private readonly IRazorSpanMappingService _mappingService;
private readonly IRazorMappingService _mappingService;

private readonly LSPDocumentSnapshot _documentSnapshot;

public CSharpDocumentExcerptService(
IRazorSpanMappingService mappingService,
IRazorMappingService mappingService,
LSPDocumentSnapshot documentSnapshot)
{
if (mappingService is null)
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
using Microsoft.AspNetCore.Razor;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.ContainedLanguage;
using Microsoft.VisualStudio.Razor.DynamicFiles;
@@ -78,7 +79,6 @@ private sealed class CSharpVirtualDocumentContainer(
private readonly LSPDocumentSnapshot _documentSnapshot = documentSnapshot;
private readonly ITextSnapshot _textSnapshot = textSnapshot;

private IRazorSpanMappingService? _spanMappingService;
private IRazorMappingService? _mappingService;
private IRazorDocumentExcerptServiceImplementation? _excerptService;

@@ -93,19 +93,15 @@ public void SetSupportsDiagnostics(bool value)

public IRazorDocumentExcerptServiceImplementation GetExcerptService()
=> _excerptService ?? InterlockedOperations.Initialize(ref _excerptService,
new CSharpDocumentExcerptService(GetSpanMappingService(), _documentSnapshot));

public IRazorSpanMappingService GetSpanMappingService()
=> _spanMappingService ?? InterlockedOperations.Initialize(ref _spanMappingService,
new RazorLSPSpanMappingService(_lspDocumentMappingProvider, _documentSnapshot, _textSnapshot));
new CSharpDocumentExcerptService(GetMappingService(), _documentSnapshot));

public IRazorDocumentPropertiesService GetDocumentPropertiesService()
=> CSharpDocumentPropertiesService.Instance;

public TextLoader GetTextLoader(string filePath)
=> new SourceTextLoader(_textSnapshot.AsText(), filePath);

public IRazorMappingService? GetMappingService()
public IRazorMappingService GetMappingService()
=> _mappingService ?? InterlockedOperations.Initialize(ref _mappingService,
new RazorLSPMappingService(_lspDocumentMappingProvider, _documentSnapshot, _textSnapshot));

Original file line number Diff line number Diff line change
@@ -4,13 +4,13 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;

namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;

internal sealed class RazorCohostClientConnection(IRazorCohostClientLanguageServerManager clientNotifier) : IClientConnection
internal sealed class RazorCohostClientConnection(IRazorClientLanguageServerManager clientNotifier) : IClientConnection
{
private readonly IRazorCohostClientLanguageServerManager _clientNotifier = clientNotifier;
private readonly IRazorClientLanguageServerManager _clientNotifier = clientNotifier;

public Task SendNotificationAsync<TParams>(string method, TParams @params, CancellationToken cancellationToken)
=> _clientNotifier.SendNotificationAsync(method, @params, cancellationToken).AsTask();
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.VisualStudio.LanguageServer.Protocol;
@@ -64,7 +65,7 @@ public async Task RegisterAsync(string clientCapabilitiesString, RazorCohostRequ
}
}

var razorCohostClientLanguageServerManager = requestContext.GetRequiredService<IRazorCohostClientLanguageServerManager>();
var razorCohostClientLanguageServerManager = requestContext.GetRequiredService<IRazorClientLanguageServerManager>();

await razorCohostClientLanguageServerManager.SendRequestAsync(
Methods.ClientRegisterCapabilityName,
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;
using Microsoft.CodeAnalysis.Razor.Protocol;
using Microsoft.CodeAnalysis.Razor.Protocol.DocumentMapping;
using Microsoft.CodeAnalysis.Text;
@@ -84,7 +84,7 @@ private async Task<ImmutableArray<RazorMappedSpanResult>> MapSpansAsync(
return mappedSpanResults;
}

private static ImmutableArray<RazorMappedSpanResult> GetMappedSpanResults(
internal static ImmutableArray<RazorMappedSpanResult> GetMappedSpanResults(
string localFilePath,
SourceText sourceTextRazor,
RazorMapToDocumentRangesResponse? mappedResult)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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.Text.Json.Serialization;
using Microsoft.VisualStudio.LanguageServer.Protocol;

namespace Microsoft.VisualStudioCode.RazorExtension.Endpoints;

internal class RazorDynamicFileChangedParams
{
[JsonPropertyName("razorDocument")]
public required TextDocumentIdentifier RazorDocument { get; set; }
}
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@ private async Task VerifyHighlightingRangesAsync(string input)
DocumentHighlightProvider = true
};
await using var csharpServer = await CSharpTestLspServerHelpers.CreateCSharpLspServerAsync(
csharpSourceText, csharpDocumentUri, serverCapabilities, razorSpanMappingService: null, capabilitiesUpdater: null, DisposalToken);
csharpSourceText, csharpDocumentUri, serverCapabilities, razorMappingService: null, capabilitiesUpdater: null, DisposalToken);
await csharpServer.OpenDocumentAsync(csharpDocumentUri, csharpSourceText.ToString());

var razorFilePath = "C:/path/to/file.razor";
Original file line number Diff line number Diff line change
@@ -186,7 +186,7 @@ public async Task Handle_Hover_SingleServer_AddTagHelper()
};

await using var csharpServer = await CSharpTestLspServerHelpers.CreateCSharpLspServerAsync(
csharpSourceText, csharpDocumentUri, serverCapabilities, razorSpanMappingService: null, capabilitiesUpdater: null, DisposalToken);
csharpSourceText, csharpDocumentUri, serverCapabilities, razorMappingService: null, capabilitiesUpdater: null, DisposalToken);
await csharpServer.OpenDocumentAsync(csharpDocumentUri, csharpSourceText.ToString());

var razorFilePath = "C:/path/to/file.razor";
Original file line number Diff line number Diff line change
@@ -283,7 +283,7 @@ private async Task VerifyCodeMappingAsync(
var csharpSourceText = codeDocument.GetCSharpSourceText();
var csharpDocumentUri = new Uri(razorFilePath + "__virtual.g.cs");
await using var csharpServer = await CSharpTestLspServerHelpers.CreateCSharpLspServerAsync(
csharpSourceText, csharpDocumentUri, new VSInternalServerCapabilities(), razorSpanMappingService: null, capabilitiesUpdater: null, DisposalToken);
csharpSourceText, csharpDocumentUri, new VSInternalServerCapabilities(), razorMappingService: null, capabilitiesUpdater: null, DisposalToken);
await csharpServer.OpenDocumentAsync(csharpDocumentUri, csharpSourceText.ToString());

var documentContextFactory = new TestDocumentContextFactory(razorFilePath, codeDocument);
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ private protected async Task<TestLanguageServer> CreateLanguageServerAsync(
{
SupportsDiagnosticRequests = true,
},
razorSpanMappingService: null,
razorMappingService: null,
multiTargetProject,
capabilitiesUpdater,
DisposalToken);
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
using Microsoft.AspNetCore.Razor.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Text;
@@ -37,7 +38,7 @@ public static Task<CSharpTestLspServer> CreateCSharpLspServerAsync(
SourceText csharpSourceText,
Uri csharpDocumentUri,
VSInternalServerCapabilities serverCapabilities,
IRazorSpanMappingService razorSpanMappingService,
IRazorMappingService razorMappingService,
Action<VSInternalClientCapabilities> capabilitiesUpdater,
CancellationToken cancellationToken)
{
@@ -46,13 +47,13 @@ public static Task<CSharpTestLspServer> CreateCSharpLspServerAsync(
(csharpDocumentUri, csharpSourceText)
};

return CreateCSharpLspServerAsync(files, serverCapabilities, razorSpanMappingService, multiTargetProject: true, capabilitiesUpdater, cancellationToken);
return CreateCSharpLspServerAsync(files, serverCapabilities, razorMappingService, multiTargetProject: true, capabilitiesUpdater, cancellationToken);
}

public static async Task<CSharpTestLspServer> CreateCSharpLspServerAsync(
IEnumerable<(Uri Uri, SourceText SourceText)> files,
VSInternalServerCapabilities serverCapabilities,
IRazorSpanMappingService razorSpanMappingService,
IRazorMappingService razorMappingService,
bool multiTargetProject,
Action<VSInternalClientCapabilities> capabilitiesUpdater,
CancellationToken cancellationToken)
@@ -64,7 +65,7 @@ public static async Task<CSharpTestLspServer> CreateCSharpLspServerAsync(
var metadataReferences = await ReferenceAssemblies.Default.ResolveAsync(language: LanguageNames.CSharp, cancellationToken);
metadataReferences = metadataReferences.Add(ReferenceUtil.AspNetLatestComponents);

var workspace = CreateCSharpTestWorkspace(csharpFiles, exportProvider, metadataReferences, razorSpanMappingService, multiTargetProject);
var workspace = CreateCSharpTestWorkspace(csharpFiles, exportProvider, metadataReferences, razorMappingService, multiTargetProject);

var clientCapabilities = new VSInternalClientCapabilities
{
@@ -104,7 +105,7 @@ private static AdhocWorkspace CreateCSharpTestWorkspace(
IEnumerable<CSharpFile> files,
ExportProvider exportProvider,
ImmutableArray<MetadataReference> metadataReferences,
IRazorSpanMappingService razorSpanMappingService,
IRazorMappingService razorMappingService,
bool multiTargetProject)
{
var workspace = TestWorkspace.CreateWithDiagnosticAnalyzers(exportProvider);
@@ -154,7 +155,7 @@ private static AdhocWorkspace CreateCSharpTestWorkspace(
name: "TestDocument" + documentCount,
filePath: documentFilePath,
loader: TextLoader.From(textAndVersion),
razorDocumentServiceProvider: new TestRazorDocumentServiceProvider(razorSpanMappingService));
razorDocumentServiceProvider: new TestRazorDocumentServiceProvider(razorMappingService));

workspace.AddDocument(documentInfo);
}
@@ -167,11 +168,16 @@ private static AdhocWorkspace CreateCSharpTestWorkspace(

private record CSharpFile(Uri DocumentUri, SourceText CSharpSourceText);

private class EmptyMappingService : IRazorSpanMappingService
private class EmptyMappingService : IRazorMappingService
{
public Task<ImmutableArray<RazorMappedSpanResult>> MapSpansAsync(Document document, IEnumerable<TextSpan> spans, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyImmutableArray<RazorMappedSpanResult>();
}

public Task<ImmutableArray<RazorMappedEditoResult>> MapTextChangesAsync(Document oldDocument, Document newDocument, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyImmutableArray<RazorMappedEditoResult>();
}
}
}
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
using Microsoft.AspNetCore.Razor.Test.Common.Workspaces;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
@@ -33,14 +33,14 @@ namespace Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;

public abstract class LanguageServerTestBase : ToolingTestBase
{
private protected IRazorSpanMappingService SpanMappingService { get; }
private protected IRazorMappingService SpanMappingService { get; }
private protected IFilePathService FilePathService { get; }
private protected JsonSerializerOptions SerializerOptions { get; }

protected LanguageServerTestBase(ITestOutputHelper testOutput)
: base(testOutput)
{
SpanMappingService = new ThrowingRazorSpanMappingService();
SpanMappingService = new ThrowingRazorMappingService();

SerializerOptions = JsonHelpers.VsLspJsonSerializerOptions;
FilePathService = new LSPFilePathService(TestLanguageServerFeatureOptions.Instance);
@@ -180,11 +180,16 @@ private static FormattingFlags GetFormattingFlags(bool enableFormatting, bool fo
return flags;
}

private class ThrowingRazorSpanMappingService : IRazorSpanMappingService
private class ThrowingRazorMappingService : IRazorMappingService
{
public Task<ImmutableArray<RazorMappedSpanResult>> MapSpansAsync(Document document, IEnumerable<TextSpan> spans, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task<ImmutableArray<RazorMappedEditoResult>> MapTextChangesAsync(Document oldDocument, Document newDocument, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -2,12 +2,13 @@
// Licensed under the MIT license. See License.txt in the project root for license information.

using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Shared;

namespace Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;

internal class TestRazorDocumentServiceProvider(IRazorSpanMappingService spanMappingService) : IRazorDocumentServiceProvider
internal class TestRazorDocumentServiceProvider(IRazorMappingService mappingService) : IRazorDocumentServiceProvider
{
private readonly IRazorSpanMappingService _spanMappingService = spanMappingService;
private readonly IRazorMappingService _mappingService = mappingService;

public bool CanApplyChange => true;

@@ -17,9 +18,9 @@ internal class TestRazorDocumentServiceProvider(IRazorSpanMappingService spanMap
{
var serviceType = typeof(TService);

if (serviceType == typeof(IRazorSpanMappingService))
if (serviceType == typeof(IRazorMappingService))
{
return (TService?)_spanMappingService;
return (TService?)_mappingService;
}

if (serviceType == typeof(IRazorDocumentPropertiesService))
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.AspNetCore.Razor.Telemetry;
using Microsoft.AspNetCore.Razor.Test.Common.Workspaces;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
@@ -642,6 +643,6 @@ public async Task TryGetExcerptInternalAsync_MultiLine_Boundaries_CanClassifyCSh

private RazorDocumentExcerptService CreateExcerptService(IDocumentSnapshot document)
{
return new RazorDocumentExcerptService(document, new RazorSpanMappingService(document));
return new RazorDocumentExcerptService(document, new RazorMappingService(document, NoOpTelemetryReporter.Instance, LoggerFactory));
}
}
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@

namespace Microsoft.VisualStudio.Razor.LanguageClient.DynamicFiles;

public class RazorSpanMappingServiceTest(ITestOutputHelper testOutput) : WorkspaceTestBase(testOutput)
public class RazorMappingServiceTest(ITestOutputHelper testOutput) : WorkspaceTestBase(testOutput)
{
private readonly HostProject _hostProject = TestProjectData.SomeProject;
private readonly HostDocument _hostDocument = TestProjectData.SomeProjectFile1;
@@ -43,7 +43,7 @@ public async Task TryGetMappedSpans_SpanMatchesSourceMapping_ReturnsTrue()

// Act
var text = await document.GetTextAsync(DisposalToken);
var result = RazorSpanMappingService.TryGetMappedSpans(span, text, generated, out var mappedLinePositionSpan, out var mappedSpan);
var result = RazorMappingService.TryGetMappedSpans(span, text, generated, out var mappedLinePositionSpan, out var mappedSpan);

// Assert
Assert.True(result);
@@ -78,7 +78,7 @@ public async Task TryGetMappedSpans_SpanMatchesSourceMappingAndPosition_ReturnsT

// Act
var text = await document.GetTextAsync(DisposalToken);
var result = RazorSpanMappingService.TryGetMappedSpans(span, text, generated, out var mappedLinePositionSpan, out var mappedSpan);
var result = RazorMappingService.TryGetMappedSpans(span, text, generated, out var mappedLinePositionSpan, out var mappedSpan);

// Assert
Assert.True(result);
@@ -112,7 +112,7 @@ public async Task TryGetMappedSpans_SpanWithinSourceMapping_ReturnsTrue()

// Act
var text = await document.GetTextAsync(DisposalToken);
var result = RazorSpanMappingService.TryGetMappedSpans(span, text, generated, out var mappedLinePositionSpan, out var mappedSpan);
var result = RazorMappingService.TryGetMappedSpans(span, text, generated, out var mappedLinePositionSpan, out var mappedSpan);

// Assert
Assert.True(result);
@@ -146,7 +146,7 @@ public async Task TryGetMappedSpans_SpanOutsideSourceMapping_ReturnsFalse()

// Act
var text = await document.GetTextAsync(DisposalToken);
var result = RazorSpanMappingService.TryGetMappedSpans(span, text, generated, out _, out _);
var result = RazorMappingService.TryGetMappedSpans(span, text, generated, out _, out _);

// Assert
Assert.False(result);
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ public void MapSpans_GetMappedSpanResults_MappingErrorReturnsDefaultMappedSpan()
var response = new RazorMapToDocumentRangesResponse { Ranges = new Range[] { VsLspFactory.UndefinedRange } };

// Act
var results = RazorLSPSpanMappingService.GetMappedSpanResults(_mockDocumentUri.LocalPath, sourceTextRazor, response);
var results = RazorLSPMappingService.GetMappedSpanResults(_mockDocumentUri.LocalPath, sourceTextRazor, response);

// Assert
Assert.Collection(results,

This file was deleted.

This file was deleted.