Skip to content

Fix close tag completion replacement ranges - #85710

Merged
davidwengier merged 1 commit into
dotnet:mainfrom
davidwengier:fix-razor-closing-tag-completion-range
Oct 6, 2026
Merged

davidwengier merged 1 commit into
dotnet:mainfrom
davidwengier:fix-razor-closing-tag-completion-range

Conversation

@davidwengier

@davidwengier davidwengier commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

Stop end-tag completion from eating the rest of the Razor document due to poor error recovery in the compiler.

Fixes #85709

Microsoft Reviewers: Open in CodeFlow

Don't use the full recovered end tag span when the close angle is missing, since it can include following Razor and C# content.
@davidwengier
davidwengier requested review from a team and a lite review from Copilot September 20, 2026 01:05
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

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.

Copilot review overview

🟢 Approval recommended

The change is small, targeted, and includes a regression test that exercises the new replacement-range behavior in a realistic nested Razor/C# scenario.

Review effort: Lite
Findings: None

What changed in this PR

This PR adjusts Razor HTML close-tag completion’s replacement range to avoid deleting unrelated following content when the Razor parser’s error recovery produces an overly-large end-tag span.

Changes:

  • Narrow the close-tag TextEdit replacement range to end at the end-tag name when the close-angle token is missing, otherwise end at the close-angle token.
  • Add a regression test covering close-tag completion inside nested C# blocks to ensure following code is preserved.
File Description
src/​Razor/​src/​Razor/​src/​Microsoft.CodeAnalysis.Remote.Razor/​Completion/​Html/​LocalHtmlCompletionProvider.cs Constrains close-tag completion replacement ranges to avoid consuming error-recovered trailing content.
src/​Razor/​src/​Razor/​test/​Microsoft.CodeAnalysis.Remote.Razor.UnitTests/​Completion/​LocalHtmlCompletionProviderTest.cs Adds regression coverage ensuring close-tag completion doesn’t remove subsequent Razor/C# content.

@davidwengier
davidwengier requested a review from a team September 21, 2026 05:21
@davidwengier

Copy link
Copy Markdown
Member Author

Ping @dotnet/roslyn-ide @dotnet/razor-tooling for review

@chsienki chsienki left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems fine as a targeted fix, but presumably the better fix is to handle error recovery in the compiler better? We should perhaps put an issue link here so we'll find the workaround if we ever get to real error recovery.

@davidwengier

Copy link
Copy Markdown
Member Author

I don't disagree, but I hate that adding a comment needs me to wait for approvals again, so I'm going to just have faith that the LLMs will find this :P

@davidwengier
davidwengier merged commit 44b02d6 into dotnet:main Oct 6, 2026
25 checks passed
@davidwengier
davidwengier deleted the fix-razor-closing-tag-completion-range branch October 6, 2026 21:36
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Oct 6, 2026
@akhera99 akhera99 modified the milestones: Next, 18.13 Oct 26, 2026
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.

Closing tag completion can eat other parts of the document

4 participants