Skip to content

add gotmpl matchup queries - #446

Open
dpezto wants to merge 2 commits into
andymass:masterfrom
dpezto:feat/gotmpl-queries
Open

add gotmpl matchup queries#446
dpezto wants to merge 2 commits into
andymass:masterfrom
dpezto:feat/gotmpl-queries

Conversation

@dpezto

@dpezto dpezto commented Jul 21, 2026

Copy link
Copy Markdown

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 on if keeps the if inside {{ else if }} from being captured as an opener.

Tested with nvim-treesitter's gotmpl parser on chezmoi templates.

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 "{{-".
Copilot AI review requested due to automatic review settings July 21, 2026 20:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.scm with scope + open/mid/close captures for gotmpl control structures.
  • Implements an anchored if_action opener match to avoid treating the if in {{ else if }} as a new opener.
  • Adds continue/break as mid targets within range blocks.

💡 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.
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.

2 participants