mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 03:08:13 +00:00
feat(scope): allow injected languages to be parsed by treesitter (#823)
## Description Adding a config flag to allow injected languages to be parsed by treesitter. This is crucial for languages like vue, which contain typescript or javascript in a script tag. When `treesitter.get_node` is not called with ignore_injections = false, the script tag is treated as a single block, which is not helpful, as it contains most code for languages like vue. ## Related Issue(s) - Fixes #430 ## Screenshots - See #430 --------- Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
This commit is contained in:
parent
fdfd70b918
commit
aba21ddc71
1 changed files with 8 additions and 2 deletions
|
@ -43,6 +43,7 @@ local defaults = {
|
||||||
-- detect scope based on treesitter.
|
-- detect scope based on treesitter.
|
||||||
-- falls back to indent based detection if not available
|
-- falls back to indent based detection if not available
|
||||||
enabled = true,
|
enabled = true,
|
||||||
|
injections = true, -- include language injections when detecting scope (useful for languages like `vue`)
|
||||||
---@type string[]|{enabled?:boolean}
|
---@type string[]|{enabled?:boolean}
|
||||||
blocks = {
|
blocks = {
|
||||||
enabled = false, -- enable to use the following blocks
|
enabled = false, -- enable to use the following blocks
|
||||||
|
@ -400,7 +401,7 @@ function TSScope:find(opts)
|
||||||
if not has_parser or parser == nil then
|
if not has_parser or parser == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
parser:parse(true)
|
parser:parse(opts.treesitter.injections)
|
||||||
|
|
||||||
local line = vim.fn.nextnonblank(opts.pos[1])
|
local line = vim.fn.nextnonblank(opts.pos[1])
|
||||||
line = line == 0 and vim.fn.prevnonblank(opts.pos[1]) or line
|
line = line == 0 and vim.fn.prevnonblank(opts.pos[1]) or line
|
||||||
|
@ -410,7 +411,12 @@ function TSScope:find(opts)
|
||||||
(vim.fn.getline(line):find("%S") or 1) - 1, -- find first non-space character
|
(vim.fn.getline(line):find("%S") or 1) - 1, -- find first non-space character
|
||||||
}
|
}
|
||||||
|
|
||||||
local node = vim.treesitter.get_node({ pos = pos, bufnr = opts.buf, lang = lang })
|
local node = vim.treesitter.get_node({
|
||||||
|
pos = pos,
|
||||||
|
bufnr = opts.buf,
|
||||||
|
lang = lang,
|
||||||
|
ignore_injections = not opts.treesitter.injections,
|
||||||
|
})
|
||||||
if not node then
|
if not node then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue