Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/neovim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ jobs:
run: git clone --depth=1 https://github.com/tree-sitter/tree-sitter-ruby.git
working-directory: /tmp

- name: Clone tree-sitter-php
# Pin to the tree-sitter-php revision currently locked by
# nvim-treesitter (https://github.com/nvim-treesitter/nvim-treesitter/blob/master/lockfile.json)
# since this is what most users have installed, and its grammar
# differs from the latest tree-sitter-php master (see #448).
run: |
mkdir tree-sitter-php && cd tree-sitter-php
git init -q
git remote add origin https://github.com/tree-sitter/tree-sitter-php.git
git fetch --depth=1 origin 576a56fa7f8b68c91524cdd211eb2ffc43e7bb11
git checkout -q FETCH_HEAD
working-directory: /tmp

- name: Create default nvim runtime parser directory
run: mkdir -p $HOME/.local/share/nvim/site/parser

Expand All @@ -55,6 +68,10 @@ jobs:
run: tree-sitter build -o $HOME/.local/share/nvim/site/parser/ruby.so
working-directory: /tmp/tree-sitter-ruby

- name: Build tree-sitter-php
run: tree-sitter build -o $HOME/.local/share/nvim/site/parser/php.so
working-directory: /tmp/tree-sitter-php/php

- name: "Run test"
run: |
bash -c 'VIMCMD=nvim test/vader/run'
Expand Down
2 changes: 1 addition & 1 deletion after/queries/php/matchup.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; PHP tags
(php_tag) @open.php
(php_end_tag) @close.php
"?>" @close.php
(program) @scope.php

; if
Expand Down
18 changes: 17 additions & 1 deletion lua/treesitter-matchup/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ local M = {}

local cache = lru.new(150)

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


---@param lang string
---@param bufnr integer
Expand Down Expand Up @@ -65,7 +69,19 @@ end
---@param erow integer
---@return matchup.treesitter.Match[]
local get_lang_matches = function(bufnr, root, lang, srow, erow)
local query = ts.query.get(lang, 'matchup')
if broken_langs[lang] then
return {}
end

local ok, query_or_err = pcall(ts.query.get, lang, 'matchup')
if not ok then
broken_langs[lang] = true
vim.notify_once(
string.format('matchup: failed to load treesitter matchup query for %s: %s', lang, query_or_err),
vim.log.levels.WARN)
return {}
end
local query = query_or_err

if not query then
return {}
Expand Down
13 changes: 13 additions & 0 deletions test/new/test-treesitter/example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

function foo($x) {
if ($x == 1) {
return 1;
} else {
return 2;
}
}

foo(1);

?>
15 changes: 15 additions & 0 deletions test/new/test-treesitter/test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,19 @@ call assert_equal([3, 4], getcurpos()[1:2])
norm 2%
call assert_equal([1, 1], getcurpos()[1:2])

" php (regression test for #448: matching PHP tags and if/else must not
" error out when the treesitter query references node types not defined
" by the installed parser)
silent edit example.php

call s:assert_ts_active()

0go
norm %
call assert_equal([13, 2], getcurpos()[1:2])

call cursor(4, 3)
norm %
call assert_equal([6, 8], getcurpos()[1:2])

call matchup#test#finished()