Skip to content

Commit 512e5f8

Browse files
authored
Merge pull request #8207 from davidwengier/SendVSInternalTypesToWebTools
2 parents 37311b9 + ab789e6 commit 512e5f8

File tree

14 files changed

+210
-145
lines changed

14 files changed

+210
-145
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ private string GetFileContents(FileTypes fileType)
141141
[Benchmark(Description = "Lightbulbs")]
142142
public async Task RazorLightbulbAsync()
143143
{
144-
var request = new CodeActionParams
144+
var request = new VSCodeActionParams
145145
{
146146
Range = RazorCodeActionRange!,
147147
Context = new VSInternalCodeActionContext(),
148-
TextDocument = new TextDocumentIdentifier
148+
TextDocument = new VSTextDocumentIdentifier
149149
{
150150
Uri = DocumentUri!
151151
},

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public CodeActionEndpoint(
5858
_allAvailableCodeActionNames = GetAllAvailableCodeActionNames();
5959
}
6060

61-
public async Task<SumType<Command, CodeAction>[]?> HandleRequestAsync(CodeActionParams request, RazorRequestContext requestContext, CancellationToken cancellationToken)
61+
public async Task<SumType<Command, CodeAction>[]?> HandleRequestAsync(VSCodeActionParams request, RazorRequestContext requestContext, CancellationToken cancellationToken)
6262
{
6363
if (request is null)
6464
{
@@ -140,7 +140,7 @@ public RegistrationExtensionResult GetRegistration(VSInternalClientCapabilities
140140
}
141141

142142
// internal for testing
143-
internal async Task<RazorCodeActionContext?> GenerateRazorCodeActionContextAsync(CodeActionParams request, DocumentSnapshot documentSnapshot)
143+
internal async Task<RazorCodeActionContext?> GenerateRazorCodeActionContextAsync(VSCodeActionParams request, DocumentSnapshot documentSnapshot)
144144
{
145145
var codeDocument = await documentSnapshot.GetGeneratedOutputAsync().ConfigureAwait(false);
146146
if (codeDocument.IsUnsupported())
@@ -358,7 +358,7 @@ private static ImmutableHashSet<string> GetAllAvailableCodeActionNames()
358358
return availableCodeActionNames.ToImmutableHashSet();
359359
}
360360

361-
public TextDocumentIdentifier GetTextDocumentIdentifier(CodeActionParams request)
361+
public TextDocumentIdentifier GetTextDocumentIdentifier(VSCodeActionParams request)
362362
{
363363
return request.TextDocument;
364364
}

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/DelegatedCodeActionParams.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Licensed under the MIT license. See License.txt in the project root for license information.
33

44
using System.Runtime.Serialization;
5+
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
56
using Microsoft.AspNetCore.Razor.LanguageServer.Protocol;
6-
using Microsoft.VisualStudio.LanguageServer.Protocol;
77

88
namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;
99

@@ -14,7 +14,7 @@ internal class DelegatedCodeActionParams
1414
public int HostDocumentVersion { get; set; }
1515

1616
[DataMember(Name = "codeActionParams")]
17-
public required CodeActionParams CodeActionParams { get; set; }
17+
public required VSCodeActionParams CodeActionParams { get; set; }
1818

1919
[DataMember(Name = "languageKind")]
2020
public RazorLanguageKind LanguageKind { get; set; }

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/RazorCodeActionContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33

44
using System;
55
using Microsoft.AspNetCore.Razor.Language;
6+
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
67
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
78
using Microsoft.CodeAnalysis.Text;
8-
using Microsoft.VisualStudio.LanguageServer.Protocol;
99

1010
namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;
1111

1212
internal sealed class RazorCodeActionContext
1313
{
1414
public RazorCodeActionContext(
15-
CodeActionParams request,
15+
VSCodeActionParams request,
1616
DocumentSnapshot documentSnapshot,
1717
RazorCodeDocument codeDocument,
1818
SourceLocation location,
@@ -29,7 +29,7 @@ public RazorCodeActionContext(
2929
SupportsCodeActionResolve = supportsCodeActionResolve;
3030
}
3131

32-
public CodeActionParams Request { get; }
32+
public VSCodeActionParams Request { get; }
3333
public DocumentSnapshot DocumentSnapshot { get; }
3434
public RazorCodeDocument CodeDocument { get; }
3535
public SourceLocation Location { get; }

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/EndpointContracts/IVSCodeActionEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
namespace Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
88

99
[LanguageServerEndpoint(Methods.TextDocumentCodeActionName)]
10-
internal interface IVSCodeActionEndpoint : IRazorRequestHandler<CodeActionParams, SumType<Command, CodeAction>[]?>, IRegistrationExtension
10+
internal interface IVSCodeActionEndpoint : IRazorRequestHandler<VSCodeActionParams, SumType<Command, CodeAction>[]?>, IRegistrationExtension
1111
{
1212
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT license. See License.txt in the project root for license information.
3+
4+
using System.Runtime.Serialization;
5+
using Microsoft.VisualStudio.LanguageServer.Protocol;
6+
7+
namespace Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
8+
9+
/// <summary>
10+
/// We can't use the CodeActionParams defined in MS.VS.LS.Protocol, so need our own version, because the platform only
11+
/// converts on read, not write. ie, if it gets a request for a CodeActionParams, it will happily deserialize the Context
12+
/// property to VSInternalCodeActionContext, but in our case we need to send a request to our CustomMessageTarget, and so
13+
/// we need the Context property serialized as the internal type.
14+
/// </summary>
15+
[DataContract]
16+
internal class VSCodeActionParams
17+
{
18+
//
19+
// Summary:
20+
// Gets or sets the document identifier indicating where the command was invoked.
21+
[DataMember(Name = "textDocument")]
22+
public required VSTextDocumentIdentifier TextDocument { get; set; }
23+
24+
//
25+
// Summary:
26+
// Gets or sets the range in the document for which the command was invoked.
27+
[DataMember(Name = "range")]
28+
public required Range Range { get; set; }
29+
30+
//
31+
// Summary:
32+
// Gets or sets the additional diagnostic information about the code action context.
33+
[DataMember(Name = "context")]
34+
public required VSInternalCodeActionContext Context { get; set; }
35+
}

src/Razor/src/Microsoft.VisualStudio.LanguageServerClient.Razor/DefaultRazorLanguageServerCustomMessageTarget.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
using System.Threading;
1111
using System.Threading.Tasks;
1212
using Microsoft.AspNetCore.Razor.LanguageServer;
13-
using Microsoft.AspNetCore.Razor.LanguageServer.ColorPresentation;
1413
using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions;
1514
using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;
15+
using Microsoft.AspNetCore.Razor.LanguageServer.ColorPresentation;
1616
using Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics;
1717
using Microsoft.AspNetCore.Razor.LanguageServer.DocumentColor;
1818
using Microsoft.AspNetCore.Razor.LanguageServer.DocumentPresentation;
19+
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
1920
using Microsoft.AspNetCore.Razor.LanguageServer.Folding;
2021
using Microsoft.AspNetCore.Razor.LanguageServer.Formatting;
2122
using Microsoft.AspNetCore.Razor.LanguageServer.Protocol;
@@ -346,7 +347,7 @@ public override async Task<RazorDocumentRangeFormattingResponse> RazorRangeForma
346347
codeActionParams.CodeActionParams.TextDocument.Uri = virtualDocumentSnapshot.Uri;
347348

348349
var textBuffer = virtualDocumentSnapshot.Snapshot.TextBuffer;
349-
var requests = _requestInvoker.ReinvokeRequestOnMultipleServersAsync<CodeActionParams, IReadOnlyList<VSInternalCodeAction>>(
350+
var requests = _requestInvoker.ReinvokeRequestOnMultipleServersAsync<VSCodeActionParams, IReadOnlyList<VSInternalCodeAction>>(
350351
textBuffer,
351352
Methods.TextDocumentCodeActionName,
352353
SupportsCodeActionResolve,

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/DefaultCSharpCodeActionProviderTest.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading.Tasks;
77
using Microsoft.AspNetCore.Razor.Language;
88
using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;
9+
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
910
using Microsoft.AspNetCore.Razor.LanguageServer.Extensions;
1011
using Microsoft.AspNetCore.Razor.Test.Common;
1112
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
@@ -46,11 +47,11 @@ public async Task ProvideAsync_ValidCodeActions_ReturnsProvidedCodeAction()
4647
var contents = "@code { $$Path; }";
4748
TestFileMarkupParser.GetPosition(contents, out contents, out var cursorPosition);
4849

49-
var request = new CodeActionParams()
50+
var request = new VSCodeActionParams()
5051
{
51-
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
52+
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
5253
Range = new Range(),
53-
Context = new CodeActionContext()
54+
Context = new VSInternalCodeActionContext()
5455
};
5556

5657
var location = new SourceLocation(cursorPosition, -1, -1);
@@ -78,11 +79,11 @@ public async Task ProvideAsync_SupportsCodeActionResolveFalse_ValidCodeActions_R
7879
var contents = "@code { $$Path; }";
7980
TestFileMarkupParser.GetPosition(contents, out contents, out var cursorPosition);
8081

81-
var request = new CodeActionParams()
82+
var request = new VSCodeActionParams()
8283
{
83-
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
84+
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
8485
Range = new Range(),
85-
Context = new CodeActionContext()
86+
Context = new VSInternalCodeActionContext()
8687
};
8788

8889
var location = new SourceLocation(cursorPosition, -1, -1);
@@ -107,11 +108,11 @@ public async Task ProvideAsync_FunctionsBlock_SingleLine_ValidCodeActions_Return
107108
var contents = "@functions { $$Path; }";
108109
TestFileMarkupParser.GetPosition(contents, out contents, out var cursorPosition);
109110

110-
var request = new CodeActionParams()
111+
var request = new VSCodeActionParams()
111112
{
112-
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
113+
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
113114
Range = new Range(),
114-
Context = new CodeActionContext()
115+
Context = new VSInternalCodeActionContext()
115116
};
116117

117118
var location = new SourceLocation(cursorPosition, -1, -1);
@@ -141,11 +142,11 @@ public async Task ProvideAsync_FunctionsBlock_OpenBraceSameLine_ValidCodeActions
141142
}";
142143
TestFileMarkupParser.GetPosition(contents, out contents, out var cursorPosition);
143144

144-
var request = new CodeActionParams()
145+
var request = new VSCodeActionParams()
145146
{
146-
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
147+
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
147148
Range = new Range(),
148-
Context = new CodeActionContext()
149+
Context = new VSInternalCodeActionContext()
149150
};
150151

151152
var location = new SourceLocation(cursorPosition, -1, -1);
@@ -176,11 +177,11 @@ public async Task ProvideAsync_FunctionsBlock_OpenBraceNextLine_ValidCodeActions
176177
}";
177178
TestFileMarkupParser.GetPosition(contents, out contents, out var cursorPosition);
178179

179-
var request = new CodeActionParams()
180+
var request = new VSCodeActionParams()
180181
{
181-
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
182+
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
182183
Range = new Range(),
183-
Context = new CodeActionContext()
184+
Context = new VSInternalCodeActionContext()
184185
};
185186

186187
var location = new SourceLocation(cursorPosition, -1, -1);
@@ -208,11 +209,11 @@ public async Task ProvideAsync_InvalidCodeActions_ReturnsNoCodeActions()
208209
var contents = "@code { $$Path; }";
209210
TestFileMarkupParser.GetPosition(contents, out contents, out var cursorPosition);
210211

211-
var request = new CodeActionParams()
212+
var request = new VSCodeActionParams()
212213
{
213-
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
214+
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
214215
Range = new Range(),
215-
Context = new CodeActionContext()
216+
Context = new VSInternalCodeActionContext()
216217
};
217218

218219
var location = new SourceLocation(cursorPosition, -1, -1);
@@ -254,11 +255,11 @@ public async Task ProvideAsync_ImplicitExpression_ReturnsProvidedCodeAction()
254255
""";
255256
TestFileMarkupParser.GetPosition(contents, out contents, out var cursorPosition);
256257

257-
var request = new CodeActionParams()
258+
var request = new VSCodeActionParams()
258259
{
259-
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
260+
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
260261
Range = new Range(),
261-
Context = new CodeActionContext()
262+
Context = new VSInternalCodeActionContext()
262263
};
263264

264265
var location = new SourceLocation(cursorPosition, -1, -1);
@@ -279,7 +280,7 @@ public async Task ProvideAsync_ImplicitExpression_ReturnsProvidedCodeAction()
279280
}
280281

281282
private static RazorCodeActionContext CreateRazorCodeActionContext(
282-
CodeActionParams request,
283+
VSCodeActionParams request,
283284
SourceLocation location,
284285
string filePath,
285286
string text,

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/CSharp/TypeAccessibilityCodeActionProviderTest.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.AspNetCore.Razor.Language.Components;
99
using Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;
1010
using Microsoft.AspNetCore.Razor.LanguageServer.Common;
11+
using Microsoft.AspNetCore.Razor.LanguageServer.EndpointContracts;
1112
using Microsoft.AspNetCore.Razor.Test.Common;
1213
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
1314
using Microsoft.CodeAnalysis.Razor.Workspaces.Extensions;
@@ -33,11 +34,11 @@ public async Task Handle_MissingDiagnostics_ReturnsEmpty()
3334
// Arrange
3435
var documentPath = "c:/Test.razor";
3536
var contents = "";
36-
var request = new CodeActionParams()
37+
var request = new VSCodeActionParams()
3738
{
38-
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
39+
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
3940
Range = new Range(),
40-
Context = new CodeActionContext()
41+
Context = new VSInternalCodeActionContext()
4142
{
4243
// Even though the DTO declares this as non-null, we want to make sure we behave
4344
Diagnostics = null!
@@ -70,11 +71,11 @@ public async Task Handle_InvalidDiagnostics_VSCode_ReturnsEmpty()
7071
// Arrange
7172
var documentPath = "c:/Test.razor";
7273
var contents = "";
73-
var request = new CodeActionParams()
74+
var request = new VSCodeActionParams()
7475
{
75-
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
76+
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
7677
Range = new Range(),
77-
Context = new CodeActionContext()
78+
Context = new VSInternalCodeActionContext()
7879
{
7980
Diagnostics = new Diagnostic[] {
8081
new Diagnostic()
@@ -126,11 +127,11 @@ public async Task Handle_EmptyCodeActions_ReturnsEmpty()
126127
// Arrange
127128
var documentPath = "c:/Test.razor";
128129
var contents = "";
129-
var request = new CodeActionParams()
130+
var request = new VSCodeActionParams()
130131
{
131-
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
132+
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
132133
Range = new Range(),
133-
Context = new CodeActionContext()
134+
Context = new VSInternalCodeActionContext()
134135
{
135136
Diagnostics = new Diagnostic[] {
136137
new Diagnostic()
@@ -167,11 +168,11 @@ public async Task Handle_ValidDiagnostic_ValidCodeAction_VSCode_ReturnsCodeActio
167168
// Arrange
168169
var documentPath = "c:/Test.razor";
169170
var contents = "@code { Path; }";
170-
var request = new CodeActionParams()
171+
var request = new VSCodeActionParams()
171172
{
172-
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
173+
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
173174
Range = new Range(),
174-
Context = new CodeActionContext()
175+
Context = new VSInternalCodeActionContext()
175176
{
176177
Diagnostics = new Diagnostic[] {
177178
new Diagnostic()
@@ -246,11 +247,11 @@ public async Task Handle_CodeActionInSingleLineDirective_VS_ReturnsOnlyUsingCode
246247
// Arrange
247248
var documentPath = "c:/Test.razor";
248249
var contents = "@inject Path";
249-
var request = new CodeActionParams()
250+
var request = new VSCodeActionParams()
250251
{
251-
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
252+
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
252253
Range = new Range(),
253-
Context = new CodeActionContext()
254+
Context = new VSInternalCodeActionContext()
254255
{
255256
Diagnostics = Array.Empty<Diagnostic>()
256257
}
@@ -298,11 +299,11 @@ public async Task Handle_ValidCodeAction_VS_ReturnsCodeActions()
298299
// Arrange
299300
var documentPath = "c:/Test.razor";
300301
var contents = "@code { Path; }";
301-
var request = new CodeActionParams()
302+
var request = new VSCodeActionParams()
302303
{
303-
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
304+
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
304305
Range = new Range(),
305-
Context = new CodeActionContext()
306+
Context = new VSInternalCodeActionContext()
306307
{
307308
Diagnostics = Array.Empty<Diagnostic>()
308309
}
@@ -356,11 +357,11 @@ public async Task Handle_ValidDiagnostic_MultipleValidCodeActions_VSCode_Returns
356357
// Arrange
357358
var documentPath = "c:/Test.razor";
358359
var contents = "@code { Path; }";
359-
var request = new CodeActionParams()
360+
var request = new VSCodeActionParams()
360361
{
361-
TextDocument = new TextDocumentIdentifier { Uri = new Uri(documentPath) },
362+
TextDocument = new VSTextDocumentIdentifier { Uri = new Uri(documentPath) },
362363
Range = new Range(),
363-
Context = new CodeActionContext()
364+
Context = new VSInternalCodeActionContext()
364365
{
365366
Diagnostics = new Diagnostic[] {
366367
new Diagnostic()
@@ -444,7 +445,7 @@ public async Task Handle_ValidDiagnostic_MultipleValidCodeActions_VSCode_Returns
444445
}
445446

446447
private static RazorCodeActionContext CreateRazorCodeActionContext(
447-
CodeActionParams request,
448+
VSCodeActionParams request,
448449
SourceLocation location,
449450
string filePath,
450451
string text,

0 commit comments

Comments
 (0)