Skip to content

Fix: snippet escaping for resolved code action edits#4378

Merged
datho7561 merged 1 commit intoredhat-developer:mainfrom
amritamishra01:fix-snippet-escape-add-throws
Mar 30, 2026
Merged

Fix: snippet escaping for resolved code action edits#4378
datho7561 merged 1 commit intoredhat-developer:mainfrom
amritamishra01:fix-snippet-escape-add-throws

Conversation

@amritamishra01
Copy link
Copy Markdown
Contributor

Summary

Fixes corruption of unrelated source text when applying resolved snippet-based code actions such as Add throws declaration.

Problem

The Java language server returns snippet edits that may contain:

  • literal backslashes (\)
  • literal dollar signs ($)
  • real snippet placeholders like ${1|...|}

These edits were passed directly into SnippetString, causing VS Code to interpret literal characters as snippet syntax.

This led to issues such as:

  • "Escaped\\Test\\Path" becoming "Escaped\Test\Path"
  • page$content() becoming page()

Fix

Added escapeSnippetLiterals() before creating SnippetString.

This safely escapes:

  • literal backslashes
  • $ characters that are not snippet placeholders

while preserving valid placeholders like ${1|ExecutionException,Exception,Throwable|}.

Verification

Tested using the reproducer project from #4314.

Verified that:

  • escaped backslashes remain unchanged
  • page$content() remains unchanged
  • Add throws declaration still updates the method signature correctly

Fixes #4314

Copy link
Copy Markdown
Contributor

@datho7561 datho7561 left a comment

Choose a reason for hiding this comment

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

Seems good from my testing. Thanks, Amrita!

@datho7561 datho7561 merged commit c4a1cd6 into redhat-developer:main Mar 30, 2026
2 checks passed
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.

Quick fix "Add throws declaration" removes backslashes and qute fragments

2 participants