aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter/languagetree.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2022-05-28 18:22:18 +0100
committerGitHub <noreply@github.com>2022-05-28 19:22:18 +0200
commiteab4d03a3264b2afaf803ed839fa25bc4e7acedd (patch)
treec7ffb19ab84792f2562273df931e759dc0e2209a /runtime/lua/vim/treesitter/languagetree.lua
parent081eb72a80afd83398465382171765bdeaf6dba5 (diff)
downloadrneovim-eab4d03a3264b2afaf803ed839fa25bc4e7acedd.tar.gz
rneovim-eab4d03a3264b2afaf803ed839fa25bc4e7acedd.tar.bz2
rneovim-eab4d03a3264b2afaf803ed839fa25bc4e7acedd.zip
fix(treesitter): offset directive associates range with capture (#18276)
Previously the `offset!` directive populated the metadata in such a way that the new range could be attributed to a specific capture. #14046 made it so the directive simply stored just the new range in the metadata and information about what capture the range is based from is lost. This change reverts that whilst also correcting the docs.
Diffstat (limited to 'runtime/lua/vim/treesitter/languagetree.lua')
-rw-r--r--runtime/lua/vim/treesitter/languagetree.lua21
1 files changed, 16 insertions, 5 deletions
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua
index 57d8c5fd21..5a05a29da8 100644
--- a/runtime/lua/vim/treesitter/languagetree.lua
+++ b/runtime/lua/vim/treesitter/languagetree.lua
@@ -295,6 +295,14 @@ function LanguageTree:included_regions()
return self._regions
end
+---@private
+local function get_node_range(node, id, metadata)
+ if metadata[id] and metadata[id].range then
+ return metadata[id].range
+ end
+ return { node:range() }
+end
+
--- Gets language injection points by language.
---
--- This is where most of the injection processing occurs.
@@ -327,10 +335,10 @@ function LanguageTree:_get_injections()
-- Allow for captured nodes to be used
if type(content) == 'number' then
- content = { match[content] }
+ content = { match[content]:range() }
end
- if content then
+ if type(content) == 'table' and #content >= 4 then
vim.list_extend(ranges, content)
end
end
@@ -351,7 +359,7 @@ function LanguageTree:_get_injections()
elseif name == 'combined' then
combined = true
elseif name == 'content' and #ranges == 0 then
- table.insert(ranges, node)
+ table.insert(ranges, get_node_range(node, id, metadata))
-- Ignore any tags that start with "_"
-- Allows for other tags to be used in matches
elseif string.sub(name, 1, 1) ~= '_' then
@@ -360,7 +368,7 @@ function LanguageTree:_get_injections()
end
if #ranges == 0 then
- table.insert(ranges, node)
+ table.insert(ranges, get_node_range(node, id, metadata))
end
end
end
@@ -397,7 +405,10 @@ function LanguageTree:_get_injections()
for _, entry in pairs(patterns) do
if entry.combined then
- table.insert(result[lang], vim.tbl_flatten(entry.regions))
+ local regions = vim.tbl_map(function(e)
+ return vim.tbl_flatten(e)
+ end, entry.regions)
+ table.insert(result[lang], regions)
else
for _, ranges in ipairs(entry.regions) do
table.insert(result[lang], ranges)