Skip to content

Commit f0d28cf

Browse files
committed
Fix endpoint and remote service to do mapping correctly
Plus some file header/footer issues
1 parent ca2f314 commit f0d28cf

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Threading;
@@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Razor.Remote;
1010

1111
internal interface IRemoteWrapWithTagService
1212
{
13-
ValueTask<RemoteResponse<bool>> IsValidWrapWithTagLocationAsync(RazorPinnedSolutionInfoWrapper solutionInfo, DocumentId razorDocumentId, LinePositionSpan range, CancellationToken cancellationToken);
14-
13+
ValueTask<RemoteResponse<LinePositionSpan>> GetValidWrappingRangeAsync(RazorPinnedSolutionInfoWrapper solutionInfo, DocumentId razorDocumentId, LinePositionSpan range, CancellationToken cancellationToken);
14+
1515
ValueTask<RemoteResponse<TextEdit[]?>> FixHtmlTextEditsAsync(RazorPinnedSolutionInfoWrapper solutionInfo, DocumentId razorDocumentId, TextEdit[] textEdits, CancellationToken cancellationToken);
16-
}
16+
}

src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/WrapWithTag/RemoteWrapWithTagService.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Threading;
@@ -7,12 +7,11 @@
77
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
88
using Microsoft.CodeAnalysis.Razor.Formatting;
99
using Microsoft.CodeAnalysis.Razor.Remote;
10-
using Microsoft.CodeAnalysis.Razor.Workspaces;
1110
using Microsoft.CodeAnalysis.Razor.Workspaces.Utilities;
1211
using Microsoft.CodeAnalysis.Remote.Razor.ProjectSystem;
1312
using Microsoft.CodeAnalysis.Text;
14-
using Response = Microsoft.CodeAnalysis.Razor.Remote.RemoteResponse<bool>;
15-
using TextEditResponse = Microsoft.CodeAnalysis.Razor.Remote.RemoteResponse<Microsoft.CodeAnalysis.Text.TextEdit[]?>;
13+
using Response = Microsoft.CodeAnalysis.Razor.Remote.RemoteResponse<Microsoft.CodeAnalysis.Text.LinePositionSpan>;
14+
using TextEditResponse = Microsoft.CodeAnalysis.Razor.Remote.RemoteResponse<Roslyn.LanguageServer.Protocol.TextEdit[]?>;
1615

1716
namespace Microsoft.CodeAnalysis.Remote.Razor;
1817

@@ -24,15 +23,15 @@ protected override IRemoteWrapWithTagService CreateService(in ServiceArgs args)
2423
=> new RemoteWrapWithTagService(in args);
2524
}
2625

