mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
feat(treesitter): add @injection.filename
Problem: Injecting languages for file redirects (e.g., in bash) is not possible. Solution: Add `@injection.filename` capture that is piped through `vim.filetype.match({ filename = node_text })`; the resulting filetype (if not `nil`) is then resolved as a language (either directly or through the list maintained via `vim.treesitter.language.register()`). Note: `@injection.filename` is a non-standard capture introduced by Helix; having two editors implement it makes it likely to be upstreamed.
This commit is contained in:
@ -809,6 +809,10 @@ function LanguageTree:_get_injection(match, metadata)
|
||||
if name == 'injection.language' then
|
||||
local text = vim.treesitter.get_node_text(node, self._source, { metadata = metadata[id] })
|
||||
lang = resolve_lang(text)
|
||||
elseif name == 'injection.filename' then
|
||||
local text = vim.treesitter.get_node_text(node, self._source, { metadata = metadata[id] })
|
||||
local ft = vim.filetype.match({ filename = text })
|
||||
lang = ft and resolve_lang(ft)
|
||||
elseif name == 'injection.content' then
|
||||
ranges = get_node_ranges(node, self._source, metadata[id], include_children)
|
||||
end
|
||||
|
Reference in New Issue
Block a user