diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostFindAllReferencesEndpoint.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/FindAllReferences/CohostFindAllReferencesEndpoint.cs similarity index 96% rename from src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostFindAllReferencesEndpoint.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/FindAllReferences/CohostFindAllReferencesEndpoint.cs index 44c3800f945..0903272ee42 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostFindAllReferencesEndpoint.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/FindAllReferences/CohostFindAllReferencesEndpoint.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Razor; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; +using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features; using Microsoft.CodeAnalysis.Razor.Remote; namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost; @@ -16,7 +17,7 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost; [Shared] [CohostEndpoint(Methods.TextDocumentReferencesName)] [Export(typeof(IDynamicRegistrationProvider))] -[ExportCohostStatelessLspService(typeof(CohostFindAllReferencesEndpoint))] +[ExportRazorStatelessLspService(typeof(CohostFindAllReferencesEndpoint))] [method: ImportingConstructor] #pragma warning restore RS0030 // Do not use banned APIs internal sealed class CohostFindAllReferencesEndpoint( diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostDocumentFormattingEndpoint.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Formatting/CohostDocumentFormattingEndpoint.cs similarity index 96% rename from src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostDocumentFormattingEndpoint.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Formatting/CohostDocumentFormattingEndpoint.cs index 68067656011..2143bde024a 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostDocumentFormattingEndpoint.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Formatting/CohostDocumentFormattingEndpoint.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Razor; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; +using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Remote; @@ -22,7 +23,7 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost; [Shared] [CohostEndpoint(Methods.TextDocumentFormattingName)] [Export(typeof(IDynamicRegistrationProvider))] -[ExportCohostStatelessLspService(typeof(CohostDocumentFormattingEndpoint))] +[ExportRazorStatelessLspService(typeof(CohostDocumentFormattingEndpoint))] [method: ImportingConstructor] #pragma warning restore RS0030 // Do not use banned APIs internal sealed class CohostDocumentFormattingEndpoint( @@ -88,7 +89,7 @@ public ImmutableArray GetRegistrations(VSInternalClientCapabilitie { _logger.LogDebug($"Got a total of {remoteResult.Length} ranges back from OOP"); - return remoteResult.Select(sourceText.GetTextEdit).ToArray(); + return [.. remoteResult.Select(sourceText.GetTextEdit)]; } return null; diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostOnTypeFormattingEndpoint.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Formatting/CohostOnTypeFormattingEndpoint.cs similarity index 97% rename from src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostOnTypeFormattingEndpoint.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Formatting/CohostOnTypeFormattingEndpoint.cs index 16b6f5cc1b2..4c966304a04 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostOnTypeFormattingEndpoint.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Formatting/CohostOnTypeFormattingEndpoint.cs @@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; +using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Remote; @@ -23,7 +24,7 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost; [Shared] [CohostEndpoint(Methods.TextDocumentOnTypeFormattingName)] [Export(typeof(IDynamicRegistrationProvider))] -[ExportCohostStatelessLspService(typeof(CohostOnTypeFormattingEndpoint))] +[ExportRazorStatelessLspService(typeof(CohostOnTypeFormattingEndpoint))] [method: ImportingConstructor] #pragma warning restore RS0030 // Do not use banned APIs internal sealed class CohostOnTypeFormattingEndpoint( @@ -124,7 +125,7 @@ public ImmutableArray GetRegistrations(VSInternalClientCapabilitie { _logger.LogDebug($"Got a total of {remoteResult.Length} ranges back from OOP"); - return remoteResult.Select(sourceText.GetTextEdit).ToArray(); + return [.. remoteResult.Select(sourceText.GetTextEdit)]; } return null; diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostRangeFormattingEndpoint.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Formatting/CohostRangeFormattingEndpoint.cs similarity index 96% rename from src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostRangeFormattingEndpoint.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Formatting/CohostRangeFormattingEndpoint.cs index 89597c10acd..378412d7db2 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostRangeFormattingEndpoint.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Formatting/CohostRangeFormattingEndpoint.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Razor; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; +using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features; using Microsoft.CodeAnalysis.Razor.Formatting; using Microsoft.CodeAnalysis.Razor.Logging; using Microsoft.CodeAnalysis.Razor.Remote; @@ -22,7 +23,7 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost; [Shared] [CohostEndpoint(Methods.TextDocumentRangeFormattingName)] [Export(typeof(IDynamicRegistrationProvider))] -[ExportCohostStatelessLspService(typeof(CohostRangeFormattingEndpoint))] +[ExportRazorStatelessLspService(typeof(CohostRangeFormattingEndpoint))] [method: ImportingConstructor] #pragma warning restore RS0030 // Do not use banned APIs internal sealed class CohostRangeFormattingEndpoint( @@ -96,7 +97,7 @@ public ImmutableArray GetRegistrations(VSInternalClientCapabilitie { _logger.LogDebug($"Got a total of {remoteResult.Length} ranges back from OOP"); - return remoteResult.Select(sourceText.GetTextEdit).ToArray(); + return [.. remoteResult.Select(sourceText.GetTextEdit)]; } return null; diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostLinkedEditingRangeEndpoint.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/LinkedEditingRange/CohostLinkedEditingRangeEndpoint.cs similarity index 93% rename from src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostLinkedEditingRangeEndpoint.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/LinkedEditingRange/CohostLinkedEditingRangeEndpoint.cs index 813a052ab2c..5c10627e17e 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostLinkedEditingRangeEndpoint.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/LinkedEditingRange/CohostLinkedEditingRangeEndpoint.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Razor; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; +using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features; using Microsoft.CodeAnalysis.Razor.LinkedEditingRange; using Microsoft.CodeAnalysis.Razor.Remote; using Microsoft.CodeAnalysis.Razor.Workspaces; @@ -19,10 +20,10 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost; [Shared] [CohostEndpoint(Methods.TextDocumentLinkedEditingRangeName)] [Export(typeof(IDynamicRegistrationProvider))] -[ExportCohostStatelessLspService(typeof(CohostLinkedEditingRangeEndpoint))] +[ExportRazorStatelessLspService(typeof(CohostLinkedEditingRangeEndpoint))] [method: ImportingConstructor] #pragma warning restore RS0030 // Do not use banned APIs -internal class CohostLinkedEditingRangeEndpoint(IRemoteServiceInvoker remoteServiceInvoker) +internal sealed class CohostLinkedEditingRangeEndpoint(IRemoteServiceInvoker remoteServiceInvoker) : AbstractRazorCohostDocumentRequestHandler, IDynamicRegistrationProvider { private readonly IRemoteServiceInvoker _remoteServiceInvoker = remoteServiceInvoker; diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Microsoft.CodeAnalysis.Razor.CohostingShared.projitems b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Microsoft.CodeAnalysis.Razor.CohostingShared.projitems index bee52513a77..48a47c82ac9 100644 --- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Microsoft.CodeAnalysis.Razor.CohostingShared.projitems +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Microsoft.CodeAnalysis.Razor.CohostingShared.projitems @@ -22,6 +22,15 @@ + + + + + + + + + @@ -42,7 +51,4 @@ - - - \ No newline at end of file diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostGoToDefinitionEndpoint.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Navigation/CohostGoToDefinitionEndpoint.cs similarity index 97% rename from src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostGoToDefinitionEndpoint.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Navigation/CohostGoToDefinitionEndpoint.cs index beb891e0462..d750c87df27 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostGoToDefinitionEndpoint.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Navigation/CohostGoToDefinitionEndpoint.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Razor.PooledObjects; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; +using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features; using Microsoft.CodeAnalysis.Razor.Remote; using Microsoft.CodeAnalysis.Razor.Workspaces; @@ -19,7 +20,7 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost; [Shared] [CohostEndpoint(Methods.TextDocumentDefinitionName)] [Export(typeof(IDynamicRegistrationProvider))] -[ExportCohostStatelessLspService(typeof(CohostGoToDefinitionEndpoint))] +[ExportRazorStatelessLspService(typeof(CohostGoToDefinitionEndpoint))] [method: ImportingConstructor] #pragma warning restore RS0030 // Do not use banned APIs internal sealed class CohostGoToDefinitionEndpoint( diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostGoToImplementationEndpoint.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Navigation/CohostGoToImplementationEndpoint.cs similarity index 97% rename from src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostGoToImplementationEndpoint.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Navigation/CohostGoToImplementationEndpoint.cs index 4e6c97b1238..aac48aef424 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostGoToImplementationEndpoint.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Navigation/CohostGoToImplementationEndpoint.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Razor; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; +using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features; using Microsoft.CodeAnalysis.Razor.Remote; using Microsoft.CodeAnalysis.Razor.Workspaces; @@ -17,7 +18,7 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost; [Shared] [CohostEndpoint(Methods.TextDocumentImplementationName)] [Export(typeof(IDynamicRegistrationProvider))] -[ExportCohostStatelessLspService(typeof(CohostGoToImplementationEndpoint))] +[ExportRazorStatelessLspService(typeof(CohostGoToImplementationEndpoint))] [method: ImportingConstructor] #pragma warning restore RS0030 // Do not use banned APIs internal sealed class CohostGoToImplementationEndpoint( diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostRenameEndpoint.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Rename/CohostRenameEndpoint.cs similarity index 96% rename from src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostRenameEndpoint.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Rename/CohostRenameEndpoint.cs index 03d030cc455..04f72d1e914 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostRenameEndpoint.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Rename/CohostRenameEndpoint.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Razor; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; +using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features; using Microsoft.CodeAnalysis.Razor.Remote; namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost; @@ -16,7 +17,7 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost; [Shared] [CohostEndpoint(Methods.TextDocumentRenameName)] [Export(typeof(IDynamicRegistrationProvider))] -[ExportCohostStatelessLspService(typeof(CohostRenameEndpoint))] +[ExportRazorStatelessLspService(typeof(CohostRenameEndpoint))] [method: ImportingConstructor] #pragma warning restore RS0030 // Do not use banned APIs internal sealed class CohostRenameEndpoint( diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostSignatureHelpEndpoint.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SignatureHelp/CohostSignatureHelpEndpoint.cs similarity index 97% rename from src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostSignatureHelpEndpoint.cs rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SignatureHelp/CohostSignatureHelpEndpoint.cs index 05edf8ff394..a643e563229 100644 --- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostSignatureHelpEndpoint.cs +++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/SignatureHelp/CohostSignatureHelpEndpoint.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Razor.LanguageServer.Hosting; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost; +using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features; using Microsoft.CodeAnalysis.Razor.Remote; using Microsoft.CodeAnalysis.Razor.Workspaces.Settings; using Microsoft.VisualStudio.Razor.LanguageClient.Cohost; @@ -19,7 +20,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.LanguageClient.Cohost; [Shared] [CohostEndpoint(Methods.TextDocumentSignatureHelpName)] [Export(typeof(IDynamicRegistrationProvider))] -[ExportCohostStatelessLspService(typeof(CohostSignatureHelpEndpoint))] +[ExportRazorStatelessLspService(typeof(CohostSignatureHelpEndpoint))] [method: ImportingConstructor] #pragma warning restore RS0030 // Do not use banned APIs internal sealed class CohostSignatureHelpEndpoint( diff --git a/src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Services/VSCodeFilePathService.cs b/src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Services/VSCodeFilePathService.cs new file mode 100644 index 00000000000..501f8e1f3a1 --- /dev/null +++ b/src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Services/VSCodeFilePathService.cs @@ -0,0 +1,43 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT license. See License.txt in the project root for license information. + +using System; +using System.Composition; +using Microsoft.CodeAnalysis.ExternalAccess.Razor; +using Microsoft.CodeAnalysis.Razor.Workspaces; + +namespace Microsoft.CodeAnalysis.Remote.Razor; + +[Export(typeof(IFilePathService)), Shared] +[method: ImportingConstructor] +internal sealed class VSCodeFilePathService(LanguageServerFeatureOptions options) : AbstractFilePathService(options) +{ + private readonly LanguageServerFeatureOptions _options = options; + + public override Uri GetRazorDocumentUri(Uri virtualDocumentUri) + { + if (_options.UseRazorCohostServer && IsVirtualCSharpFile(virtualDocumentUri)) + { + throw new InvalidOperationException("Can not get a Razor document from a generated document Uri in cohosting"); + } + + if (virtualDocumentUri.Scheme == "razor-html") + { + var builder = new UriBuilder(virtualDocumentUri); + builder.Scheme = Uri.UriSchemeFile; + return base.GetRazorDocumentUri(builder.Uri); + } + + return base.GetRazorDocumentUri(virtualDocumentUri); + } + + public override bool IsVirtualCSharpFile(Uri uri) + { + if (_options.UseRazorCohostServer) + { + return RazorUri.IsGeneratedDocumentUri(uri); + } + + return base.IsVirtualCSharpFile(uri); + } +}