Skip to content

[Sonic] Support multiple C# documents in auto insert - #84148

Merged
davidwengier merged 7 commits into
dotnet:features/sonicfrom
davidwengier:razor-sonic-auto-insert
Jun 17, 2026
Merged

[Sonic] Support multiple C# documents in auto insert#84148
davidwengier merged 7 commits into
dotnet:features/sonicfrom
davidwengier:razor-sonic-auto-insert

Conversation

@davidwengier

@davidwengier davidwengier commented Jun 16, 2026

Copy link
Copy Markdown
Member

Also moves logic from Workspaces up to Remote.

UPDATE: Seems I overlooked something in the on type formatting changes, which a test in this endpoint revealed, so the on type formatter got some changes too. Aside: I hate the on type formatter so much, and I want to delete so much code.

Microsoft Reviewers: Open in CodeFlow

davidwengier and others added 5 commits June 16, 2026 15:16
… the endpoint (since there is only one that comes from MEF anyway)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 16, 2026 05:52
@davidwengier
davidwengier requested a review from a team as a code owner June 16, 2026 05:52

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 refactors Razor auto-insert infrastructure so the provider logic lives in the Remote layer, and updates cohosting registration/tests accordingly, enabling C# auto-insert to work correctly when the mapped position targets different generated C# documents (decl vs impl).

Changes:

  • Move Razor auto-insert provider contracts/exports into Microsoft.CodeAnalysis.Remote.Razor and remove the old Workspaces-based auto-insert service/types.
  • Update RemoteAutoInsertService to select the correct generated C# document (decl/impl) and flow that choice into formatting/mapping.
  • Simplify Cohost trigger-character registration by hardcoding the trigger sets, and add unit tests to keep cohost triggers in sync with OOP/Remote.

Reviewed changes

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

Show a summary per file
File Description
src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.UnitTests/Endpoints/CohostOnAutoInsertEndpointTest.cs Adds trigger-character sync tests; re-enables several previously skipped C# auto-insert tests.
src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.UnitTests/AutoInsert/RazorOnAutoInsertProviderTestBase.cs Updates tests to reference the new Remote auto-insert provider namespace.
src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.UnitTests/AutoInsert/CloseTextTagOnAutoInsertProviderTest.cs Updates using to new Remote provider namespace.
src/Razor/src/Razor/test/Microsoft.CodeAnalysis.Razor.CohostingShared.UnitTests/AutoInsert/AutoClosingTagOnAutoInsertProviderTest.cs Updates using to new Remote provider namespace.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/AutoInsert/RemoteOnAutoInsertProviders.cs Deletes now-unnecessary remote wrapper exports (providers are exported directly).
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/AutoInsert/RemoteAutoInsertService.cs Moves Razor-provider resolution into Remote, adds decl/impl generated-doc support, and keeps trigger allowlists local.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/AutoInsert/OOPAutoInsertService.cs Deletes old Workspaces-derived auto-insert service wrapper.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/AutoInsert/IOnAutoInsertProvider.cs Moves the provider interface into the Remote namespace and inlines TriggerCharacter.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/AutoInsert/CloseTextTagOnAutoInsertProvider.cs Moves provider into Remote namespace and adds MEF export attributes.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/AutoInsert/AutoClosingTagOnAutoInsertProvider.cs Moves provider into Remote namespace and adds MEF export attributes.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AutoInsert/IOnAutoInsertTriggerCharacterProvider.cs Deletes obsolete Workspaces trigger-character-only contract.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AutoInsert/IAutoInsertService.cs Deletes obsolete Workspaces auto-insert service contract.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/AutoInsert/AutoInsertService.cs Deletes obsolete Workspaces implementation of provider dispatch/trigger allowlists.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/OnAutoInsert/CohostOnAutoInsertTriggerCharacterProviders.cs Deletes old cohost-only trigger providers (replaced by hardcoded trigger sets).
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/OnAutoInsert/CohostOnAutoInsertEndpoint.cs Replaces MEF-imported trigger computation with static trigger arrays + test accessors.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Microsoft.CodeAnalysis.Razor.CohostingShared.projitems Removes the deleted cohost trigger-provider file from the shared project items.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 16, 2026 06:32

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 16 out of 16 changed files in this pull request and generated no new comments.

@davidwengier

Copy link
Copy Markdown
Member Author

Oh the test failure here is fun. So during typing, when the razor document looks like this:

@code {
    void TestMethod() {
        var x = """$$
    }
}

That document has no decl document, because the unterminated raw string literal eats the closing brace, so the code block is not a code block, so all of that goes in the impl document. As soon as auto insert runs, the document is now:

@code {
    void TestMethod() {
        var x = """$$"""
    }
}

That document has a correctly closed raw string literal, so has a code block, so has a decl document, and thats where the code is. So during formatting, the code we're trying to format moves from one document to the other. This is less than ideal. I legitimately don't know how to deal with this.

Account for Razor edits that move mapped C# content between implementation and declaration generated documents during formatter cleanup and indentation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@davidwengier
davidwengier merged commit 6b834d3 into dotnet:features/sonic Jun 17, 2026
25 checks passed
@davidwengier
davidwengier deleted the razor-sonic-auto-insert branch June 17, 2026 01:51
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