-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: empty metadata caused treesitter directives like offset to be ig…
…nored (#80)
- Loading branch information
1 parent
cf29fc2
commit 0fd09ca
Showing
2 changed files
with
35 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
M = {} | ||
|
||
M.iter_captures = function (node, source, query) | ||
if type(source) == "number" and source == 0 then | ||
source = vim.api.nvim_get_current_buf() | ||
end | ||
|
||
local raw_iter = node:_rawquery(query.query, true, 0, -1) | ||
local metadata = {} | ||
local function iter(end_line) | ||
local capture, captured_node, match = raw_iter() | ||
|
||
if match ~= nil then | ||
local active = query:match_preds(match, match.pattern, source) | ||
match.active = active | ||
if not active then | ||
return iter(end_line) -- tail call: try next match | ||
else | ||
-- if it has an active match, reset the metadata. | ||
-- then hopefully apply_directives can fill the metadata | ||
metadata = {} | ||
end | ||
query:apply_directives(match, match.pattern, source, metadata) | ||
end | ||
return capture, captured_node, metadata | ||
end | ||
return iter | ||
end | ||
|
||
|
||
return M |