mirror of
https://github.com/neovim/neovim.git
synced 2025-12-06 14:42:35 +00:00
Merge pull request #12847 from nvim-treesitter/ts-list-predicates
treesitter: allow to list supported predicates
This commit is contained in:
@@ -782,6 +782,11 @@ vim.treesitter.query.add_predicate({name}, {handler})
|
|||||||
This adds a predicate with the name {name} to be used in queries.
|
This adds a predicate with the name {name} to be used in queries.
|
||||||
{handler} should be a function whose signature will be : >
|
{handler} should be a function whose signature will be : >
|
||||||
handler(match, pattern, bufnr, predicate)
|
handler(match, pattern, bufnr, predicate)
|
||||||
|
<
|
||||||
|
*vim.treesitter.query.list_predicates()*
|
||||||
|
vim.treesitter.query.list_predicates()
|
||||||
|
|
||||||
|
This lists the currently available predicates to use in queries.
|
||||||
|
|
||||||
Treesitter syntax highlighting (WIP) *lua-treesitter-highlight*
|
Treesitter syntax highlighting (WIP) *lua-treesitter-highlight*
|
||||||
|
|
||||||
|
|||||||
@@ -127,6 +127,11 @@ function M.add_predicate(name, handler, force)
|
|||||||
predicate_handlers[name] = handler
|
predicate_handlers[name] = handler
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Returns the list of currently supported predicates
|
||||||
|
function M.list_predicates()
|
||||||
|
return vim.tbl_keys(predicate_handlers)
|
||||||
|
end
|
||||||
|
|
||||||
function Query:match_preds(match, pattern, bufnr)
|
function Query:match_preds(match, pattern, bufnr)
|
||||||
local preds = self.info.patterns[pattern]
|
local preds = self.info.patterns[pattern]
|
||||||
if not preds then
|
if not preds then
|
||||||
|
|||||||
@@ -312,6 +312,18 @@ void ui_refresh(void)
|
|||||||
]], custom_query)
|
]], custom_query)
|
||||||
|
|
||||||
eq({{0, 4, 0, 8}}, res)
|
eq({{0, 4, 0, 8}}, res)
|
||||||
|
|
||||||
|
local res_list = exec_lua[[
|
||||||
|
local query = require'vim.treesitter.query'
|
||||||
|
|
||||||
|
local list = query.list_predicates()
|
||||||
|
|
||||||
|
table.sort(list)
|
||||||
|
|
||||||
|
return list
|
||||||
|
]]
|
||||||
|
|
||||||
|
eq({ 'contains?', 'eq?', 'is-main?', 'match?', 'vim-match?' }, res_list)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('supports highlighting', function()
|
it('supports highlighting', function()
|
||||||
|
|||||||
Reference in New Issue
Block a user