Skip to content

Commit

Permalink
Get all named child nodes in comment
Browse files Browse the repository at this point in the history
Removed the code in cycle.lua to consider columns since we are using the
root node, so multiple comment (tag) nodes will have the same root, i.e.
the row/column and text will be the same for all comment (tag) nodes
  • Loading branch information
ram02z committed Aug 7, 2022
1 parent 6c3fa2d commit 22f27a6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
30 changes: 16 additions & 14 deletions lua/dev_comments/comments.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,22 @@ local finder = function(bufnr, results, opts)

comment_lang_tree:for_each_tree(function(tree)
local root_node = tree:root()
local child_node = root_node:named_child()
if child_node and child_node:type() == "tag" then
local tag = utils.get_node_text(child_node:named_child(0), bufnr)
local user = utils.get_node_text(child_node:named_child(1), bufnr)
if
(#opts.tags == 0 or vim.tbl_contains(opts.tags, tag))
and (#opts.users == 0 or vim.tbl_contains(opts.users, user))
then
table.insert(results, {
node = root_node,
tag = tag,
user = user,
bufnr = bufnr,
})
for child_node in root_node:iter_children() do
if child_node:named() and child_node:type() == "tag" then
local tag = utils.get_node_text(child_node:named_child(0), bufnr)
local user = utils.get_node_text(child_node:named_child(1), bufnr)
if
(#opts.tags == 0 or vim.tbl_contains(opts.tags, tag))
and (#opts.users == 0 or vim.tbl_contains(opts.users, user))
then
-- FIXME: if a comment node contains two tag nodes, we will get the text of the first node
table.insert(results, {
node = root_node,
tag = tag,
user = user,
bufnr = bufnr,
})
end
end
end
end)
Expand Down
16 changes: 6 additions & 10 deletions lua/dev_comments/cycle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ local function next_dev_comment(wrap, opts, forward)

wrap = vim.F.if_nil(wrap, false)

-- assumes results are already ordered by row
-- assumes results are in ascending line order
local results = comments.generate(opts)
if #results == 0 then
return
end

local row, col = unpack(vim.api.nvim_win_get_cursor(0))
local row, _ = unpack(vim.api.nvim_win_get_cursor(0))

local start_i, end_i, inc_i
if forward then
Expand All @@ -33,14 +33,10 @@ local function next_dev_comment(wrap, opts, forward)
local entry = results[i]
node_row, node_col = entry.node:range()
node_row = node_row + 1
if forward and row <= node_row then
if row ~= node_row or col > node_col then
return { node_row, node_col }
end
elseif not forward and row >= node_row then
if row ~= node_row or col < node_col then
return { node_row, node_col }
end
if forward and row < node_row then
return { node_row, node_col }
elseif not forward and row > node_row then
return { node_row, node_col }
end
end

Expand Down

0 comments on commit 22f27a6

Please sign in to comment.