Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1303,8 +1303,8 @@ function registerRestartJavaLanguageServerCommand(context: ExtensionContext) {
}));
}

function escapeSnippetLiterals(value: string): string {
export function escapeSnippetLiterals(value: string): string {
return value
.replace(/\\/g, '\\\\') // Escape backslashes
.replace(/\\(?!,)/g, '\\\\') // Escape backslashes, but preserve escaped commas
.replace(/\$(?!\{)/g, '\\$'); // Escape $ only if NOT followed by {
}
7 changes: 7 additions & 0 deletions test/standard-mode-suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Commands } from '../../src/commands';
import * as java from '../../src/javaServerStarter';
import * as plugin from '../../src/plugin';
import * as requirements from '../../src/requirements';
import { escapeSnippetLiterals } from '../../src/extension';

suite('Java Language Extension - Standard', () => {

Expand Down Expand Up @@ -233,4 +234,10 @@ suite('Java Language Extension - Standard', () => {
assert(java.hasDebugFlag(['foo', '--debug=1234']));
assert(java.hasDebugFlag(['foo', '--debug-brk=1234']));
});

test('should preserve escaped commas in code action snippets', () => {
const snippet = '${1|HashMap<Integer\\,Integer>,Map<Integer\\,Integer>|} ${2:x} = new HashMap<Integer, Integer>();';

assert.equal(escapeSnippetLiterals(snippet), snippet);
});
});
Loading