Skip to content

fix(indent): Don't check indent on nil treesitter nodes #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lua/hlchunk/utils/indentHelper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,22 @@ local function get_rows_indent_by_treesitter(range)
local bufnr = range.bufnr
for i = range.start, range.finish, 1 do
local t1 = vim.api.nvim_buf_call(bufnr, function()
return ts_indent.get_indent(i + 1)
local ok, indent = pcall(ts_indent.get_indent, i + 1)
return ok and indent or nil
end)

if t1 == nil then
goto continue
end

local t2 = cFunc.get_indent(bufnr, i)
local line_len = cFunc.get_line_len(bufnr, i)
local indent = math.min(t1, t2)
if indent == 0 and line_len == 0 then
indent = get_virt_indent(bufnr, i)
end
rows_indent[i] = indent
::continue::
end

return indentHelper.ROWS_INDENT_RETCODE.OK, rows_indent
Expand Down