mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-07 22:10:01 -04:00
fix: off-by-one errors in indent calculation
This commit is contained in:
parent
1affb20c0e
commit
6407d54092
2 changed files with 6 additions and 7 deletions
|
|
@ -54,7 +54,8 @@ function M.get_indent(lnum)
|
|||
return -1
|
||||
end
|
||||
|
||||
local root, _, lang_tree = tsutils.get_root_for_position(lnum, 0, parser)
|
||||
-- get_root_for_position is 0-based.
|
||||
local root, _, lang_tree = tsutils.get_root_for_position(lnum - 1, 0, parser)
|
||||
|
||||
-- Not likely, but just in case...
|
||||
if not root then
|
||||
|
|
@ -114,8 +115,10 @@ function M.get_indent(lnum)
|
|||
local prev_row = node:start()
|
||||
|
||||
while node do
|
||||
-- do not indent if we are inside an @ignore block
|
||||
if q.ignores[node_fmt(node)] and node:start() < lnum - 1 and node:end_() > lnum - 1 then
|
||||
-- Do not indent if we are inside an @ignore block.
|
||||
-- If a node spans from L1,C1 to L2,C2, we know that lines where L1 < line <= L2 would
|
||||
-- have their indentations contained by the node.
|
||||
if q.ignores[node_fmt(node)] and node:start() < lnum - 1 and lnum - 1 <= node:end_() then
|
||||
return -1
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -13,14 +13,10 @@ describe("indent Python:", function()
|
|||
run:whole_file(".", {
|
||||
expected_failures = {
|
||||
"./aligned_indent.py",
|
||||
"./basic_blocks.py",
|
||||
"./branches.py",
|
||||
"./control_flow.py",
|
||||
"./hanging_indent.py",
|
||||
"./join_lines.py",
|
||||
"./nested_collections.py",
|
||||
"./strings.py",
|
||||
"./control_flow.py",
|
||||
},
|
||||
})
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue