aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter
Commit message (Collapse)AuthorAge
* feat(treesitter): allow `iter_captures` to accept `opts`Riley Bruins2025-03-12
| | | | | | 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.
* feat(treesitter): allow disabling captures and patterns on TSQuery (#32790)Ian Chamberlain2025-03-11
| | | | | | | | | 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!`).
* fix: warn when :InspectTree on buffer with no parser #32783phanium2025-03-11
| | | | | Problem: `InspectTree` error on buffer without ts parser attached. Solution: show a more correct warning.
* feat(checkhealth): group parsers by name and path in outputEike2025-03-10
| | | | | | | | | Problem: :checkhealth vim.treesitter sorts parser entries solely by path, splitting duplicates and reducing clarity. Solution: Sort entries first by name, then by path, so that duplicates are grouped.
* feat(comment): allow commentstring to be determined from node metadataRiley Bruins2025-03-02
| | | | | | | | | | | **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.
* feat(treesitter): add more metadata to `language.inspect()` (#32657)Lewis Russell2025-03-01
| | | | | | | | | Problem: No way to check the version of a treesitter parser. Solution: Add version metadata (ABI 15 parsers only) as well as parser state count and supertype information (ABI 15) in `vim.treesitter.language.inspect()`. Also graduate the `abi_version` field, as this is now the official upstream name. --------- Co-authored-by: Christian Clason <c.clason@uni-graz.at>
* fix(marks): ineffective conceal_line callback optimization (#32662)luukvbaal2025-02-28
| | | | | | | Problem: _on_conceal_line callbacks are not invoked if callback has not let Nvim know it wants to receive them. But this may change on factors other than what is currently checked (changed buffer). Solution: Forego this optimization, callback is still guarded behind 'conceallevel'.
* fix(treesitter): correctly parse queries with combined injectionsRiley Bruins2025-02-28
|
* fix(treesitter): nil check query for has_conceal_lineLuuk van Baal2025-02-25
|
* feat(treesitter): vertical conceal support for highlighterLuuk van Baal2025-02-25
| | | | | | | | 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.
* refactor(treesitter): simplify parsing coroutine logicRiley Bruins2025-02-23
| | | | | | | | | Lua coroutines can yield across non-coroutine function boundaries, meaning that we don't need to wrap each helper function in a coroutine and resume it within `_parse()`. If we just have them yield when appropriate, this will be caught by the top level `_parse()` coroutine, and resuming the `_parse()` will resume from the position in the helper function where we yielded last.
* feat(treesitter): table of contents for checkhealth, markdown (#32282)Christian Clason2025-02-22
| | | | | | | | | | | Problem: It's difficult to navigate large structured text files (vim help, checkhealth, Markdown). Solution: Support `gO` for table of contents and `]]`/`[[` for moving between headings for all these filetypes using treesitter queries. Refactor: colorization of highlight groups is moved to the `help` ftplugin while headings-related functionality is implemented in a private `vim.treesitter` module for possible future use for other filetypes.
* perf(treesitter): don't block when finding injection rangesRiley Bruins2025-02-21
| | | | | | | | | | | **Problem:** Currently, parsing is asynchronous, but it involves a (sometimes lengthy) step which finds all injection ranges for a tree by iterating over that language's injection queries. This causes edits in large files to be extremely slow, and also causes a long stutter during the initial parse of a large file. **Solution:** Break up the injection query iteration over multiple event loop iterations.
* fix(treesitter): `TSNode:field()` returns all children with the given fieldRiley Bruins2025-02-21
|
* perf(treesitter): only search for injections within the parse rangeRiley Bruins2025-02-21
| | | | Co-authored-by: Jaehwang Jung <tomtomjhj@gmail.com>
* fix(treesitter): don't spam query errors in the highlighterRiley Bruins2025-02-19
| | | | | | | | **Problem:** An erroneous query in the treesitter highlighter gives a deluge of errors that makes the editor almost unusable. **Solution:** Detach the highlighter after an error is detected, so that it only gets displayed once (per highlighter instance).
* fix(treesitter): avoid computing fold levels for empty bufferLuuk van Baal2025-02-19
| | | | | | | | Problem: Computing fold levels for an empty buffer (somehow) breaks the parser state, resulting in a broken highlighter and foldexpr. Cached foldexpr parser is invalid after filetype has changed. Solution: Avoid computing fold levels for empty buffer. Clear cached foldinfos upon `FileType`.
* fix(treesitter): separately track the number of valid regionsRiley Bruins2025-02-17
| | | | | | We need to add a separate variable to keep track of this information, since we cannot read the length of the valid regions table itself, since it has holes.
* fix(treesitter): detect trees with outdated regions in `is_valid()`Riley Bruins2025-02-11
|
* feat(treesitter): show which nodes are missing in InspectTreeRiley Bruins2025-02-05
| | | | | | | | Now `:InspectTree` will show missing nodes as e.g. `(MISSING identifier)` or `(MISSING ";")` rather than just `(identifier)` or `";"`. This is doable because the `MISSING` keyword is now valid query syntax. Co-authored-by: Christian Clason <c.clason@uni-graz.at>
* feat(treesitter): allow LanguageTree:is_valid() to accept a rangeRiley Bruins2025-02-02
| | | | | | When given, only that range will be checked for validity rather than the entire tree. This is used in the highlighter to save CPU cycles since we only need to parse a certain region at a time anyway.
* refactor(treesitter): use coroutines for resuming _parse() logicRiley Bruins2025-02-02
| | | | | | This means that all work previously done by a `_parse()` iteration will be kept in future iterations. This prevents it from running indefinitely in some cases where the file is very large and there are 2+ injections.
* refactor(treesitter): always return valid range from parse() #32273Riley Bruins2025-02-02
| | | | | | | | | | | Problem: When running an initial parse, parse() returns an empty table rather than an actual range. In `languagetree.lua`, we manually check if a parse was incremental to determine the changed parse region. Solution: - Always return a range (in the C side) from parse(). - Simplify the language tree code a bit. - Logger no longer shows empty ranges on the initial parse.
* refactor(treesitter): drop `LanguageTree._has_regions` #32274Riley Bruins2025-02-02
| | | | | | | | | | | | | | | | This simplifies some logic in `languagetree.lua`, removing the need for `_has_regions`, and removing side effects in `:included_regions()`. Before: - Edit is made which sets `_regions = nil` - Upon the next call to `included_regions()` (usually right after we marked `_regions` as `nil` due to an `_iter_regions()` call), if `_regions` is nil, we repopulate the table (as long as the tree actually has regions) After: - Edit is made which resets `_regions` if it exists - `included_regions()` no longer needs to perform this logic itself, and also no longer needs to read a `_has_regions` variable
* fix(treesitter): nil access when running string parser asyncRiley Bruins2025-02-01
|
* docs: miscdundargoc2025-01-30
| | | | | | | | | Co-authored-by: Dustin S. <dstackmasta27@gmail.com> Co-authored-by: Ferenc Fejes <fejes@inf.elte.hu> Co-authored-by: Maria José Solano <majosolano99@gmail.com> Co-authored-by: Yochem van Rosmalen <git@yochem.nl> Co-authored-by: brianhuster <phambinhanctb2004@gmail.com> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
* fix(treesitter): stop async parsing if buffer is invalidnotomo2025-01-29
| | | | | Problem: Error occurs if delete buffer in the middle of parsing. Solution: Check if buffer is valid in parsing.
* fix(treesitter) Set modeline=false in TSHighlighter:destroy (#32234)Daniel Petrovic2025-01-29
| | | | | | | | | | Problem: `TSHighlighter:destroy()` causes double-processing of the modeline and failure of `b:undo_ftplugin`. Solution: Disable modeline in `TSHighlighter:destroy()` by setting `modeline=false` if executing `syntaxset` autocommands for the `FileType` event. Co-authored-by: Daniel Petrovic <daniel.petrovic@ebcont.com>
* feat(treesitter): support modelines in `query.set()` (#30257)Maria José Solano2025-01-29
|
* fix(treesitter): recalculate folds on VimEnter #32240Riley Bruins2025-01-28
| | | | | | | | | | **Problem:** In the case where the user sets the treesitter foldexpr upon startup in their `init.lua`, the fold info will be calculated before the parser has been loaded in, meaning folds will be properly calculated until edits or `:e`. **Solution:** Refresh fold information upon `VimEnter` as a sanity check to ensure that a parser really doesn't exist before always returning `'0'` in the foldexpr.
* fix(treesitter): empty queries can disable injections (#31748)Riley Bruins2025-01-28
| | | | | | | | | | | | **Problem:** Currently, if users want to efficiently disable injections, they have to delete the injection query files at their runtime path. This is because we only check for existence of the files before running the query over the entire buffer. **Solution:** Check for existence of query files, *and* that those files actually have captures. This will allow users to just comment out existing queries (or better yet, just add their own injection query to `~/.config/nvim` which contains only comments) to disable running the query over the entire buffer (a potentially slow operation)
* fix(treesitter): avoid computing foldlevels for reloaded buffer #32233luukvbaal2025-01-28
|
* docs(treesitter): fix TSNode:range() type signature #32224Riley Bruins2025-01-27
| | | | Uses an overload to properly show the different return type based on the input parameter.
* fix: resolve all remaining LuaLS diagnosticsLewis Russell2025-01-27
|
* build(deps)!: bump tree-sitter to HEAD, wasmtime to v29.0.1 (#32200)Christian Clason2025-01-27
| | | | | Breaking change: `ts_node_child_containing_descendant()` was removed Breaking change: tree-sitter 0.25 (HEAD) required
* fix(treesitter): compute folds on_changedtree only if not nilKonrad Malik2025-01-20
|
* docs(treesitter): expose LanguageTree:parent() #32108Jaehwang Jung2025-01-20
| | | | | Plugins may want to climb up the LanguageTree. Also add missing type annotations for other methods.
* fix(treesitter): clean up parsing queueJaehwang Jung2025-01-19
|
* fix(docs): replace `yxx` mappings with `g==` #31947Evgeni Chasnovski2025-01-15
| | | | | | | | 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'.
* Merge #32001 from MariaSolOs/consistent-namespacesJustin M. Keyes2025-01-15
|\
| * refactor: use nvim.foo.bar format for autocommand groupsMaria José Solano2025-01-14
| |
| * refactor: use nvim.foo.bar format for namespacesMaria José Solano2025-01-14
| |
* | perf(treesitter): calculate folds asynchronouslyRiley Bruins2025-01-14
|/ | | | | | | | | **Problem:** The treesitter `foldexpr` runs synchronous parses to calculate fold levels, which eliminates async parsing performance in the highlighter. **Solution:** Migrate the `foldexpr` to also calculate and apply fold levels asynchronously.
* feat(treesitter)!: don't parse tree in get_parser() or start()Riley Bruins2025-01-12
| | | | | | | | | | **Problem:** `vim.treesitter.get_parser()` and `vim.treesitter.start()` both parse the tree before returning it. This is problematic because if this is a sync parse, it will stall the editor on large files. If it is an async parse, the functions return stale trees. **Solution:** Remove this parsing side effect and leave it to the user to parse the returned trees, either synchronously or asynchronously.
* feat(treesitter): async parsingRiley Bruins2025-01-12
| | | | | | | | | | | | **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>
* perf(treesitter): cache queries stronglyRiley Bruins2025-01-12
| | | | | | | | | | **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>
* fix(treesitter): don't return error message on success #31955Guilherme Soares2025-01-10
| | | | | | | | Problem: The `vim.treesitter.language.add` function returns a error message even when it succeeds. Solution: Don't return error message on success.
* refactor(treesitter.foldexpr): remove unused parse_injections parameterRiley Bruins2025-01-10
|
* feat(docs): "yxx" runs Lua/Vimscript code examples #31904Riley Bruins2025-01-09
| | | | | `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>
* perf(treesitter): don't fetch parser for each fold lineRiley Bruins2025-01-07
| | | | | | | | | | | | | | **Problem:** The treesitter `foldexpr` calls `get_parser()` for each line in the buffer when calculating folds. This can be incredibly slow for buffers where a parser cannot be found (because the result is not cached), and exponentially more so when the user has many `runtimepath`s. **Solution:** Only fetch the parser when it is needed; that is, only when initializing fold data for a buffer. Co-authored-by: Jongwook Choi <wookayin@gmail.com> Co-authored-by: Justin M. Keyes <justinkz@gmail.com>