Skip to content

Commit

Permalink
🐛 Fix double-escaping completion items in strings (#1686)
Browse files Browse the repository at this point in the history
  • Loading branch information
misode authored Dec 27, 2024
1 parent b3e8fed commit 4ebdba8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/core/src/processor/completer/Completer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ export namespace CompletionItem {
export function escape(textToInsert: string): string {
return textToInsert.replace(/([\\$}])/g, '\\$1')
}

/**
* Un-escape `$`, `\`, and `}` in `textToInsert`
*/
export function unescape(textToInsert: string): string {
return textToInsert.replace(/\\([\\$}])/g, '$1')
}
}

export class InsertTextBuilder {
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/processor/completer/builtin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,10 @@ export function escapeString(value: string, quote?: Quote) {
if (!quote) {
return value
}
return value.replaceAll('\\', '\\\\').replaceAll(quote, '\\"')
// Un-escape and then re-escape completion
value = CompletionItem.unescape(value)
value = value.replaceAll('\\', '\\\\').replaceAll(quote, '\\"')
return CompletionItem.escape(value)
}

export const symbol: Completer<SymbolBaseNode> = (node, ctx) => {
Expand Down

0 comments on commit 4ebdba8

Please sign in to comment.