Skip to content

A completion snippet does not link a tab stop to the placeholder with its index: ${1:name} = $1 inserts name =  #2073

Closed

Description

@lagergren

A completion snippet whose tab stop has the same index as a placeholder inserts the tab stop empty, and doesn't link it to the placeholder.

Snippet Inserted After typing x at the first stop Expected
${1:name} = $1 name = x = name = name, then x = x
$1 = ${1:name} = name (the first stop is the empty $1) x = name name = name, then x = x

The LSP specification (3.17 and 3.18, Snippet Syntax) says: "Multiple tab stops are linked and updated in sync." InsertTextFormat.Snippet says: "Placeholders with equal identifiers are linked, that is typing in one will update others too."

Reproduce

On main (2da25ca), this test fails both ways:

public class SnippetMirrorTest extends LSPCompletionFixtureTestCase {

    public SnippetMirrorTest() {
        super("*.snippet-test");
    }

    public void testATabStopAfterItsPlaceholderMirrorsIt() {
        insert("${1:name} = $1$0"); // inserts "name = "
    }

    public void testATabStopBeforeItsPlaceholderMirrorsIt() {
        insert("$1 = ${1:name}$0"); // inserts " = name"
    }

    private void insert(String text) {
        TemplateManagerImpl.setTemplateTesting(getTestRootDisposable());
        var item = new CompletionItem("block");
        item.setInsertText(text);
        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("name = name", myFixture.getEditor().getDocument().getText());
    }
}

Cause

SnippetTemplateLoader links template variables by placeholder text, not by index. tabstop(int) adds a new empty variable for every tab stop other than $0. startPlaceholder declares a variable named after its text, which variable reuses only for a later placeholder with the same text. So ${1:name} = ${1:name} is linked, but ${1:name} = $1 isn't, and neither is ${1:a} ${1:b}.

#2070 uses the same loader for the live template of a snippet edit, so it has the same gap in the selected editor. The plain text #2070 inserts in another file already repeats the default at the tab stop.

Activity

  1. added
    bug
    on Nov 21, 2026
  2. added this to the 0.30.2 milestone on Nov 22, 2026
  3. added a commit that references this issue on Nov 23, 2026
    7bfb9f4
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