aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter/query.lua
diff options
context:
space:
mode:
authorRiley Bruins <ribru17@hotmail.com>2025-02-13 16:57:44 -0800
committerChristian Clason <ch.clason+github@icloud.com>2025-02-21 09:56:21 +0100
commit562056c87573a532a0e670952d23d77026eeae28 (patch)
treeaf92dc7f3d4c91dd2ff5475a8bec2999bc5cd809 /runtime/lua/vim/treesitter/query.lua
parentb533c0f222ed8815803cc4a948cc8d30d43763d1 (diff)
downloadrneovim-562056c87573a532a0e670952d23d77026eeae28.tar.gz
rneovim-562056c87573a532a0e670952d23d77026eeae28.tar.bz2
rneovim-562056c87573a532a0e670952d23d77026eeae28.zip
perf(treesitter): only search for injections within the parse range
Co-authored-by: Jaehwang Jung <tomtomjhj@gmail.com>
Diffstat (limited to 'runtime/lua/vim/treesitter/query.lua')
-rw-r--r--runtime/lua/vim/treesitter/query.lua10
1 files changed, 8 insertions, 2 deletions
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua
index 10fb82e533..d26aa8e604 100644
--- a/runtime/lua/vim/treesitter/query.lua
+++ b/runtime/lua/vim/treesitter/query.lua
@@ -30,9 +30,11 @@ end
--- Splits the query patterns into predicates and directives.
---@param patterns table<integer, (integer|string)[][]>
---@return table<integer, vim.treesitter.query.ProcessedPattern>
+---@return boolean
local function process_patterns(patterns)
---@type table<integer, vim.treesitter.query.ProcessedPattern>
local processed_patterns = {}
+ local has_combined = false
for k, pattern_list in pairs(patterns) do
---@type vim.treesitter.query.ProcessedPredicate[]
@@ -47,6 +49,9 @@ local function process_patterns(patterns)
if is_directive(pred_name) then
table.insert(directives, pattern)
+ if vim.deep_equal(pattern, { 'set!', 'injection.combined' }) then
+ has_combined = true
+ end
else
local should_match = true
if pred_name:match('^not%-') then
@@ -60,7 +65,7 @@ local function process_patterns(patterns)
processed_patterns[k] = { predicates = predicates, directives = directives }
end
- return processed_patterns
+ return processed_patterns, has_combined
end
---@nodoc
@@ -71,6 +76,7 @@ end
---@field captures string[] list of (unique) capture names defined in query
---@field info vim.treesitter.QueryInfo query context (e.g. captures, predicates, directives)
---@field query TSQuery userdata query object
+---@field has_combined_injections boolean whether the query contains combined injections
---@field private _processed_patterns table<integer, vim.treesitter.query.ProcessedPattern>
local Query = {}
Query.__index = Query
@@ -90,7 +96,7 @@ function Query.new(lang, ts_query)
patterns = query_info.patterns,
}
self.captures = self.info.captures
- self._processed_patterns = process_patterns(self.info.patterns)
+ self._processed_patterns, self.has_combined_injections = process_patterns(self.info.patterns)
return self
end