mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-20 12:20:02 -04:00
indent: introduce @ignore to avoid indenting some nodes (e.g. comments)
This commit is contained in:
parent
e6b8c5e680
commit
252472081e
1 changed files with 13 additions and 3 deletions
|
|
@ -35,6 +35,7 @@ local get_indents = utils.memoize_by_buf_tick(function(bufnr)
|
||||||
indents = get_map('@indent.node'),
|
indents = get_map('@indent.node'),
|
||||||
branches = get_map('@branch.node'),
|
branches = get_map('@branch.node'),
|
||||||
returns = get_map('@return.node'),
|
returns = get_map('@return.node'),
|
||||||
|
ignores = get_map('@ignore.node'),
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
@ -85,15 +86,24 @@ function M.get_indent(lnum)
|
||||||
node = node:parent()
|
node = node:parent()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local first = true
|
||||||
local prev_row = node:start()
|
local prev_row = node:start()
|
||||||
|
|
||||||
while node do
|
while node do
|
||||||
node = node:parent()
|
-- do not indent if we are inside an @ignore block
|
||||||
local row = node and node:start() or prev_row
|
if q.ignores[node_fmt(node)] and node:start() < lnum-1 and node:end_() > lnum-1 then
|
||||||
if q.indents[node_fmt(node)] and prev_row ~= row then
|
return -1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- do not indent the starting node, do not add multiple indent levels on single line
|
||||||
|
local row = node:start()
|
||||||
|
if not first and q.indents[node_fmt(node)] and prev_row ~= row then
|
||||||
indent = indent + indent_size
|
indent = indent + indent_size
|
||||||
prev_row = row
|
prev_row = row
|
||||||
end
|
end
|
||||||
|
|
||||||
|
node = node:parent()
|
||||||
|
first = false
|
||||||
end
|
end
|
||||||
|
|
||||||
return indent
|
return indent
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue