aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/treesitter_spec.lua
diff options
context:
space:
mode:
authorThomas Vigouroux <tomvig38@gmail.com>2020-08-10 18:25:52 +0200
committerThomas Vigouroux <tomvig38@gmail.com>2020-08-13 20:30:15 +0200
commitd7b12e58dfc7303dbc06381a9bedd5c3539d5413 (patch)
treeac8754a46a21b87305777126d9f9cd52caaad53b /test/functional/lua/treesitter_spec.lua
parent58e37d7df8ab3afc4d77e6ff1248d26a2559399e (diff)
downloadrneovim-d7b12e58dfc7303dbc06381a9bedd5c3539d5413.tar.gz
rneovim-d7b12e58dfc7303dbc06381a9bedd5c3539d5413.tar.bz2
rneovim-d7b12e58dfc7303dbc06381a9bedd5c3539d5413.zip
treesitter: add and test vim-match? predicate
Diffstat (limited to 'test/functional/lua/treesitter_spec.lua')
-rw-r--r--test/functional/lua/treesitter_spec.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/functional/lua/treesitter_spec.lua b/test/functional/lua/treesitter_spec.lua
index 808f6aa8db..b0ac9e079a 100644
--- a/test/functional/lua/treesitter_spec.lua
+++ b/test/functional/lua/treesitter_spec.lua
@@ -198,6 +198,41 @@ void ui_refresh(void)
}, res)
end)
+ it('allows to add predicates', function()
+ insert([[
+ int main(void) {
+ return 0;
+ }
+ ]])
+
+ local custom_query = "((identifier) @main (#is-main? @main))"
+
+ local res = exec_lua([[
+ local query = require"vim.treesitter.query"
+
+ local function is_main(match, pattern, bufnr, predicate)
+ local node = match[ predicate[2] ]
+
+ return query.get_node_text(node, bufnr)
+ end
+
+ local parser = vim.treesitter.get_parser(0, "c")
+
+ query.add_predicate("is-main?", is_main)
+
+ local query = query.parse_query("c", ...)
+
+ local nodes = {}
+ for _, node in query:iter_captures(parser:parse():root(), 0, 0, 19) do
+ table.insert(nodes, {node:range()})
+ end
+
+ return nodes
+ ]], custom_query)
+
+ eq({{0, 4, 0, 8}}, res)
+ end)
+
it('supports highlighting', function()
if not check_parser() then return end
@@ -246,6 +281,7 @@ static int nlua_schedule(lua_State *const lstate)
; Use lua regexes
((identifier) @Identifier (#contains? @Identifier "lua_"))
((identifier) @Constant (#match? @Constant "^[A-Z_]+$"))
+((identifier) @Normal (#vim-match? @Constant "^lstate$"))
((binary_expression left: (identifier) @WarningMsg.left right: (identifier) @WarningMsg.right) (#eq? @WarningMsg.left @WarningMsg.right))