Skip to content

Fix PHP treesitter query error "Invalid node type php_end_tag" on every cursor move - #450

Closed
andymass with Copilot wants to merge 3 commits into
masterfrom
copilot/fix-nvim-treesitter-php-error
Closed

Fix PHP treesitter query error "Invalid node type php_end_tag" on every cursor move#450
andymass with Copilot wants to merge 3 commits into
masterfrom
copilot/fix-nvim-treesitter-php-error

Conversation

Copilot AI commented Sep 5, 2026

Copy link
Copy Markdown

Nvim + treesitter users editing PHP files saw a repeated error on every cursor move because the matchup query referenced a tree-sitter node type not present in their installed grammar.

Root cause

after/queries/php/matchup.scm matched PHP's closing tag via a named (php_end_tag) node. That node only exists in the very latest upstream tree-sitter-php grammar; the revision currently locked by nvim-treesitter (what most users actually have installed) still represents ?> as an anonymous token. Query compilation fails hard on unknown node types, so every match computation errored out.

Changes

  • Query fix: use "?>" @close.php instead of (php_end_tag) @close.php, matching the anonymous token used by the currently-shipped grammar (and matching nvim-treesitter's own highlights.scm).
  • Defensive guard: wrap treesitter query compilation in pcall in internal.lua, caching failures per-language so a mismatch logs a single warning and disables treesitter matching for that language instead of erroring on every cursor move.
  • Regression test: new test/new/test-treesitter/example.php plus additions to test.vim covering PHP tag matching and if/else matching.
  • CI: build a tree-sitter-php parser pinned to the same revision nvim-treesitter locks, so the new PHP test runs in CI.
; PHP tags
 (php_tag) @open.php
-(php_end_tag) @close.php
+"?>" @close.php
 (program) @scope.php

Copilot AI changed the title [WIP] Fix error 'Invalid node type php_end_tag' in Nvim treesitter Fix PHP treesitter query error "Invalid node type php_end_tag" on every cursor move Sep 5, 2026
Copilot AI requested a review from andymass September 5, 2026 19:48
-- languages whose matchup query failed to parse (e.g. because the
-- installed parser does not define a node type used by the query); we
-- remember this so we don't try (and error) again on every cursor move
local broken_langs = {} ---@type table<string, boolean>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Dumb

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.

Nvim + treesitter gives error "Invalid node type php_end_tag" on every cursor move

2 participants