Skip to content

Commit fb84ae5

Browse files
Co-hosting: Add API for mapping a generated document URI and range back to the host document (#10712)
There's a fair amount of refactoring here, but I was careful to separate everything. So, I recommend reviewing commit-by-commit.
2 parents 36542b2 + a2c21cf commit fb84ae5

File tree

121 files changed

+1065
-794
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+1065
-794
lines changed

src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCodeActionsBenchmark.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public enum FileTypes
4949
public async Task SetupAsync()
5050
{
5151
CodeActionEndpoint = new CodeActionEndpoint(
52-
documentMappingService: RazorLanguageServerHost.GetRequiredService<IRazorDocumentMappingService>(),
52+
documentMappingService: RazorLanguageServerHost.GetRequiredService<IDocumentMappingService>(),
5353
razorCodeActionProviders: RazorLanguageServerHost.GetRequiredService<IEnumerable<IRazorCodeActionProvider>>(),
5454
csharpCodeActionProviders: RazorLanguageServerHost.GetRequiredService<IEnumerable<ICSharpCodeActionProvider>>(),
5555
htmlCodeActionProviders: RazorLanguageServerHost.GetRequiredService<IEnumerable<IHtmlCodeActionProvider>>(),

src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorCompletionBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public async Task SetupAsync()
3838
var razorCompletionListProvider = RazorLanguageServerHost.GetRequiredService<RazorCompletionListProvider>();
3939
var lspServices = RazorLanguageServerHost.GetRequiredService<ILspServices>();
4040
var responseRewriters = lspServices.GetRequiredServices<DelegatedCompletionResponseRewriter>();
41-
var documentMappingService = lspServices.GetRequiredService<IRazorDocumentMappingService>();
41+
var documentMappingService = lspServices.GetRequiredService<IDocumentMappingService>();
4242
var clientConnection = lspServices.GetRequiredService<IClientConnection>();
4343
var completionListCache = lspServices.GetRequiredService<CompletionListCache>();
4444
var loggerFactory = lspServices.GetRequiredService<ILoggerFactory>();
@@ -141,7 +141,7 @@ public async Task RazorCompletionAsync()
141141

142142
private class TestDelegatedCompletionListProvider : DelegatedCompletionListProvider
143143
{
144-
public TestDelegatedCompletionListProvider(IEnumerable<DelegatedCompletionResponseRewriter> responseRewriters, IRazorDocumentMappingService documentMappingService, IClientConnection clientConnection, CompletionListCache completionListCache)
144+
public TestDelegatedCompletionListProvider(IEnumerable<DelegatedCompletionResponseRewriter> responseRewriters, IDocumentMappingService documentMappingService, IClientConnection clientConnection, CompletionListCache completionListCache)
145145
: base(responseRewriters, documentMappingService, clientConnection, completionListCache)
146146
{
147147
}

src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorDiagnosticsBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ private protected override LanguageServerFeatureOptions BuildFeatureOptions()
115115
MockBehavior.Strict);
116116
}
117117

118-
private IRazorDocumentMappingService BuildRazorDocumentMappingService()
118+
private IDocumentMappingService BuildRazorDocumentMappingService()
119119
{
120-
var razorDocumentMappingService = new Mock<IRazorDocumentMappingService>(MockBehavior.Strict);
120+
var razorDocumentMappingService = new Mock<IDocumentMappingService>(MockBehavior.Strict);
121121

122122
Range? hostDocumentRange;
123123
razorDocumentMappingService.Setup(

src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorDocumentMappingBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class RazorDocumentMappingBenchmark : RazorLanguageServerBenchmarkBase
1919
{
2020
private string _filePath;
2121

22-
private IRazorDocumentMappingService DocumentMappingService { get; set; }
22+
private IDocumentMappingService DocumentMappingService { get; set; }
2323

2424
private IDocumentSnapshot DocumentSnapshot { get; set; }
2525

@@ -171,6 +171,6 @@ public async Task CleanupServerAsync()
171171

172172
private void EnsureServicesInitialized()
173173
{
174-
DocumentMappingService = RazorLanguageServerHost.GetRequiredService<IRazorDocumentMappingService>();
174+
DocumentMappingService = RazorLanguageServerHost.GetRequiredService<IDocumentMappingService>();
175175
}
176176
}

src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ internal class TestRazorSemanticTokensInfoService : RazorSemanticTokensInfoServi
108108
{
109109
public TestRazorSemanticTokensInfoService(
110110
LanguageServerFeatureOptions languageServerFeatureOptions,
111-
IRazorDocumentMappingService documentMappingService,
111+
IDocumentMappingService documentMappingService,
112112
RazorSemanticTokensLegendService razorSemanticTokensLegendService,
113113
ILoggerFactory loggerFactory)
114114
: base(documentMappingService, razorSemanticTokensLegendService, csharpSemanticTokensProvider: null!, languageServerFeatureOptions, loggerFactory)

src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensRangeEndpointBenchmark.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ internal class TestCustomizableRazorSemanticTokensInfoService : RazorSemanticTok
140140
{
141141
public TestCustomizableRazorSemanticTokensInfoService(
142142
LanguageServerFeatureOptions languageServerFeatureOptions,
143-
IRazorDocumentMappingService documentMappingService,
143+
IDocumentMappingService documentMappingService,
144144
RazorSemanticTokensLegendService razorSemanticTokensLegendService,
145145
ILoggerFactory loggerFactory)
146146
: base(documentMappingService, razorSemanticTokensLegendService, csharpSemanticTokensProvider: null!, languageServerFeatureOptions, loggerFactory)

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AbstractRazorDelegatingEndpoint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ internal abstract class AbstractRazorDelegatingEndpoint<TRequest, TResponse> : I
2222
where TRequest : ITextDocumentPositionParams
2323
{
2424
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions;
25-
private readonly IRazorDocumentMappingService _documentMappingService;
25+
private readonly IDocumentMappingService _documentMappingService;
2626
private readonly IClientConnection _clientConnection;
2727
protected readonly ILogger Logger;
2828

2929
protected AbstractRazorDelegatingEndpoint(
3030
LanguageServerFeatureOptions languageServerFeatureOptions,
31-
IRazorDocumentMappingService documentMappingService,
31+
IDocumentMappingService documentMappingService,
3232
IClientConnection clientConnection,
3333
ILogger logger)
3434
{

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertEndpoint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert;
2323
[RazorLanguageServerEndpoint(VSInternalMethods.OnAutoInsertName)]
2424
internal class OnAutoInsertEndpoint(
2525
LanguageServerFeatureOptions languageServerFeatureOptions,
26-
IRazorDocumentMappingService documentMappingService,
26+
IDocumentMappingService documentMappingService,
2727
IClientConnection clientConnection,
2828
IEnumerable<IOnAutoInsertProvider> onAutoInsertProvider,
2929
RazorLSPOptionsMonitor optionsMonitor,
@@ -170,7 +170,7 @@ public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, V
170170
}
171171

172172
return Task.FromResult<IDelegatedParams?>(new DelegatedOnAutoInsertParams(
173-
documentContext.Identifier,
173+
documentContext.GetTextDocumentIdentifierAndVersion(),
174174
positionInfo.Position,
175175
positionInfo.LanguageKind,
176176
request.Character,

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/PreferHtmlInAttributeValuesDocumentPositionStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal class PreferHtmlInAttributeValuesDocumentPositionInfoStrategy : IDocume
2020
{
2121
public static IDocumentPositionInfoStrategy Instance { get; } = new PreferHtmlInAttributeValuesDocumentPositionInfoStrategy();
2222

23-
public async Task<DocumentPositionInfo?> TryGetPositionInfoAsync(IRazorDocumentMappingService documentMappingService, DocumentContext documentContext, Position position, CancellationToken cancellationToken)
23+
public async Task<DocumentPositionInfo?> TryGetPositionInfoAsync(IDocumentMappingService documentMappingService, DocumentContext documentContext, Position position, CancellationToken cancellationToken)
2424
{
2525
var defaultDocumentPositionInfo = await DefaultDocumentPositionInfoStrategy.Instance.TryGetPositionInfoAsync(documentMappingService, documentContext, position, cancellationToken).ConfigureAwait(false);
2626
if (defaultDocumentPositionInfo is null)

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;
2323
internal sealed class UnformattedRemappingCSharpCodeActionResolver(
2424
IDocumentContextFactory documentContextFactory,
2525
IClientConnection clientConnection,
26-
IRazorDocumentMappingService documentMappingService) : CSharpCodeActionResolver(clientConnection)
26+
IDocumentMappingService documentMappingService) : CSharpCodeActionResolver(clientConnection)
2727
{
2828
private readonly IDocumentContextFactory _documentContextFactory = documentContextFactory;
29-
private readonly IRazorDocumentMappingService _documentMappingService = documentMappingService;
29+
private readonly IDocumentMappingService _documentMappingService = documentMappingService;
3030

3131
public override string Action => LanguageServerConstants.CodeActions.UnformattedRemap;
3232

0 commit comments

Comments
 (0)