Skip to content

fix: clamp completion range for unclosed string literals#239

Merged
aeschli merged 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-273226-html-unclosed-string-completions
Apr 10, 2026
Merged

fix: clamp completion range for unclosed string literals#239
aeschli merged 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-273226-html-unclosed-string-completions

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

Summary

Fixes microsoft/vscode#273226

Bug: HTML attribute value completions with unclosed quotes would extend the replace range past < characters, causing subsequent HTML tags to be deleted when accepting a completion.

Root Cause: When a quoted attribute value is not closed, valueContentEnd was set to the end of the scanner token, which could span across < characters into subsequent HTML content. The completion replace range then covered too much text.

Fix: When the closing quote is missing (unclosed string literal), clamp valueContentEnd to the current cursor offset so the replace range does not extend into subsequent HTML content.

Changes

  • src/services/htmlCompletion.ts: Added an else branch in the attribute value range calculation to set valueContentEnd = offset when the closing quote is absent, preventing the replace range from spanning past the cursor.
  • src/test/completion.test.ts: Added two regression tests verifying that completions inside unclosed attribute values do not delete subsequent </th> or <td> tags.

Testing

  • Added regression tests in src/test/completion.test.ts that verify completions for unclosed string literals preserve subsequent HTML tags
  • All 147 existing tests pass

When an attribute value has an unclosed quote, the replace range could
extend past `<` characters after the cursor, causing completions to
delete subsequent HTML tags. Clamp valueContentEnd to the cursor offset
when the closing quote is missing.

Fixes microsoft/vscode#273226
@aeschli aeschli enabled auto-merge (squash) April 10, 2026 07:56
@aeschli aeschli merged commit bd99c28 into microsoft:main Apr 10, 2026
3 checks passed
@aeschli
Copy link
Copy Markdown
Collaborator

aeschli commented Apr 10, 2026

@maruthang Thanks!
I think these's still a problem if there's a quote somewhere later in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[html] completions: better handle unclosed string literals

3 participants