From 039fe9095d07910e71ec41ef38e0bffa378293e1 Mon Sep 17 00:00:00 2001 From: Phạm Huy Hoàng Date: Sun, 18 Feb 2024 20:56:53 +0900 Subject: fix(format): update scripts to support nightly (#6126) No need for assert as the use is contained within the script only --- scripts/format-queries.lua | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'scripts/format-queries.lua') 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 = ' ' -- cgit v1.2.3-70-g09d2