diff --git a/plugin/hmts.lua b/plugin/hmts.lua index 8514070..0cfb2ae 100644 --- a/plugin/hmts.lua +++ b/plugin/hmts.lua @@ -117,6 +117,19 @@ local function find_filename_in_parent_node(path_node, bufnr) end end +--- Neovim 0.12 dropped the `all = false` directive mode, so `match[capture]` is now +--- always a list of nodes instead of a single node. Resolve to the actual node. +---@param captured TSNode|TSNode[]|nil +---@return TSNode|nil +local is_list = vim.islist or vim.tbl_islist + +local function resolve_node(captured) + if is_list(captured) then + return captured[#captured] + end + return captured +end + --- Checks if the given capture is located at the end of the given nix path. Every node can be matched by a regex. ---@param match table ---@param _ string @@ -124,7 +137,11 @@ end ---@param predicate string[] ---@return boolean local function hmts_path_handler(match, _, bufnr, predicate) - local node = match[predicate[2]]:parent() + local capture = resolve_node(match[predicate[2]]) + if capture == nil then + return false + end + local node = capture:parent() local target_path = vim.list_slice(predicate, 3, nil) while node do @@ -152,7 +169,10 @@ end ---@param predicate string[] ---@param metadata table local function hmts_inject_handler(match, _, bufnr, predicate, metadata) - local path_node = match[predicate[2]] + local path_node = resolve_node(match[predicate[2]]) + if path_node == nil then + return + end local filename = find_filename_in_parent_node(path_node, bufnr) local alias = vim.filetype.match({ filename = filename })