Skip to content

Commit 03e44de

Browse files
Copilotdavidwengier
andcommitted
Fix compilation issues - add missing using statements, fix DocumentUri initialization, add SyntaxNode alias, fix test method calls, extract ShowSerializedTagHelpers_Cohost method
Co-authored-by: davidwengier <754264+davidwengier@users.noreply.github.com>
1 parent 47f13f0 commit 03e44de

File tree

7 files changed

+56
-38
lines changed

7 files changed

+56
-38
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/DevTools/CohostGeneratedDocumentContentsEndpoint.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Threading.Tasks;
88
using Microsoft.CodeAnalysis;
99
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost;
10+
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features;
1011
using Microsoft.CodeAnalysis.Razor.Cohost;
1112
using Microsoft.CodeAnalysis.Razor.Protocol.DevTools;
1213
using Microsoft.CodeAnalysis.Razor.Remote;

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/DevTools/CohostSyntaxTreeEndpoint.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading.Tasks;
77
using Microsoft.CodeAnalysis;
88
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost;
9+
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features;
910
using Microsoft.CodeAnalysis.Razor.Cohost;
1011
using Microsoft.CodeAnalysis.Razor.Protocol.DevTools;
1112
using Microsoft.CodeAnalysis.Razor.Remote;

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/DevTools/CohostTagHelpersEndpoint.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.AspNetCore.Razor.Language;
1010
using Microsoft.CodeAnalysis;
1111
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost;
12+
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features;
1213
using Microsoft.CodeAnalysis.Razor.Cohost;
1314
using Microsoft.CodeAnalysis.Razor.Protocol.DevTools;
1415
using Microsoft.CodeAnalysis.Razor.Remote;

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Protocol/DevTools/DocumentContentsRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static DocumentContentsRequest Create(Uri hostDocumentUri, GeneratedDocum
1818
{
1919
return new DocumentContentsRequest
2020
{
21-
TextDocument = new TextDocumentIdentifier { DocumentUri = hostDocumentUri },
21+
TextDocument = new TextDocumentIdentifier { DocumentUri = new(hostDocumentUri) },
2222
Kind = kind
2323
};
2424
}

src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DevTools/RemoteDevToolsService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
namespace Microsoft.CodeAnalysis.Remote.Razor;
1818

19+
using SyntaxNode = Microsoft.AspNetCore.Razor.Language.Syntax.SyntaxNode;
20+
1921
internal sealed class RemoteDevToolsService(in ServiceArgs args) : RazorDocumentServiceBase(in args), IRemoteDevToolsService
2022
{
2123
internal sealed class Factory : FactoryBase<IRemoteDevToolsService>

src/Razor/src/Microsoft.VisualStudio.RazorExtension/SyntaxVisualizer/SyntaxVisualizerControl.xaml.cs

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,50 @@ private bool ShowGeneratedCode_Cohost(ITextBuffer textBuffer, Uri hostDocumentUr
241241
return false;
242242
}
243243

244+
private bool ShowSerializedTagHelpers_Cohost(ITextBuffer textBuffer, Uri hostDocumentUri, TagHelperDisplayMode displayKind)
245+
{
246+
EnsureInitialized();
247+
248+
var tagHelpersKind = displayKind switch
249+
{
250+
TagHelperDisplayMode.All => TagHelpersKind.All,
251+
TagHelperDisplayMode.InScope => TagHelpersKind.InScope,
252+
TagHelperDisplayMode.Referenced => TagHelpersKind.Referenced,
253+
_ => TagHelpersKind.All
254+
};
255+
256+
var request = TagHelpersRequest.Create(hostDocumentUri, tagHelpersKind);
257+
258+
var response = _joinableTaskFactory.Run(async () =>
259+
{
260+
var lspResponse = await _lspRequestInvoker.ReinvokeRequestOnServerAsync<TagHelpersRequest, string>(
261+
textBuffer,
262+
"razor/tagHelpers",
263+
RazorLSPConstants.RoslynLanguageServerName,
264+
request,
265+
CancellationToken.None);
266+
267+
return lspResponse?.Response;
268+
});
269+
270+
if (response != null)
271+
{
272+
var tempFileName = GetTempFileName(displayKind.ToString() + "TagHelpers.json");
273+
try
274+
{
275+
File.WriteAllText(tempFileName, response);
276+
VsShellUtilities.OpenDocument(ServiceProvider.GlobalProvider, tempFileName);
277+
return true;
278+
}
279+
catch
280+
{
281+
// Fall through to legacy method
282+
}
283+
}
284+
285+
return false;
286+
}
287+
244288
public void ShowSerializedTagHelpers(TagHelperDisplayMode displayKind)
245289
{
246290
ThreadHelper.ThrowIfNotOnUIThread();
@@ -251,41 +295,9 @@ public void ShowSerializedTagHelpers(TagHelperDisplayMode displayKind)
251295
{
252296
if (_fileUriProvider.TryGet(_activeWpfTextView.TextBuffer, out var hostDocumentUri))
253297
{
254-
var tagHelpersKind = displayKind switch
298+
if (ShowSerializedTagHelpers_Cohost(_activeWpfTextView.TextBuffer, hostDocumentUri, displayKind))
255299
{
256-
TagHelperDisplayMode.All => TagHelpersKind.All,
257-
TagHelperDisplayMode.InScope => TagHelpersKind.InScope,
258-
TagHelperDisplayMode.Referenced => TagHelpersKind.Referenced,
259-
_ => TagHelpersKind.All
260-
};
261-
262-
var request = TagHelpersRequest.Create(hostDocumentUri, tagHelpersKind);
263-
264-
var response = _joinableTaskFactory.Run(async () =>
265-
{
266-
var lspResponse = await _lspRequestInvoker.ReinvokeRequestOnServerAsync<TagHelpersRequest, string>(
267-
_activeWpfTextView.TextBuffer,
268-
"razor/tagHelpers",
269-
RazorLSPConstants.RoslynLanguageServerName,
270-
request,
271-
CancellationToken.None);
272-
273-
return lspResponse?.Response;
274-
});
275-
276-
if (response != null)
277-
{
278-
var tempFileName = GetTempFileName(displayKind.ToString() + "TagHelpers.json");
279-
try
280-
{
281-
File.WriteAllText(tempFileName, response);
282-
VsShellUtilities.OpenDocument(ServiceProvider.GlobalProvider, tempFileName);
283-
return;
284-
}
285-
catch
286-
{
287-
// Fall through to legacy method
288-
}
300+
return;
289301
}
290302
}
291303
}

src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/Shared/CohostDevToolsEndpointTest.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text.Json;
55
using System.Threading.Tasks;
66
using Microsoft.AspNetCore.Razor;
7+
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
78
using Microsoft.CodeAnalysis.Razor.Protocol.DevTools;
89
using Microsoft.CodeAnalysis.Testing;
910
using Roslyn.LanguageServer.Protocol;
@@ -61,7 +62,7 @@ public async Task GetTagHelpers_ReturnsJson()
6162
<div>Test content</div>
6263
""";
6364

64-
var razorDocument = await CreateDocumentAsync(input);
65+
var razorDocument = CreateProjectAndRazorDocument(input);
6566
var endpoint = new CohostTagHelpersEndpoint(IncompatibleProjectService, RemoteServiceInvoker);
6667

6768
var request = new TagHelpersRequest
@@ -90,7 +91,7 @@ public async Task GetSyntaxTree_ReturnsTree()
9091
<div>@message</div>
9192
""";
9293

93-
var razorDocument = await CreateDocumentAsync(input);
94+
var razorDocument = CreateProjectAndRazorDocument(input);
9495
var endpoint = new CohostSyntaxTreeEndpoint(IncompatibleProjectService, RemoteServiceInvoker);
9596

9697
var request = new SyntaxTreeRequest
@@ -109,7 +110,7 @@ public async Task GetSyntaxTree_ReturnsTree()
109110

110111
private async Task VerifyGeneratedDocumentContentsAsync(string input, GeneratedDocumentKind kind, string expectedContentSubstring, string expectedFileExtension)
111112
{
112-
var razorDocument = await CreateDocumentAsync(input);
113+
var razorDocument = CreateProjectAndRazorDocument(input);
113114
var endpoint = new CohostGeneratedDocumentContentsEndpoint(IncompatibleProjectService, RemoteServiceInvoker);
114115

115116
var request = new DocumentContentsRequest

0 commit comments

Comments
 (0)