indent file by 4 spaces

This commit is contained in:
Ivar Fatland
2026-04-18 16:15:43 +02:00
parent d24946e94b
commit a876af8380
@@ -1,46 +1,46 @@
local query = require "vim.treesitter.query" local query = require "vim.treesitter.query"
local html_script_type_languages = { local html_script_type_languages = {
["importmap"] = "json", ["importmap"] = "json",
["module"] = "javascript", ["module"] = "javascript",
["application/ecmascript"] = "javascript", ["application/ecmascript"] = "javascript",
["text/ecmascript"] = "javascript", ["text/ecmascript"] = "javascript",
} }
local non_filetype_match_injection_language_aliases = { local non_filetype_match_injection_language_aliases = {
ex = "elixir", ex = "elixir",
pl = "perl", pl = "perl",
sh = "bash", sh = "bash",
uxn = "uxntal", uxn = "uxntal",
ts = "typescript", ts = "typescript",
} }
-- compatibility shim for breaking change on nightly/0.11 -- compatibility shim for breaking change on nightly/0.11
local opts = vim.fn.has "nvim-0.10" == 1 and { force = true, all = false } or true local opts = vim.fn.has "nvim-0.10" == 1 and { force = true, all = false } or true
local function get_parser_from_markdown_info_string(injection_alias) local function get_parser_from_markdown_info_string(injection_alias)
local match = vim.filetype.match { filename = "a." .. injection_alias } local match = vim.filetype.match { filename = "a." .. injection_alias }
return match or non_filetype_match_injection_language_aliases[injection_alias] or injection_alias return match or non_filetype_match_injection_language_aliases[injection_alias] or injection_alias
end end
local function error(str) local function error(str)
vim.api.nvim_err_writeln(str) vim.api.nvim_err_writeln(str)
end end
local function valid_args(name, pred, count, strict_count) local function valid_args(name, pred, count, strict_count)
local arg_count = #pred - 1 local arg_count = #pred - 1
if strict_count then if strict_count then
if arg_count ~= count then if arg_count ~= count then
error(string.format("%s must have exactly %d arguments", name, count)) error(string.format("%s must have exactly %d arguments", name, count))
return false return false
end
elseif arg_count < count then
error(string.format("%s must have at least %d arguments", name, count))
return false
end end
elseif arg_count < count then
error(string.format("%s must have at least %d arguments", name, count))
return false
end
return true return true
end end
---@param match (TSNode|nil)[] ---@param match (TSNode|nil)[]
@@ -49,17 +49,17 @@ end
---@param pred string[] ---@param pred string[]
---@return boolean|nil ---@return boolean|nil
query.add_predicate("nth?", function(match, _pattern, _bufnr, pred) query.add_predicate("nth?", function(match, _pattern, _bufnr, pred)
if not valid_args("nth?", pred, 2, true) then if not valid_args("nth?", pred, 2, true) then
return return
end end
local node = match[pred[2]] ---@type TSNode local node = match[pred[2]] ---@type TSNode
local n = tonumber(pred[3]) local n = tonumber(pred[3])
if node and node:parent() and node:parent():named_child_count() > n then if node and node:parent() and node:parent():named_child_count() > n then
return node:parent():named_child(n) == node return node:parent():named_child(n) == node
end end
return false return false
end, opts) end, opts)
---@param match (TSNode|nil)[] ---@param match (TSNode|nil)[]
@@ -68,22 +68,22 @@ end, opts)
---@param pred string[] ---@param pred string[]
---@return boolean|nil ---@return boolean|nil
query.add_predicate("is?", function(match, _pattern, bufnr, pred) query.add_predicate("is?", function(match, _pattern, bufnr, pred)
if not valid_args("is?", pred, 2) then if not valid_args("is?", pred, 2) then
return return
end end
-- Avoid circular dependencies -- Avoid circular dependencies
local locals = require "nvim-treesitter.locals" local locals = require "nvim-treesitter.locals"
local node = match[pred[2]] local node = match[pred[2]]
local types = { unpack(pred, 3) } local types = { unpack(pred, 3) }
if not node then if not node then
return true return true
end end
local _, _, kind = locals.find_definition(node, bufnr) local _, _, kind = locals.find_definition(node, bufnr)
return vim.tbl_contains(types, kind) return vim.tbl_contains(types, kind)
end, opts) end, opts)
---@param match (TSNode|nil)[] ---@param match (TSNode|nil)[]
@@ -92,18 +92,18 @@ end, opts)
---@param pred string[] ---@param pred string[]
---@return boolean|nil ---@return boolean|nil
query.add_predicate("kind-eq?", function(match, _pattern, _bufnr, pred) query.add_predicate("kind-eq?", function(match, _pattern, _bufnr, pred)
if not valid_args(pred[1], pred, 2) then if not valid_args(pred[1], pred, 2) then
return return
end end
local node = match[pred[2]] local node = match[pred[2]]
local types = { unpack(pred, 3) } local types = { unpack(pred, 3) }
if not node then if not node then
return true return true
end end
return vim.tbl_contains(types, node:type()) return vim.tbl_contains(types, node:type())
end, opts) end, opts)
---@param match (TSNode|nil)[] ---@param match (TSNode|nil)[]
@@ -112,19 +112,19 @@ end, opts)
---@param pred string[] ---@param pred string[]
---@return boolean|nil ---@return boolean|nil
query.add_directive("set-lang-from-mimetype!", function(match, _, bufnr, pred, metadata) query.add_directive("set-lang-from-mimetype!", function(match, _, bufnr, pred, metadata)
local capture_id = pred[2] local capture_id = pred[2]
local node = match[capture_id] local node = match[capture_id]
if not node then if not node then
return return
end end
local type_attr_value = vim.treesitter.get_node_text(node, bufnr) local type_attr_value = vim.treesitter.get_node_text(node, bufnr)
local configured = html_script_type_languages[type_attr_value] local configured = html_script_type_languages[type_attr_value]
if configured then if configured then
metadata["injection.language"] = configured metadata["injection.language"] = configured
else else
local parts = vim.split(type_attr_value, "/", {}) local parts = vim.split(type_attr_value, "/", {})
metadata["injection.language"] = parts[#parts] metadata["injection.language"] = parts[#parts]
end end
end, opts) end, opts)
---@param match (TSNode|nil)[] ---@param match (TSNode|nil)[]
@@ -133,16 +133,16 @@ end, opts)
---@param pred string[] ---@param pred string[]
---@return boolean|nil ---@return boolean|nil
query.add_directive("set-lang-from-info-string!", function(match, _, bufnr, pred, metadata) query.add_directive("set-lang-from-info-string!", function(match, _, bufnr, pred, metadata)
local capture_id = pred[2] local capture_id = pred[2]
local node = match[capture_id] local node = match[capture_id]
if not node then if not node then
return return
end end
local injection_alias = vim.treesitter.get_node_text(node, bufnr):lower()
metadata["injection.language"] = get_parser_from_markdown_info_string(injection_alias)
if not node.range then if not node.range then
return -- TODO: What is goin on here??? return -- TODO: What is goin on here???
end end
local injection_alias = vim.treesitter.get_node_text(node, bufnr):lower()
metadata["injection.language"] = get_parser_from_markdown_info_string(injection_alias)
end, opts) end, opts)
-- Just avoid some annoying warnings for this directive -- Just avoid some annoying warnings for this directive
@@ -156,15 +156,15 @@ query.add_directive("make-range!", function() end, opts)
---@param pred string[] ---@param pred string[]
---@return boolean|nil ---@return boolean|nil
query.add_directive("downcase!", function(match, _, bufnr, pred, metadata) query.add_directive("downcase!", function(match, _, bufnr, pred, metadata)
local id = pred[2] local id = pred[2]
local node = match[id] local node = match[id]
if not node then if not node then
return return
end end
local text = vim.treesitter.get_node_text(node, bufnr, { metadata = metadata[id] }) or "" local text = vim.treesitter.get_node_text(node, bufnr, { metadata = metadata[id] }) or ""
if not metadata[id] then if not metadata[id] then
metadata[id] = {} metadata[id] = {}
end end
metadata[id].text = string.lower(text) metadata[id].text = string.lower(text)
end, opts) end, opts)