Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions plugin/hmts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,31 @@ 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
Comment thread
crisidev marked this conversation as resolved.

--- 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<string, TSNode>
---@param _ string
---@param bufnr integer
---@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
Expand Down Expand Up @@ -152,7 +169,10 @@ end
---@param predicate string[]
---@param metadata table<string, string>
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 })

Expand Down