mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	fix(treesitter): nil check query for has_conceal_line
This commit is contained in:
		 Luuk van Baal
					Luuk van Baal
				
			
				
					committed by
					
						 Christian Clason
						Christian Clason
					
				
			
			
				
	
			
			
			 Christian Clason
						Christian Clason
					
				
			
						parent
						
							3bdc3a1689
						
					
				
				
					commit
					c3337e357a
				
			| @@ -101,6 +101,13 @@ function TSHighlighter.new(tree, opts) | |||||||
|     end, |     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({ |   tree:register_cbs({ | ||||||
|     on_changedtree = function(...) |     on_changedtree = function(...) | ||||||
|       self:on_changedtree(...) |       self:on_changedtree(...) | ||||||
| @@ -112,7 +119,7 @@ function TSHighlighter.new(tree, opts) | |||||||
|     end, |     end, | ||||||
|     on_child_added = function(child) |     on_child_added = function(child) | ||||||
|       child:for_each_tree(function(t) |       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) | ||||||
|     end, |     end, | ||||||
|   }, true) |   }, true) | ||||||
| @@ -130,11 +137,10 @@ function TSHighlighter.new(tree, opts) | |||||||
|   if opts.queries then |   if opts.queries then | ||||||
|     for lang, query_string in pairs(opts.queries) do |     for lang, query_string in pairs(opts.queries) do | ||||||
|       self._queries[lang] = TSHighlighterQuery.new(lang, query_string) |       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 | ||||||
|   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 |   self.orig_spelloptions = vim.bo[self.bufnr].spelloptions | ||||||
|  |  | ||||||
|   vim.bo[self.bufnr].syntax = '' |   vim.bo[self.bufnr].syntax = '' | ||||||
|   | |||||||
| @@ -1298,3 +1298,16 @@ it('starting and stopping treesitter highlight in init.lua works #29541', functi | |||||||
|   -- legacy syntax highlighting is used |   -- legacy syntax highlighting is used | ||||||
|   screen:expect(hl_grid_legacy_c) |   screen:expect(hl_grid_legacy_c) | ||||||
| end) | 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) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user