Skip to content

Conversation

@MariaSolOs
Copy link
Contributor

Closes #2194

I do want to call out that an alternative solution is to allow nested placeholders to consist of multiple nodes, which would require the grammar change from #2032.

@jwortmann
Copy link

jwortmann commented Oct 26, 2025

Could you explain how ${1:${2:placeholder}} should behave in practice? A construct like that doesn't make much sense to me. Let's say I trigger such a snippet, then the text placeholder is inserted and selected, and when I press the tab key to jump to the "next" tab stop, nothing happens and it is still selected?

On the other hand I could see how something like ${1:another ${2:placeholder}} might be useful in theory. Let's assume the full snippet is lorem ${1:another ${2:placeholder}} ipsum. When the snippet is triggered, the text another placeholder is selected first. If the user then presses tab, only the text placeholder is still selected.

Scenario 1: user accepts both placeholders: tabtab
The resulting text is: lorem another placeholder ipsum

Scenario 2: user accepts only the first placeholder, then types something to overwrite the second placeholder: tabfootab
The resulting text is: lorem another foo ipsum

Scenario 3: user immediately types something to overwrite the first placeholder (that means that the second tab stop never comes into effect, because it is part of the first placeholder, which was overwritten): footab
The resulting text is: lorem foo ipsum

I don't know about client support for snippets with nested placeholders. But I would say, either the grammar should be fixed to allow ${1:another ${2:placeholder}}, or nested snippets should simply not be allowed. If you instead want to add the construct ${1:${2:placeholder}} as an explicit example for nested snippets, then the specs should include an explanation what the purpose of that is and how exactly it should behave.

Edit: #2194 (comment) shows a good example with a nested placeholder of the form ${1:another ${2:placeholder}}. Since it works fine in VSCode, and I can confirm that it works in Sublime Text as well, I would vote to keep the current description and just fix the grammar accordingly.

@MariaSolOs
Copy link
Contributor Author

@jwortmann I don't have a preference over whether we should change the grammar or this example. As mentioned in the PR description #2032 is the alternative that modifies the grammar, this PR is simply the other option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid snippet example in nested placeholder snippet

2 participants