summaryrefslogtreecommitdiff
path: root/lua/nvim-treesitter/query_predicates.lua
diff options
context:
space:
mode:
authorMatthias Deiml <matthias@deiml.net>2022-06-26 18:02:29 +0200
committerGitHub <noreply@github.com>2022-06-26 18:02:29 +0200
commit002084b1bea4311fdac184f080206bf890937d80 (patch)
tree7215a635789883d0f7b00aca3d59a4f19a566b6e /lua/nvim-treesitter/query_predicates.lua
parentd810c386341fbf0d49895a2cdd6a2b63b945b71a (diff)
feat(markdown)!: switch to split parser (#3048)
* switch to split markdown parser with separate block and inline parsers to improve performance * add exclude_children! directive (useful for something like Injected markdown incorrectly highlights indented docstrings #2212) * split markdown queries into block and inline ones and add the injection for inline into block grammar * add include_dir option to parser configs (needed because the two grammars don't live in the repos root directory) BREAKING CHANGE: downstream queries need to be adapted to new parser
Diffstat (limited to 'lua/nvim-treesitter/query_predicates.lua')
-rw-r--r--lua/nvim-treesitter/query_predicates.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/lua/nvim-treesitter/query_predicates.lua b/lua/nvim-treesitter/query_predicates.lua
index be713304..75f0efc0 100644
--- a/lua/nvim-treesitter/query_predicates.lua
+++ b/lua/nvim-treesitter/query_predicates.lua
@@ -128,3 +128,28 @@ query.add_directive("downcase!", function(match, _, bufnr, pred, metadata)
metadata[key] = string.lower(text)
end
end)
+
+query.add_directive("exclude_children!", function(match, _pattern, _bufnr, pred, metadata)
+ local capture_id = pred[2]
+ local node = match[capture_id]
+ local start_row, start_col, end_row, end_col = node:range()
+ local ranges = {}
+ for i = 0, node:named_child_count() - 1 do
+ local child = node:named_child(i)
+ local child_start_row, child_start_col, child_end_row, child_end_col = child:range()
+ if child_start_row > start_row or child_start_col > start_col then
+ table.insert(ranges, {
+ start_row,
+ start_col,
+ child_start_row,
+ child_start_col,
+ })
+ end
+ start_row = child_end_row
+ start_col = child_end_col
+ end
+ if end_row > start_row or end_col > start_col then
+ table.insert(ranges, { start_row, start_col, end_row, end_col })
+ end
+ metadata.content = ranges
+end)