mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	fix(treesitter): support multiple @injection.content captures
				
					
				
			Before, only the last capture's range would be counted for injection. Now all captured ranges will be counted in the ranges array. This is more intuitive, and also provides a nice solution/alternative to the "scoped injections" issue.
This commit is contained in:
		 Riley Bruins
					Riley Bruins
				
			
				
					committed by
					
						 Christian Clason
						Christian Clason
					
				
			
			
				
	
			
			
			 Christian Clason
						Christian Clason
					
				
			
						parent
						
							775e845d59
						
					
				
				
					commit
					8b41df185c
				
			| @@ -573,7 +573,10 @@ parent tree. The language injection query allows you to specify these | |||||||
| “injections” using the following captures: | “injections” using the following captures: | ||||||
|  |  | ||||||
|     • `@injection.content` - indicates that the captured node should have its |     • `@injection.content` - indicates that the captured node should have its | ||||||
|       contents re-parsed using another language. |       contents re-parsed using another language. If there are multiple | ||||||
|  |       `@injection.content` captures in one pattern, all ranges will be | ||||||
|  |       collected and parsed as one tree. This allows query authors to create | ||||||
|  |       "scoped" injections with injection query quantifiers. | ||||||
|     • `@injection.language` - indicates that the captured node’s text may |     • `@injection.language` - indicates that the captured node’s text may | ||||||
|       contain the name of a language that should be used to re-parse the |       contain the name of a language that should be used to re-parse the | ||||||
|       `@injection.content`. |       `@injection.content`. | ||||||
|   | |||||||
| @@ -1013,7 +1013,9 @@ function LanguageTree:_get_injection(match, metadata) | |||||||
|         local ft = vim.filetype.match({ filename = text }) |         local ft = vim.filetype.match({ filename = text }) | ||||||
|         lang = ft and resolve_lang(ft) |         lang = ft and resolve_lang(ft) | ||||||
|       elseif name == 'injection.content' then |       elseif name == 'injection.content' then | ||||||
|         ranges = get_node_ranges(node, self._source, metadata[id], include_children) |         for _, range in ipairs(get_node_ranges(node, self._source, metadata[id], include_children)) do | ||||||
|  |           ranges[#ranges + 1] = range | ||||||
|  |         end | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user