summaryrefslogtreecommitdiffstatshomepage
path: root/runtime/lua/vim/treesitter/query.lua
AgeCommit message (Collapse)AuthorFiles
2026-03-30docs: fix syntax errors in examples #38606skewb1k1
2026-03-23refactor(treesitter)!: remove "all" option of Query:iter_matches #33070Gregory Anders1
This option was introduced to help with transitioning to the new behavior during the 0.11 release cycle with the intention of removing in 0.12.
2026-03-11docs: api, messages, lsp, trustJustin M. Keyes1
gen_vimdoc.lua: In prepare for the upcoming release, comment-out the "Experimental" warning for prerelease features.
2026-03-07refactor(lua): adapt to Stylua 2.4.0Christian Clason1
2026-02-12fix(treesitter): highlight group for EditQuery captures #36265Michele Campeotto1
fix(treesitter): more distinctive highlight for EditQuery captures Problem: EditQuery shows captures in the source buffer using the Title highlight group, which could be too similar to Normal. Solution: Use a virtual text diagnostic highlight group: they are displayed in a similar manner to the query captures so we can assume that the color scheme should have appropriate styling applied to make them visible.
2025-08-28perf: add on_range in treesitter highlightingvanaigr1
2025-07-28docs: lsp, ui events, dev guidance, osc7Justin M. Keyes1
fix #34981
2025-07-19fix(treesitter): ":EditQuery [lang]" with injected languages #34914Peter Cardenas1
Problem: `:EditQuery` command accepts a language argument, but it doesn't highlight properly for injected languages. Solution: - Fully parse with the root language and then filter the query on the child trees that are of the language requested. - Also support completion (`EditQuery <tab>`).
2025-07-08docs: tag of `:EditQuery` #34844Phạm Bình An1
Problem: - Running `:h :EditQuery` throws error `E149: Sorry, no help for :EditQuery` - vim_diff.txt miss an entry for `:EditQuery` Solution: - Make tag `[:EditQuery]()` right-aligned, similar to command `:Open` - Update vim_diff.txt
2025-06-22docs(treesitter): fix parameter list for `Query:iter_matches` (#34553)Luis Calle1
2025-06-13feat(treesitter)!: apply `offset!` directive to all captures #34383Riley Bruins1
This commit changes the `offset!` directive so that instead of setting a `metadata.range` value for the entire pattern, it will set a `metadata.offset` value. This offset will be applied to the range only in `vim.treesitter.get_range()`, rather than at directive application time. This allows the offset to be applied to any and all nodes captured by the given pattern, and removes the requirement that `#offset!` be applied to only a single node. The downside of this change is that plugins which read from `metadata.range` may be thrown off course, but such plugins should prefer `vim.treesitter.get_range()` when retrieving ranges anyway. Note that `#trim!` still sets `metadata.range`, and `vim.treesitter.get_range()` still reads from `metadata.range`, if it exists.
2025-06-06fix: type fixesLewis Russell1
Type fixes caught by emmylua
2025-06-06refactor(treesitter): avoid unnecessarily copying treeRodrigodd1
node:tree() now already copies the tree before returning it, for memory safety reasons.
2025-03-12feat(treesitter): allow `iter_captures` to accept `opts`Riley Bruins1
This matches the `iter_captures` functionality to the `iter_matches` functionality, allowing it to specify a match limit and start depth for the query iterator.
2025-03-11feat(treesitter): allow disabling captures and patterns on TSQuery (#32790)Ian Chamberlain1
Problem: Cannot disable individual captures and patterns in treesitter queries. Solution: * Expose the corresponding tree-sitter API functions for `TSQuery` object. * Add documentation for `TSQuery`. * Return the pattern ID from `get_captures_at_pos()` (and hence `:Inspect!`).
2025-03-02feat(comment): allow commentstring to be determined from node metadataRiley Bruins1
**Problem:** Some weird languages have different comment syntax depending on the location in the code, and we do not have a way to determine the correct `commentstring` for these special cases. **Solution:** Allow queries to specify `commentstring` values in metadata, allowing users/`nvim-treesitter` to provide a better commenting experience without hugely increasing the scope of the code in core.
2025-02-28fix(treesitter): correctly parse queries with combined injectionsRiley Bruins1
2025-02-25feat(treesitter): vertical conceal support for highlighterLuuk van Baal1
TSHighlighter now places marks for conceal_lines metadata. A new internal decor provider callback _on_conceal_line was added that instructs the highlighter to place conceal_lines marks whenever the editor needs to know whether a line is concealed. The bundled markdown queries use conceal_lines metadata to conceal code block fence lines.
2025-02-21perf(treesitter): only search for injections within the parse rangeRiley Bruins1
Co-authored-by: Jaehwang Jung <tomtomjhj@gmail.com>
2025-01-29feat(treesitter): support modelines in `query.set()` (#30257)Maria José Solano1
2025-01-27fix: resolve all remaining LuaLS diagnosticsLewis Russell1
2025-01-15fix(docs): replace `yxx` mappings with `g==` #31947Evgeni Chasnovski1
Problem: `yx` uses "y" prefix, which shadows a builtin operator. Solution: Use `g=` (in the form of `g==` currently), drawing from precedent of CTRL-= and 'tpope/vim-scriptease'.
2025-01-14refactor: use nvim.foo.bar format for autocommand groupsMaria José Solano1
2025-01-12feat(treesitter): async parsingRiley Bruins1
**Problem:** Parsing can be slow for large files, and it is a blocking operation which can be disruptive and annoying. **Solution:** Provide a function for asynchronous parsing, which accepts a callback to be run after parsing completes. Co-authored-by: Lewis Russell <lewis6991@gmail.com> Co-authored-by: Luuk van Baal <luukvbaal@gmail.com> Co-authored-by: VanaIgr <vanaigranov@gmail.com>
2025-01-12perf(treesitter): cache queries stronglyRiley Bruins1
**Problem:** Query parsing uses a weak cache which is invalidated frequently **Solution:** Make the cache strong, and invalidate it manually when necessary (that is, when `rtp` is changed or `query.set()` is called) Co-authored-by: Christian Clason <c.clason@uni-graz.at>
2025-01-09feat(docs): "yxx" runs Lua/Vimscript code examples #31904Riley Bruins1
`yxx` in Normal mode over a Lua or Vimscript code block section will execute the code. Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2025-01-06refactor: split predicates and directivesvanaigr1
2025-01-06perf(decor): join predicates and matches cachevanaigr1
2025-01-05feat(func): allow manual cache invalidation for _memoizeRiley Bruins1
This commit also adds some tests for the existing memoization functionality.
2025-01-01docs: misc #31479Justin M. Keyes1
2024-12-07fix(treesitter): #trim! range for nodes ending at col 0 #31488Riley Bruins1
Problem: char-wise folding for `#trim!` ranges are improperly calculated for nodes that end at column 0, due to the way `get_node_text` works. Solution: Add the blank line that `get_node_text` removes for for nodes ending at column 0. Also properly set column positions when performing linewise trims.
2024-12-06feat(treesitter): #trim! can trim all whitespaceRiley Bruins1
This commit also implements more generic trimming, acting on all whitespace (charwise) rather than just empty lines. It will unblock https://github.com/nvim-treesitter/nvim-treesitter/pull/3442 and allow for properly concealing markdown bullet markers regardless of indent width, e.g.
2024-10-27docs(treesitter): specify predicate boolean return valueRiley Bruins1
2024-09-29feat(treesitter)!: use return values in `language.add()`Christian Clason1
Problem: No clear way to check whether parsers are available for a given language. Solution: Make `language.add()` return `true` if a parser was successfully added and `nil` otherwise. Use explicit `assert` instead of relying on thrown errors.
2024-09-28fix(treesitter): specify success status in edit_query return valueRiley Bruins1
2024-09-28fix(treesitter): suppress get_parser warnings via opts.errorRiley Bruins1
2024-09-01feat(treesitter)!: default to correct behavior for quantified captures (#30193)Gregory Anders1
For context, see https://github.com/neovim/neovim/pull/24738. Before that PR, Nvim did not correctly handle captures with quantifiers. That PR made the correct behavior opt-in to minimize breaking changes, with the intention that the correct behavior would eventually become the default. Users can still opt-in to the old (incorrect) behavior for now, but this option will eventually be removed completely. BREAKING CHANGE: Any plugin which uses `Query:iter_matches()` must update their call sites to expect an array of nodes in the `match` table, rather than a single node.
2024-09-01docs(treesitter): annotate some tables as `TSMetadata`Yi Ming1
2024-05-16perf(treesitter): use child_containing_descendant() in has-ancestor? (#28512)vanaigr1
Problem: `has-ancestor?` is O(n²) for the depth of the tree since it iterates over each of the node's ancestors (bottom-up), and each ancestor takes O(n) time. This happens because tree-sitter's nodes don't store their parent nodes, and the tree is searched (top-down) each time a new parent is requested. Solution: Make use of new `ts_node_child_containing_descendant()` in tree-sitter v0.22.6 (which is now the minimum required version) to rewrite the `has-ancestor?` predicate in C to become O(n). For a sample file, decreases the time taken by `has-ancestor?` from 360ms to 6ms.
2024-05-14fix(treesitter): allow optional directive captures (#28664)Riley Bruins1
2024-03-27fix(treesitter): return correct match table in iter_captures()Lewis Russell1
2024-03-19refactor(treesitter): redesign query iteratingLewis Russell1
Problem: `TSNode:_rawquery()` is complicated, has known issues and the Lua and C code is awkwardly coupled (see logic with `active`). Solution: - Add `TSQueryCursor` and `TSQueryMatch` bindings. - Replace `TSNode:_rawquery()` with `TSQueryCursor:next_capture()` and `TSQueryCursor:next_match()` - Do more stuff in Lua - API for `Query:iter_captures()` and `Query:iter_matches()` remains the same. - `treesitter.c` no longer contains any logic related to predicates. - Add `match_limit` option to `iter_matches()`. Default is still 256.
2024-03-17fix(treesitter): revert to using iter_captures in highlighterLewis Russell1
Fixes #27895
2024-03-16refactor(lua): type annotationsLewis Russell1
2024-03-09docs: support inline markdownLewis Russell1
- Tags are now created with `[tag]()` - References are now created with `[tag]` - Code spans are no longer wrapped
2024-03-09feat!: remove deprecated functionsdundargoc1
2024-03-01docs: improve/add documentation of Lua typesLewis Russell1
- Added `@inlinedoc` so single use Lua types can be inlined into the functions docs. E.g. ```lua --- @class myopts --- @inlinedoc --- --- Documentation for some field --- @field somefield integer --- @param opts myOpts function foo(opts) end ``` Will be rendered as ``` foo(opts) Parameters: - {opts} (table) Object with the fields: - somefield (integer) Documentation for some field ``` - Marked many classes with with `@nodoc` or `(private)`. We can eventually introduce these when we want to.
2024-02-27feat(docs): replace lua2dox.luaLewis Russell1
Problem: The documentation flow (`gen_vimdoc.py`) has several issues: - it's not very versatile - depends on doxygen - doesn't work well with Lua code as it requires an awkward filter script to convert it into pseudo-C. - The intermediate XML files and filters makes it too much like a rube goldberg machine. Solution: Re-implement the flow using Lua, LPEG and treesitter. - `gen_vimdoc.py` is now replaced with `gen_vimdoc.lua` and replicates a portion of the logic. - `lua2dox.lua` is gone! - No more XML files. - Doxygen is now longer used and instead we now use: - LPEG for comment parsing (see `scripts/luacats_grammar.lua` and `scripts/cdoc_grammar.lua`). - LPEG for C parsing (see `scripts/cdoc_parser.lua`) - Lua patterns for Lua parsing (see `scripts/luacats_parser.lua`). - Treesitter for Markdown parsing (see `scripts/text_utils.lua`). - The generated `runtime/doc/*.mpack` files have been removed. - `scripts/gen_eval_files.lua` now instead uses `scripts/cdoc_parser.lua` directly. - Text wrapping is implemented in `scripts/text_utils.lua` and appears to produce more consistent results (the main contributer to the diff of this change).
2024-02-16fix(treesitter): correctly handle query quantifiers (#24738)Thomas Vigouroux1
Query patterns can contain quantifiers (e.g. (foo)+ @bar), so a single capture can map to multiple nodes. The iter_matches API can not handle this situation because the match table incorrectly maps capture indices to a single node instead of to an array of nodes. The match table should be updated to map capture indices to an array of nodes. However, this is a massively breaking change, so must be done with a proper deprecation period. `iter_matches`, `add_predicate` and `add_directive` must opt-in to the correct behavior for backward compatibility. This is done with a new "all" option. This option will become the default and removed after the 0.10 release. Co-authored-by: Christian Clason <c.clason@uni-graz.at> Co-authored-by: MDeiml <matthias@deiml.net> Co-authored-by: Gregory Anders <greg@gpanders.com>
2024-02-08refactor(treesitter): {start,stop} are optional in Query:iter_* methodsJongwook Choi1
Document that the `start` and `stop` parameters in `Query:iter_captures()` and `Query:iter_matches()` are optional. The tree-sitter lib has been bumped up to 0.20.9, so we also no longer need "Requires treesitter >= 0.20.9".