From d65e226382a1eee585dcfe55f53beb93554cd497 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Wed, 25 Jun 2025 21:22:57 +0200 Subject: [PATCH] fix(indent-hints): prevent nil function call changed with nvim 0.11 "Query:iter_matches() correctly returns all matching nodes in a match instead of only the last node. This means that the returned table maps capture IDs to a list of nodes that need to be iterated over. For backwards compatibility, an option all=false (only return the last matching node) is provided that will be removed in a future release." https://neovim.io/doc/user/news-0.11.html --- lua/helm-ls/conceal.lua | 3 +++ lua/helm-ls/indent-hints.lua | 31 ++++++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/lua/helm-ls/conceal.lua b/lua/helm-ls/conceal.lua index 38399f6..716d02b 100644 --- a/lua/helm-ls/conceal.lua +++ b/lua/helm-ls/conceal.lua @@ -85,6 +85,9 @@ end local conceal_templates_with_hover = function() local bufnr = api.nvim_get_current_buf() local parser = vim.treesitter.get_parser(bufnr, vim.bo.filetype) + if parser == nil then + return + end local root = parser:parse()[1]:root() local query = vim.treesitter.query.parse( diff --git a/lua/helm-ls/indent-hints.lua b/lua/helm-ls/indent-hints.lua index 0ab60dd..03a6cf4 100644 --- a/lua/helm-ls/indent-hints.lua +++ b/lua/helm-ls/indent-hints.lua @@ -50,6 +50,9 @@ end local add_indent_hints = function() local bufnr = vim.api.nvim_get_current_buf() local parser = vim.treesitter.get_parser(bufnr, vim.bo.filetype) + if parser == nil then + return + end local root = parser:parse()[1]:root() local query = vim.treesitter.query.parse( @@ -72,22 +75,24 @@ local add_indent_hints = function() end vim.api.nvim_buf_clear_namespace(0, ns_id, math.max(start_line - 1, 0), end_line + 2) - for _, match in query:iter_matches(root, bufnr, start_line, end_line) do + for _, match in query:iter_matches(root, bufnr, start_line, end_line, { all = true }) do local new_line_indent = false - for id, node in pairs(match) do + for id, nodes in pairs(match) do local name = query.captures[id] - local node_content = vim.treesitter.get_node_text(node, bufnr) - if name == "args" then - -- parse original_text to int - local indent_count = tonumber(node_content) - if not indent_count then - return + for _, node in ipairs(nodes) do + local node_content = vim.treesitter.get_node_text(node, bufnr) + if name == "args" then + -- parse original_text to int + local indent_count = tonumber(node_content) + if not indent_count then + return + end + + local start_row = node:range() + show_hint(start_row + (new_line_indent and 1 or 0), indent_count) + elseif name == "func" then + new_line_indent = node_content == "nindent" end - - local start_row = node:range() - show_hint(start_row + (new_line_indent and 1 or 0), indent_count) - elseif name == "func" then - new_line_indent = node_content == "nindent" end end end