Skip to content

Move Razor to DocumentUri - #84370

Merged
davidwengier merged 15 commits into
dotnet:features/sonicfrom
davidwengier:DocumentUri
Jul 10, 2026
Merged

Move Razor to DocumentUri#84370
davidwengier merged 15 commits into
dotnet:features/sonicfrom
davidwengier:DocumentUri

Conversation

@davidwengier

@davidwengier davidwengier commented Jul 2, 2026

Copy link
Copy Markdown
Member

Not 100% on DocumentUri, because we still use Uri for specific things, like parsing generated document Uris to find which generator produced it, but this is most of it.

Build is failing locally for strange reasons, so I might have missed a using directive or something.

Microsoft Reviewers: Open in CodeFlow

…o Remote.Razor

This includes moving one method in DelegatedCompletionHandler to remote, since it used the interface, and only had one caller, and combines all of the IDocumentMappingService extensions into one set
This was started with the various extension methods, and following the virality of those changes. Next commits will be mop-ups for anything missed.
@davidwengier
davidwengier requested a review from a team as a code owner July 2, 2026 00:15
Copilot AI review requested due to automatic review settings July 2, 2026 00:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates Razor’s LSP plumbing from System.Uri usage toward Roslyn.LanguageServer.Protocol.DocumentUri, aligning more of the Razor cohost/remote pipeline with the LSP protocol’s URI type and updating document-mapping and code-action flows accordingly.

Changes:

  • Switches many Razor remote/cohost service paths (mapping, navigation, diagnostics, completion, etc.) to pass DocumentUri instead of Uri, reducing conversions via GetRequiredSystemUri() / CreateDocumentUriFromSystemUri().
  • Moves/retargets Razor document-mapping helpers into the remote layer (Microsoft.CodeAnalysis.Remote.Razor.DocumentMapping) and updates callers accordingly.
  • Refactors Roslyn code-action helper usage by removing the MEF-exported IRoslynCodeActionHelpers and using a static helper instead.

Reviewed changes

