diff options
| author | Matthias Deiml <matthias@deiml.net> | 2022-06-26 18:02:29 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-26 18:02:29 +0200 |
| commit | 002084b1bea4311fdac184f080206bf890937d80 (patch) | |
| tree | 7215a635789883d0f7b00aca3d59a4f19a566b6e /lua | |
| parent | Chore: remove prefix from parser "location" property (diff) | |
| download | nvim-treesitter-002084b1bea4311fdac184f080206bf890937d80.tar nvim-treesitter-002084b1bea4311fdac184f080206bf890937d80.tar.gz nvim-treesitter-002084b1bea4311fdac184f080206bf890937d80.tar.bz2 nvim-treesitter-002084b1bea4311fdac184f080206bf890937d80.tar.lz nvim-treesitter-002084b1bea4311fdac184f080206bf890937d80.tar.xz nvim-treesitter-002084b1bea4311fdac184f080206bf890937d80.tar.zst nvim-treesitter-002084b1bea4311fdac184f080206bf890937d80.zip | |
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')
| -rw-r--r-- | lua/nvim-treesitter/parsers.lua | 15 | ||||
| -rw-r--r-- | lua/nvim-treesitter/query_predicates.lua | 25 |
2 files changed, 39 insertions, 1 deletions
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index dc02c9322..b24b6ce0c 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -528,9 +528,22 @@ list.hcl = { list.markdown = { install_info = { url = "https://github.com/MDeiml/tree-sitter-markdown", + location = "tree-sitter-markdown", files = { "src/parser.c", "src/scanner.cc" }, - branch = "main", + branch = "split_parser", + }, + maintainers = { "@MDeiml" }, + experimental = true, +} + +list.markdown_inline = { + install_info = { + url = "https://github.com/MDeiml/tree-sitter-markdown", + location = "tree-sitter-markdown-inline", + files = { "src/parser.c", "src/scanner.cc" }, + branch = "split_parser", }, + maintainers = { "@MDeiml" }, experimental = true, } diff --git a/lua/nvim-treesitter/query_predicates.lua b/lua/nvim-treesitter/query_predicates.lua index be713304c..75f0efc04 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) |
