aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/format-queries.lua
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/format-queries.lua')
-rwxr-xr-xscripts/format-queries.lua39
1 files changed, 27 insertions, 12 deletions
diff --git a/scripts/format-queries.lua b/scripts/format-queries.lua
index 8639daf2b..f924b8064 100755
--- a/scripts/format-queries.lua
+++ b/scripts/format-queries.lua
@@ -14,25 +14,40 @@ else
end
ts.query.add_predicate('kind-eq?', function(match, _, _, pred)
- local cap = match[pred[2]]
- local node = type(cap) == 'table' and cap[1] or cap
- if not node then
+ local nodes = match[pred[2]]
+ local types = { unpack(pred, 3) }
+
+ if not nodes or #nodes == 0 then
return true
end
- local types = { unpack(pred, 3) }
- return vim.tbl_contains(types, node:type())
-end, true)
+ for _, node in pairs(nodes) do
+ if not vim.tbl_contains(types, node:type()) then
+ return false
+ end
+ end
+ return true
+end, {
+ force = true,
+ all = true,
+})
ts.query.add_predicate('is-start-of-line?', function(match, _, _, pred)
- local cap = match[pred[2]]
- local node = type(cap) == 'table' and cap[1] or cap
- if not node then
+ local nodes = match[pred[2]]
+ if not nodes or #nodes == 0 then
return true
end
- local start_row, start_col = node:start()
- return vim.fn.indent(start_row + 1) == start_col
-end)
+ for _, node in pairs(nodes) do
+ local start_row, start_col = node:start()
+ if vim.fn.indent(start_row + 1) ~= start_col then
+ return false
+ end
+ end
+ return true
+end, {
+ force = true,
+ all = true,
+})
--- Control the indent here. Change to \t if uses tab instead
local indent_str = ' '