Skip to content

Commit a33940a

Browse files
committed
Create VS Code file path service
1 parent 120d539 commit a33940a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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;
5+
using System.Composition;
6+
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
7+
using Microsoft.CodeAnalysis.Razor.Workspaces;
8+
9+
namespace Microsoft.CodeAnalysis.Remote.Razor;
10+
11+
[Export(typeof(IFilePathService)), Shared]
12+
[method: ImportingConstructor]
13+
internal sealed class VSCodeFilePathService(LanguageServerFeatureOptions options) : AbstractFilePathService(options)
14+
{
15+
private readonly LanguageServerFeatureOptions _options = options;
16+
17+
public override Uri GetRazorDocumentUri(Uri virtualDocumentUri)
18+
{
19+
if (_options.UseRazorCohostServer && IsVirtualCSharpFile(virtualDocumentUri))
20+
{
21+
throw new InvalidOperationException("Can not get a Razor document from a generated document Uri in cohosting");
22+
}
23+
24+
if (virtualDocumentUri.Scheme == "razor-html")
25+
{
26+
var builder = new UriBuilder(virtualDocumentUri);
27+
builder.Scheme = "file";
28+
return base.GetRazorDocumentUri(builder.Uri);
29+
}
30+
31+
return base.GetRazorDocumentUri(virtualDocumentUri);
32+
}
33+
34+
public override bool IsVirtualCSharpFile(Uri uri)
35+
{
36+
if (_options.UseRazorCohostServer)
37+
{
38+
return RazorUri.IsGeneratedDocumentUri(uri);
39+
}
40+
41+
return base.IsVirtualCSharpFile(uri);
42+
}
43+
}

0 commit comments

Comments
 (0)