27-
public ValueTask<Response> IsValidWrapWithTagLocationAsync(
26+
public ValueTask<Response> GetValidWrappingRangeAsync(
2827
RazorPinnedSolutionInfoWrapper solutionInfo,
2928
DocumentId razorDocumentId,
3029
LinePositionSpan range,
3130
CancellationToken cancellationToken)
3231
=> RunServiceAsync(
3332
solutionInfo,
3433
razorDocumentId,
35-
context => IsValidWrapWithTagLocationAsync(context, range, cancellationToken),
34+
context => GetValidWrappingRangeAsync(context, range, cancellationToken),
3635
cancellationToken);
3736

3837
public ValueTask<TextEditResponse> FixHtmlTextEditsAsync(
@@ -46,14 +45,18 @@ public ValueTask<TextEditResponse> FixHtmlTextEditsAsync(
4645
context => FixHtmlTextEditsAsync(context, textEdits, cancellationToken),
4746
cancellationToken);
4847

49-
private async ValueTask<Response> IsValidWrapWithTagLocationAsync(
48+
private async ValueTask<Response> GetValidWrappingRangeAsync(
5049
RemoteDocumentContext context,
5150
LinePositionSpan range,
5251
CancellationToken cancellationToken)
5352
{
5453
var codeDocument = await context.GetCodeDocumentAsync(cancellationToken).ConfigureAwait(false);
55-
var isValid = WrapWithTagHelper.TryGetValidWrappingRange(codeDocument, range, out var adjustedRange);
56-
return Response.Results(isValid);
54+
if (WrapWithTagHelper.TryGetValidWrappingRange(codeDocument, range, out var adjustedRange))
55+
{
56+
return Response.Results(adjustedRange);
57+
}
58+
59+
return Response.NoFurtherHandling;
5760
}
5861

5962
private async ValueTask<TextEditResponse> FixHtmlTextEditsAsync(
@@ -72,4 +75,4 @@ private async ValueTask<TextEditResponse> FixHtmlTextEditsAsync(
7275
var fixedEdits = FormattingUtilities.FixHtmlTextEdits(htmlSourceText, textEdits);
7376
return TextEditResponse.Results(fixedEdits);
7477
}
75-
}
78+
}

src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostWrapWithTagEndpoint.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Collections.Immutable;
54
using System.Composition;
65
using System.Threading;
76
using System.Threading.Tasks;
7+
using Microsoft.AspNetCore.Razor;
88
using Microsoft.CodeAnalysis;
99
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost;
10-
using Microsoft.CodeAnalysis.Razor.Formatting;
1110
using Microsoft.CodeAnalysis.Razor.Protocol;
1211
using Microsoft.CodeAnalysis.Razor.Remote;
13-
using Microsoft.CodeAnalysis.Razor.Workspaces;
1412
using Microsoft.CodeAnalysis.Text;
1513
using Microsoft.VisualStudio.Razor.LanguageClient.WrapWithTag;
16-
using Roslyn.LanguageServer.Protocol;
1714

1815
namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
1916

@@ -25,12 +22,10 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
2522
#pragma warning restore RS0030 // Do not use banned APIs
2623
internal sealed class CohostWrapWithTagEndpoint(
2724
IRemoteServiceInvoker remoteServiceInvoker,
28-
IFilePathService filePathService,
2925
IHtmlRequestInvoker requestInvoker)
3026
: AbstractRazorCohostDocumentRequestHandler<VSInternalWrapWithTagParams, VSInternalWrapWithTagResponse?>
3127
{
3228
private readonly IRemoteServiceInvoker _remoteServiceInvoker = remoteServiceInvoker;
33-
private readonly IFilePathService _filePathService = filePathService;
3429
private readonly IHtmlRequestInvoker _requestInvoker = requestInvoker;
3530

3631
protected override bool MutatesSolutionState => false;
@@ -47,17 +42,19 @@ internal sealed class CohostWrapWithTagEndpoint(
4742
{
4843
// First, check if the position is valid for wrap with tag operation through the remote service
4944
var range = request.Range.ToLinePositionSpan();
50-
var isValidLocation = await _remoteServiceInvoker.TryInvokeAsync<IRemoteWrapWithTagService, RemoteResponse<bool>>(
45+
var result = await _remoteServiceInvoker.TryInvokeAsync<IRemoteWrapWithTagService, RemoteResponse<LinePositionSpan>>(
5146
razorDocument.Project.Solution,
52-
(service, solutionInfo, cancellationToken) => service.IsValidWrapWithTagLocationAsync(solutionInfo, razorDocument.Id, range, cancellationToken),
47+
(service, solutionInfo, cancellationToken) => service.GetValidWrappingRangeAsync(solutionInfo, razorDocument.Id, range, cancellationToken),
5348
cancellationToken).ConfigureAwait(false);
5449

5550
// If the remote service says it's not a valid location or we should stop handling, return null
56-
if (!isValidLocation.Result || isValidLocation.StopHandling)
51+
if (result.StopHandling)
5752
{
5853
return null;
5954
}
6055

56+
request.Range = result.Result.ToRange();
57+
6158
// The location is valid, so delegate to the HTML server
6259
var htmlResponse = await _requestInvoker.MakeHtmlLspRequestAsync<VSInternalWrapWithTagParams, VSInternalWrapWithTagResponse>(
6360
razorDocument,
@@ -89,4 +86,4 @@ internal readonly struct TestAccessor(CohostWrapWithTagEndpoint instance)
8986
public Task<VSInternalWrapWithTagResponse?> HandleRequestAsync(VSInternalWrapWithTagParams request, TextDocument razorDocument, CancellationToken cancellationToken)
9087
=> instance.HandleRequestAsync(request, razorDocument, cancellationToken);
9188
}
92-
}
89+
}

0 commit comments

Comments
 (0)