Handle backslash escapes in snippet completion text #6

Closed
ondrejmirtes wants to merge 0 commits from ondrejmirtes/lsp-client:snippet-escapes into main
First-time contributor

Snippet completion items (insertTextFormat: Snippet) carry LSP snippets, which
use \$, \} and \\ for literal characters. serverCompletion translated the $1
tab stops to ${1} but passed the escapes through to CodeMirror's snippet
parser unchanged, so e.g. a method completion with insertText "add(${1:\$x})$0"
came out as add(\$x) instead of add($x).

This unescapes \$, \} and \\ in the snippet translation, and adds a test.

Snippet completion items (insertTextFormat: Snippet) carry LSP snippets, which use `\$`, `\}` and `\\` for literal characters. serverCompletion translated the `$1` tab stops to `${1}` but passed the escapes through to CodeMirror's snippet parser unchanged, so e.g. a method completion with insertText `"add(${1:\$x})$0"` came out as `add(\$x)` instead of `add($x)`. This unescapes `\$`, `\}` and `\\` in the snippet translation, and adds a test.
The insertText of a snippet completion is an LSP snippet, where \$, \} and \\
are escapes for literal characters. We translated $1 tab stops to ${1} but
left the escapes alone and handed them to CodeMirror's snippet parser, which
doesn't understand them. So a completion like add(${1:\$x})$0 was inserted as
add(\$x) instead of add($x). Unescape \$, \} and \\ as well.
marijn referenced this pull request from a commit 2026-05-24 09:09:57 +02:00
Owner

Thanks! Merged as 1371912bbf

Thanks! Merged as 1371912bbfbad911a37eb556d7e1f4d1f02b5719
marijn closed this pull request 2026-05-24 09:10:12 +02:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/lsp-client!6
No description provided.