mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
Use stylua for autoformat code (#1480)
This commit is contained in:
parent
90f15d9bf7
commit
be8f656087
32 changed files with 1181 additions and 979 deletions
|
|
@ -1,4 +1,4 @@
|
|||
local query = require"vim.treesitter.query"
|
||||
local query = require "vim.treesitter.query"
|
||||
|
||||
local function error(str)
|
||||
vim.api.nvim_err_writeln(str)
|
||||
|
|
@ -21,7 +21,9 @@ local function valid_args(name, pred, count, strict_count)
|
|||
end
|
||||
|
||||
query.add_predicate("nth?", function(match, pattern, bufnr, pred)
|
||||
if not valid_args("nth?", pred, 2, true) then return end
|
||||
if not valid_args("nth?", pred, 2, true) then
|
||||
return
|
||||
end
|
||||
|
||||
local node = match[pred[2]]
|
||||
local n = pred[3]
|
||||
|
|
@ -33,13 +35,17 @@ query.add_predicate("nth?", function(match, pattern, bufnr, pred)
|
|||
end)
|
||||
|
||||
local function has_ancestor(match, pattern, bufnr, pred)
|
||||
if not valid_args(pred[1], pred, 2) then return end
|
||||
if not valid_args(pred[1], pred, 2) then
|
||||
return
|
||||
end
|
||||
|
||||
local node = match[pred[2]]
|
||||
local ancestor_types = {unpack(pred, 3)}
|
||||
if not node then return true end
|
||||
local ancestor_types = { unpack(pred, 3) }
|
||||
if not node then
|
||||
return true
|
||||
end
|
||||
|
||||
local just_direct_parent = pred[1]:find('has-parent', 1, true)
|
||||
local just_direct_parent = pred[1]:find("has-parent", 1, true)
|
||||
|
||||
node = node:parent()
|
||||
while node do
|
||||
|
|
@ -55,40 +61,48 @@ local function has_ancestor(match, pattern, bufnr, pred)
|
|||
return false
|
||||
end
|
||||
|
||||
query.add_predicate('has-ancestor?', has_ancestor)
|
||||
query.add_predicate("has-ancestor?", has_ancestor)
|
||||
|
||||
query.add_predicate('has-parent?', has_ancestor)
|
||||
query.add_predicate("has-parent?", has_ancestor)
|
||||
|
||||
query.add_predicate('is?', function(match, pattern, bufnr, pred)
|
||||
if not valid_args("is?", pred, 2) then return end
|
||||
query.add_predicate("is?", function(match, pattern, bufnr, pred)
|
||||
if not valid_args("is?", pred, 2) then
|
||||
return
|
||||
end
|
||||
|
||||
-- Avoid circular dependencies
|
||||
local locals = require"nvim-treesitter.locals"
|
||||
local locals = require "nvim-treesitter.locals"
|
||||
local node = match[pred[2]]
|
||||
local types = {unpack(pred, 3)}
|
||||
local types = { unpack(pred, 3) }
|
||||
|
||||
if not node then return true end
|
||||
if not node then
|
||||
return true
|
||||
end
|
||||
|
||||
local _, _, kind = locals.find_definition(node, bufnr)
|
||||
|
||||
return vim.tbl_contains(types, kind)
|
||||
end)
|
||||
|
||||
query.add_predicate('has-type?', function(match, pattern, bufnr, pred)
|
||||
if not valid_args(pred[1], pred, 2) then return end
|
||||
query.add_predicate("has-type?", function(match, pattern, bufnr, pred)
|
||||
if not valid_args(pred[1], pred, 2) then
|
||||
return
|
||||
end
|
||||
|
||||
local node = match[pred[2]]
|
||||
local types = {unpack(pred, 3)}
|
||||
local types = { unpack(pred, 3) }
|
||||
|
||||
if not node then return true end
|
||||
if not node then
|
||||
return true
|
||||
end
|
||||
|
||||
return vim.tbl_contains(types, node:type())
|
||||
end)
|
||||
|
||||
-- Just avoid some anoying warnings for this directive
|
||||
query.add_directive('make-range!', function() end)
|
||||
query.add_directive("make-range!", function() end)
|
||||
|
||||
query.add_directive('downcase!', function(match, _, bufnr, pred, metadata)
|
||||
query.add_directive("downcase!", function(match, _, bufnr, pred, metadata)
|
||||
local text, key, value
|
||||
|
||||
if #pred == 3 then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue