add gotmpl matchup queries - #446
Open
dpezto wants to merge 2 commits into
Open
Conversation
Adds tree-sitter matchup queries for Go templates (gotmpl):
if/else/end, range/else/end (with continue/break as mids),
with/else/end, block/end, and define/end.
Both "{{" and the whitespace-trim marker "{{-" are listed since
they are distinct grammar tokens; templates written for chezmoi and
helm commonly use "{{-".
There was a problem hiding this comment.
Pull request overview
Adds tree-sitter matchup queries for the gotmpl (Go templates) parser so vim-matchup can navigate template block structures (if/range/with/block/define) using @open/@mid/@close captures, including support for {{- trim-marker delimiters and handling else if in if blocks.
Changes:
- Introduces
after/queries/gotmpl/matchup.scmwith scope + open/mid/close captures for gotmpl control structures. - Implements an anchored
if_actionopener match to avoid treating theifin{{ else if }}as a new opener. - Adds
continue/breakas mid targets withinrangeblocks.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+27
to
+31
| (continue_action | ||
| "continue" @mid.range.2) | ||
|
|
||
| (break_action | ||
| "break" @mid.range.3) |
The with pattern captured every direct-child "with" token as an opener,
so the "with" in {{ else with }} opened a phantom scope. Anchor it to
the delimiter like the if pattern.
The else mids used "?", which stops at one else; if and with chains can
hold any number of else-if / else-with clauses. Quantify with "*" and
include the clause keyword, so each clause spans one mid delimiter and
% works with the cursor on either word.
dpezto
added a commit
to dpezto/chezmoi-template.nvim
that referenced
this pull request
Jul 27, 2026
The with pattern captured every direct-child `with` token as an opener,
so the `with` in `{{ else with }}` opened a phantom scope. The grammar
inlines else clauses, which puts their tokens directly under
`with_action`; the pattern now anchors the opener to the delimiter, the
same way the if pattern already does.
The else mids used `?`, which stops at one else, but if and with chains
can hold any number of `{{ else if }}` / `{{ else with }}` clauses. They
are now quantified with `*` and include the clause keyword, so each
clause spans one mid delimiter and `%` works with the cursor on either
word.
Verified headless against tree-sitter-go-template: chains of else-if /
else-with, trim markers, nested actions, range with continue/break,
block and define all produce the expected open/mid/close sets after
vim-matchup's span-merge and range dedup. Mirrored verbatim to
vim-matchup PR andymass/vim-matchup#446.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds matchup queries for Go templates (gotmpl): if/else/end, range (+ continue/break as mids), with, block, define.
Both
{{and the trim marker{{-are listed since they're distinct tokens in the grammar; chezmoi and helm templates use{{-heavily. The anchor onifkeeps theifinside{{ else if }}from being captured as an opener.Tested with nvim-treesitter's gotmpl parser on chezmoi templates.