neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit c3337e357a838aadf0ac40dd5bbc4dd0d1909b32
parent 3bdc3a1689477e1b4944919edfdf495b81c0724e
Author: Luuk van Baal <luukvbaal@gmail.com>
Date:   Tue, 25 Feb 2025 14:17:29 +0100

fix(treesitter): nil check query for has_conceal_line

Diffstat:
Mruntime/lua/vim/treesitter/highlighter.lua | 14++++++++++----
Mtest/functional/treesitter/highlight_spec.lua | 13+++++++++++++
2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua @@ -101,6 +101,13 @@ function TSHighlighter.new(tree, opts) end, }) + -- Enable conceal_lines if query exists for lang and has conceal_lines metadata. + local function set_conceal_lines(lang) + if not self._conceal_line and self:get_query(lang):query() then + self._conceal_line = self:get_query(lang):query().has_conceal_line + end + end + tree:register_cbs({ on_changedtree = function(...) self:on_changedtree(...) @@ -112,7 +119,7 @@ function TSHighlighter.new(tree, opts) end, on_child_added = function(child) child:for_each_tree(function(t) - self._conceal_line = self._conceal_line or self:get_query(t:lang()):query().has_conceal_line + set_conceal_lines(t:lang()) end) end, }, true) @@ -130,11 +137,10 @@ function TSHighlighter.new(tree, opts) if opts.queries then for lang, query_string in pairs(opts.queries) do self._queries[lang] = TSHighlighterQuery.new(lang, query_string) - self._conceal_line = self._conceal_line or self._queries[lang]:query().has_conceal_line + set_conceal_lines(lang) end end - self._conceal_line = self._conceal_line or self:get_query(tree:lang()):query().has_conceal_line - + set_conceal_lines(tree:lang()) self.orig_spelloptions = vim.bo[self.bufnr].spelloptions vim.bo[self.bufnr].syntax = '' diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua @@ -1298,3 +1298,16 @@ it('starting and stopping treesitter highlight in init.lua works #29541', functi -- legacy syntax highlighting is used screen:expect(hl_grid_legacy_c) end) + +it('no nil index for missing highlight query', function() + clear() + local cqueries = vim.uv.cwd() .. '/runtime/queries/c/' + os.rename(cqueries .. 'highlights.scm', cqueries .. '_highlights.scm') + finally(function() + os.rename(cqueries .. '_highlights.scm', cqueries .. 'highlights.scm') + end) + exec_lua([[ + local parser = vim.treesitter.get_parser(0, 'c') + vim.treesitter.highlighter.new(parser) + ]]) +end)