From 05f2f402f867cc24fc130ff1299d8eed5d56213b Mon Sep 17 00:00:00 2001 From: Lukas Reineke Date: Mon, 7 Oct 2024 12:05:02 +0900 Subject: [PATCH] fix: don't allow empty scope There seems to be a bug in treesitter that allows an infinite loop of node parents, if the node is empty. IBL doesn't care about the node if it's empty anyway, so we can just ignore them. fix #930 --- lua/ibl/init.lua | 1 + lua/ibl/scope.lua | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/ibl/init.lua b/lua/ibl/init.lua index 0d3333e..85c41fc 100644 --- a/lua/ibl/init.lua +++ b/lua/ibl/init.lua @@ -244,6 +244,7 @@ M.refresh = function(bufnr) local scope_row_start, scope_col_start, scope_row_end, scope_col_end = -1, -1, -1, -1 local scope_index = -1 if scope then + ---@diagnostic disable-next-line: cast-local-type scope_row_start, scope_col_start, scope_row_end, scope_col_end = scope:range() scope_row_start, scope_col_start, scope_row_end = scope_row_start + 1, scope_col_start + 1, scope_row_end + 1 end diff --git a/lua/ibl/scope.lua b/lua/ibl/scope.lua index 122c170..2e7dcfe 100644 --- a/lua/ibl/scope.lua +++ b/lua/ibl/scope.lua @@ -72,7 +72,7 @@ M.get = function(bufnr, config) local include_node_types = utils.tbl_join(config.scope.include.node_type["*"] or {}, config.scope.include.node_type[lang] or {}) - while node do + while node and node:byte_length() > 0 do local type = node:type() if