Copilot reviewed 74 out of 74 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Razor/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.UnitTests/Cohost/CohostRoslynRenameTest.cs Updates mapping namespace import for tests.
src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.UnitTests/DocumentUriExtensionsTest.cs Updates assertions for DocumentUri access patterns.
src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.UnitTests/RazorDocumentMappingServiceTest.cs Removes old mapping namespace import in tests.
src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.UnitTests/Formatting/HtmlFormattingPassTest.cs Switches test import to remote mapping namespace.
src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.UnitTests/DocumentExcerpt/RazorDocumentExcerptServiceTest.cs Switches test import to remote mapping namespace.
src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.UnitTests/AutoInsert/PreferHtmlInAttributeValuesDocumentPositionInfoStrategyTest.cs Removes old mapping namespace import in tests.
src/Razor/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Debugging/RazorProximityExpressionResolver.cs Simplifies cache key to cohost-only form; uses DocumentId/VersionStamp key.
src/Razor/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Debugging/RazorBreakpointResolver.cs Simplifies cache key to cohost-only form; uses DocumentId/VersionStamp key.
src/Razor/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostUriPresentationEndpoint.cs Uses DocumentUri directly when remapping virtual HTML URIs.
src/Razor/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostTextPresentationEndpoint.cs Uses DocumentUri directly when remapping virtual HTML URIs.
src/Razor/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostDocumentPullDiagnosticsEndpoint.cs Switches HTML diagnostics params creation to DocumentUri.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/TypeHierarchy/RemoteTypeHierarchyService.cs Switches type hierarchy mapping/identity resolution to DocumentUri.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/SpellCheck/SpellCheckService.cs Switches mapping import to remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/SignatureHelp/RemoteSignatureHelpService.cs Switches mapping import to remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/SemanticTokens/RazorSemanticTokensInfoService.cs Switches mapping import to remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/SelectionRanges/RemoteSelectionRangeService.cs Adds remote mapping import to support DocumentUri-based mapping.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Rename/RemoteRenameService.cs Removes old mapping import to align with remote mapping location.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/RemoteSnapshotManager.cs Updates generated-document lookup APIs to accept DocumentUri.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/ProjectSystem/Extensions.cs Updates “get Razor document URI” helper to return DocumentUri.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/NestedFiles/RemoteAddNestedFileService.cs Switches formatting helper usage to DocumentUri/path-based APIs.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/InlineCompletion/RemoteInlineCompletionService.cs Updates inline completion request info to carry DocumentUri.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Hover/RemoteHoverService.cs Removes old mapping import, relying on remote mapping.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/GoToImplementation/RemoteGoToImplementationService.cs Uses DocumentUri in location mapping + de-duplication.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/GoToDefinition/RemoteGoToDefinitionService.cs Uses DocumentUri in location mapping + de-duplication.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/GoToDefinition/RazorComponentDefinitionHelpers.cs Switches mapping import to remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/GoToDefinition/DefinitionService.cs Adds remote mapping import for updated mapping usage.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/RemoteFormattingService.cs Switches mapping import to remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/RazorFormattingService.cs Removes old mapping import to align with remote mapping.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/Passes/HtmlFormattingPass.cs Switches mapping import to remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/Passes/CSharpOnTypeFormattingPass.cs Removes old mapping import to align with remote mapping.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/Passes/CSharpFormattingPass.CSharpDocumentGenerator.cs Switches mapping import to remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Formatting/Passes/CSharpFormattingPass.cs Switches mapping import to remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/FoldingRanges/FoldingRangeService.cs Switches mapping import to remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/FindAllReferences/RemoteFindAllReferencesService.cs Uses DocumentUri for mapping + display-path adjustment.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DocumentSymbols/DocumentSymbolService.cs Switches mapping import to remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DocumentMapping/RazorEditService.cs Removes old mapping import; aligns with remote mapping layer.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DocumentMapping/RazorEditService_WorkspaceEdit.cs Converts workspace-edit remapping to DocumentUri.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DocumentMapping/MappingBehavior.cs Moves mapping behavior enum into remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DocumentMapping/IDocumentMappingServiceExtensions.cs Hosts mapping extension helpers in remote mapping namespace; updates MapToHost... signature to DocumentUri.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DocumentMapping/IDocumentMappingService.cs Updates mapping service interface to include DocumentUri mapping API.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DocumentMapping/DocumentMappingService.cs Implements DocumentUri mapping flow and TryGetSourceGeneratedDocumentIdentity(DocumentUri, ...) usage.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/DocumentHighlight/RemoteDocumentHighlightService.cs Switches mapping import to remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Diagnostics/RazorTranslateDiagnosticsService.cs Switches mapping import to remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Debugging/RemoteDebugInfoService.cs Switches mapping import to remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Debugging/RemoteDataTipRangeService.cs Switches mapping import to remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Completion/RemoteCompletionService.cs Inlines provisional-completion helper into remote service; continues using mapping GetPositionInfo.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Completion/CSharpCompletionItemFormatter.cs Treats command doc URIs as DocumentUri directly.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CodeLens/RemoteCodeLensService.cs Switches mapping import to remote mapping namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CodeActions/RoslynCodeActionHelpers.cs Replaces MEF service with static helper methods (format/simplify).
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CodeActions/RazorCodeActionContext.cs Changes delegated document URI field to DocumentUri?.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CodeActions/Razor/RazorCodeActionFactory.cs Changes delegated document URI parameters to DocumentUri?.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CodeActions/Razor/IRoslynCodeActionHelpers.cs Removes old helper interface.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CodeActions/Razor/GenerateEventHandlerCodeActionResolver.cs Switches to static simplification helper + DocumentUri plumbing.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs Switches to static formatting helper + keeps DocumentUri identifiers.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CodeActions/Razor/AddUsingsCodeActionResolver.cs Updates delegated document URI fields to DocumentUri?.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CodeActions/Models/CodeActionExtensions.cs Updates delegated document URI parameters to DocumentUri?.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CodeActions/CSharp/CSharpCodeActionResolver.cs Uses DocumentUri for generated document identity and lookups.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CodeActions/CodeActionsService.cs Uses DocumentUri for delegated document URI flow.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CallHierarchy/RemoteCallHierarchyService.cs Uses DocumentUri for mapping call hierarchy items/ranges.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/UriExtensions.cs Simplifies GetRequiredSystemUri and retains UriDocumentUri conversion helper.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Remote/IRemoteInlineCompletionService.cs Changes inline completion request info to DocumentUri.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/SolutionExtensions.cs Updates source-generated document identity APIs to accept DocumentUri.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/RazorCodeDocumentExtensions.cs Updates generated-document lookup helper to accept DocumentUri.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/LspExtensions_Location.cs Deconstructs LspLocation to DocumentUri instead of Uri.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/DocumentUriExtensions.cs Updates Razor virtual HTML URI detection to return DocumentUri.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DocumentMapping/IDocumentMappingServiceExtensions.cs Removes workspaces-layer copy of mapping extensions (now hosted in remote layer).
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/Delegation/DelegatedCompletionHelper.cs Removes provisional-completion helper (now in remote completion service).
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/CodeActions/RazorCodeActionResolutionParams.cs Changes delegated document URI to DocumentUri? with converter for JSON.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Navigation/CohostGoToImplementationEndpoint.cs Uses DocumentUri directly when remapping virtual HTML URIs.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Navigation/CohostGoToDefinitionEndpoint.cs Uses DocumentUri directly when remapping virtual HTML URIs and links.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/IncompatibleProjectService.cs Replaces GetSystemUri() usage with DocumentUri.ParsedUri.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Diagnostics/CohostDocumentPullDiagnosticsEndpointBase.cs Uses DocumentUri for HTML diagnostic delegation params.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/CodeActions/CohostCodeActionsResolveEndpoint.cs Reorders/updates imports consistent with cohost DocumentUri plumbing.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/CodeActions/CohostCodeActionsEndpoint.cs Uses DocumentUri for source-generated document lookup from request.

