aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter
Commit message (Collapse)AuthorAge
* 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>
* refactor(treesitter): simplify condition #31889Riley Bruins2025-01-06
|
* refactor: split predicates and directivesvanaigr2025-01-06
|
* perf(decor): join predicates and matches cachevanaigr2025-01-06
|
* feat(func): allow manual cache invalidation for _memoizeRiley Bruins2025-01-05
| | | | | This commit also adds some tests for the existing memoization functionality.
* docs: misc #31479Justin M. Keyes2025-01-01
|
* fix(treesitter.foldexpr): only refresh valid buffersIgor2024-12-29
| | | | | | | | | Problem: autocmd to refresh folds always uses the current buffer if the option type is local. However, the current buffer may not have a parser, and thus the assert that checks for a parser could fail. Solution: check if the foldinfo contains the buffer, and only refresh if so.
* fix(treesitter.foldexpr): refresh in the buffers affected by OptionSetJaehwang Jung2024-12-29
|
* fix(treesitter): #trim! range for nodes ending at col 0 #31488Riley Bruins2024-12-07
| | | | | | | | | 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.
* feat(treesitter): #trim! can trim all whitespaceRiley Bruins2024-12-06
| | | | | | | | | | 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.
* feat(lsp): support `textDocument/foldingRange` (#31311)Yi Ming2024-11-29
| | | | | | | | | | | | | | | | | | | * refactor(shared): extract `vim._list_insert` and `vim._list_remove` * feat(lsp): add `vim.lsp.foldexpr()` * docs(lsp): add a todo for state management * feat(lsp): add `vim.lsp.folding_range.foldclose()` * feat(lsp): schedule `foldclose()` if the buffer is not up-to-date * feat(lsp): add `vim.lsp.foldtext()` * feat(lsp): support multiple folding range providers * refactor(lsp): expose all folding related functions under `vim.lsp.*` * perf(lsp): add `lsp.MultiHandler` for do `foldupdate()` only once
* fix(api): only flush nvim__redraw when necessary #31250luukvbaal2024-11-18
| | | | | | | | Problem: Not possible to only set a "redraw later" type with nvim__redraw, which seems to be desired for the treesitter highlighter. Solution: Do not update the screen when "flush" is explicitly set to false and only redraw later types are present. In that case, do not call ui_flush() either.
* fix(api): update "range" windows in nvim__redraw #31042luukvbaal2024-11-17
| | | | | | | Problem: nvim__redraw's "range" marks a buffer range for redraw, and subsequently flushes the UI without updating the windows containing that buffer. Solution: Implicitly update the screen, unless specified otherwise. Only update the screen with the last call of the treesitter on_changedtree() callback.
* fix(treesitter): remove redundant on_bytes callback #31041luukvbaal2024-11-16
| | | | | | | Problem: Treesitter highlighter implements an on_bytes callback that just re-marks a buffer range for redraw. The edit that prompted the callback will already have done that. Solution: Remove redundant on_bytes callback from the treesitter highlighter module.
* fix(treesitter): keep treeview open if source window is still open #31198Hyker2024-11-14
| | | | | | | | | | | | Problem: When there is a tree view opened by :InspectTree and the source buffer is open in multiple windows, closing one of the source windows will lead to the tree view being closed as well. Regression by #31181. Solution: Check how many source windows are open when trying to quit one. If there are more than one, keep the tree view(s) open. If the only source window is closed, also close the tree view(s). fix #31196
* fix(treesitter): add 'QuitPre' event to autocommands in inspect_treehykerr2024-11-12
| | | | | | | | | Problem: Quitting source buffer for ```:InspectTree``` command raises ```E855``` when source buffer and tree views are the only open buffers. Solution: Add ```QuitPre``` event to autocmd handling closing/hiding the source buffer to close all open tree views. This allows nvim to quit when source and tree buffers are the only open windows.
* fix(treesitter): close InspectTree/EditQuery window on BufUnload (#31036)zeertzjq2024-11-03
| | | | | | Problem: The window opened :InspectTree or :EditQuery isn't closed when the source buffer is unloaded, even though it is closed when the buffer is hidden. Solution: Also close the window on BufUnload.
* fix(health): better layout of vim.treesitter health checkChristian Clason2024-11-02
| | | | | | | | Problem: Long lists of available parsers make it hard to see WASM status. Solution: Add separate headings for "treesitter features" (ABI, WASM) and "treesitter parsers". Also add minimum supported ABI version.
* docs(treesitter): specify predicate boolean return valueRiley Bruins2024-10-27
|
* feat(vim.validate): improve fast form and deprecate spec formLewis Russell2024-10-21
| | | | | | | | | | | | | | Problem: `vim.validate()` takes two forms when it only needs one. Solution: - Teach the fast form all the features of the spec form. - Deprecate the spec form. - General optimizations for both forms. - Add a `message` argument which can be used alongside or in place of the `optional` argument.