fix: clamp HTML completion ranges for unclosed string literals#308736
Closed
maruthang wants to merge 1 commit intomicrosoft:mainfrom
Closed
fix: clamp HTML completion ranges for unclosed string literals#308736maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…soft#273226) When an attribute value has an opening quote but no closing quote, the HTML parser treats subsequent HTML tags as part of the attribute value, causing completion replacement ranges to extend too far. Post-process completion items to clamp their ranges before any '<' character after the cursor position, preventing deletion of subsequent HTML content.
Contributor
|
The correct place to fix this is in the https://github.com/microsoft/vscode-html-languageservice |
Contributor
Author
|
Thanks @aeschli — you're right. I've submitted the fix upstream at microsoft/vscode-html-languageservice#239 instead. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #273226
Summary
Bug: When an HTML attribute value has an unclosed quote (e.g.,
<input type="che), selecting a completion replaces content beyond the cursor, deleting subsequent HTML tags.Root Cause: The HTML parser treats everything after an unclosed quote as part of the attribute value string, so the completion replacement range extends into subsequent tags like
</th>.Fix: Post-process completion items in
htmlMode.tsto clamp their text edit ranges before any<character found after the cursor position, preventing the replacement from leaking into subsequent HTML content.Changes
extensions/html-language-features/server/src/modes/htmlMode.ts: Added range clamping logic afterdoComplete2that scans for<between the cursor and the edit range end, and clamps the range to stop before it.extensions/html-language-features/server/src/test/completions.test.ts: Added 3 regression tests covering unclosed quote completions, unclosed quote with trailing space, and properly closed quotes (to ensure no regression).Test Plan
<th><input type="che|</th>producescheckboxwithout replacing</th><th><input type="che| </th>works correctly with space before closing tag<input type="che|">still works normally with properly closed quotes