[Sonic] Support multiple C# documents in auto insert - #84148
Conversation
… the endpoint (since there is only one that comes from MEF anyway)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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.Razorand remove the old Workspaces-based auto-insert service/types. - Update
RemoteAutoInsertServiceto 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>
|
Oh the test failure here is fun. So during typing, when the razor document looks like this: 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: 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>
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