Skip to content

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

Closed

Description

@lagergren

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());
var item = new CompletionItem("block");
item.setInsertText("${1:a ${2:b} c} d$0");
item.setInsertTextFormat(InsertTextFormat.Snippet);
var other = new CompletionItem("blockOther");
assertCompletion("test.snippet-test", "blo<caret>",
        new CompletionList(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:

startPlaceholder(1, "a ", 1), startPlaceholder(2, "b", 2), endPlaceholder(2), text(" c} d"), endPlaceholder(1)

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

  1. added
    bug
    on Nov 21, 2026
  2. added a commit that references this issue on Nov 22, 2026
    9b3dd91
  3. added this to the 0.30.2 milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcompletion

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions