Skip to content

Commit bc6b808

Browse files
committed
improve treesitter for blank line
1 parent b51cd09 commit bc6b808

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lua/indentmini/init.lua

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,19 @@ local function make_snapshot(lnum)
8181
if is_empty and context.has_ts then
8282
local node = treesitter.get_node({ pos = { lnum - 1, 0 } })
8383
if node then
84-
context.tree_node_type = node:tree():root():type() or context.tree_node_type
85-
if node:type() == context.tree_node_type then
86-
local packed = pack_snapshot(true, 0, 0)
87-
context.snapshot[lnum] = packed
88-
return unpack_snapshot(packed)
84+
context.tree_root = context.tree_root or node:tree():root():type()
85+
local indent = 0
86+
if context.tree_root and node:type() ~= context.tree_root then
87+
local parent = node:parent()
88+
if parent then
89+
local p_srow = parent:range()
90+
indent = get_indent_lnum(p_srow + 1)
91+
indent = indent + context.step
92+
end
8993
end
94+
local packed = pack_snapshot(true, indent, indent)
95+
context.snapshot[lnum] = packed
96+
return unpack_snapshot(packed)
9097
end
9198
end
9299

0 commit comments

Comments
 (0)