You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A snippet with a nested placeholder inserts the closing brace of the outer placeholder: ${1:a ${2:b} c} d inserts a b c} d #2074
A snippet with a nested placeholder, such as ${1:a ${2:b} c} d, inserts the closing } of the outer placeholder as text, and that placeholder covers only the text before the nested one.
Completion snippet
Inserted
Selected at the first stop
After typing x
Expected
${1:a ${2:b} c} d
a b c} d
a
xb c} d
a b c d, with a b c selected, then x d
The LSP specification (Snippet Syntax, Placeholders) says: "Placeholders can be nested, like ${1:another ${2:placeholder}}."
Reproduce
On main (2da25ca), in an LSPCompletionFixtureTestCase:
TemplateManagerImpl.setTemplateTesting(getTestRootDisposable());
varitem = newCompletionItem("block");
item.setInsertText("${1:a ${2:b} c} d$0");
item.setInsertTextFormat(InsertTextFormat.Snippet);
varother = newCompletionItem("blockOther");
assertCompletion("test.snippet-test", "blo<caret>",
newCompletionList(false, List.of(item, other)), "block", "blockOther");
myFixture.selectItem(myFixture.getLookupElements()[0]);
assertEquals("a b c d", myFixture.getEditor().getDocument().getText()); // was "a b c} d"
Cause
LspSnippetParser gives these handler calls for ${1:a ${2:b} c} d:
For a placeholder whose text doesn't end at its }, readAny reads the rest of the placeholder with a recursive readAny(). That call goes on to the end of the snippet, not to the placeholder's }. handleText then reads c} d as one text, } included, and endPlaceholder(1) comes only after the whole snippet.
#2070 repeats a placeholder's default at a tab stop with its index in the text of a snippet edit, so its mirror of a nested placeholder is wrong too. Once the parser ends the outer placeholder at its }, that text can be the placeholder's full rendered value.
Activity
fix: end a placeholder of a snippet at its closing brace, after a nes…