Co-authored-by: David Wengier <david.wengier@microsoft.com>
Copilot AI review requested due to automatic review settings July 2, 2026 01:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 74 out of 74 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings July 2, 2026 01:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 74 out of 74 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings July 2, 2026 05:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 74 out of 74 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CodeActions/Razor/GenerateEventHandlerCodeActionResolver.cs:86

  • RoslynCodeActionHelpers.GetSimplifiedEditsAsync now returns a non-null TextEdit[], but this code still treats the result as nullable (result ?? [edit]). That fallback is now dead and makes it unclear whether callers should expect simplification to fail gracefully vs throw. Simplify the flow by using the returned edits directly.
        var result = await RoslynCodeActionHelpers.GetSimplifiedEditsAsync(codeBehindDocument, edit, cancellationToken).ConfigureAwait(false);

        var codeBehindTextDocumentIdentifier = new OptionalVersionedTextDocumentIdentifier() { DocumentUri = codeBehindDocument.GetURI() };
        var codeBehindTextDocEdit = new TextDocumentEdit()
        {
            TextDocument = codeBehindTextDocumentIdentifier,
            Edits = [.. result ?? [edit]]
        };

Copilot AI review requested due to automatic review settings July 10, 2026 01:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 74 out of 74 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/CodeActions/Razor/GenerateEventHandlerCodeActionResolver.cs:125

  • RoslynCodeActionHelpers.GetSimplifiedEditsAsync returns a non-null TextEdit[], so this null-check pattern is now redundant and may produce warnings/unreachable-code noise. You can assign directly to edits and remove the if block.
        var result = await RoslynCodeActionHelpers.GetSimplifiedEditsAsync(generatedDocument, tempTextEdit, cancellationToken).ConfigureAwait(false);
        if (result is not { } edits)
        {
            return null;
        }

Copilot AI review requested due to automatic review settings July 10, 2026 02:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 74 out of 74 changed files in this pull request and generated no new comments.

@davidwengier
davidwengier enabled auto-merge July 10, 2026 03:05
@davidwengier
davidwengier merged commit b31f38e into dotnet:features/sonic Jul 10, 2026
24 of 25 checks passed
@davidwengier
davidwengier deleted the DocumentUri branch July 10, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants