aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter/_fold.lua
Commit message (Collapse)AuthorAge
* 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): avoid computing foldlevels for reloaded buffer #32233luukvbaal2025-01-28
|
* fix(treesitter): compute folds on_changedtree only if not nilKonrad Malik2025-01-20
|
* Merge #32001 from MariaSolOs/consistent-namespacesJustin M. Keyes2025-01-15
|\
| * refactor: use nvim.foo.bar format for autocommand groupsMaria 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.
* refactor(treesitter.foldexpr): remove unused parse_injections parameterRiley Bruins2025-01-10
|
* 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>
* 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
|
* 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(treesitter): suppress get_parser warnings via opts.errorRiley Bruins2024-09-28
|
* feat(treesitter): start moving get_parser to return nil #30313Riley Bruins2024-09-13
| | | | | | | | | | | | | | | | | | | **Problem:** `vim.treesitter.get_parser` will throw an error if no parser can be found. - This means the caller is responsible for wrapping it in a `pcall`, which is easy to forget - It also makes it slightly harder to potentially memoize `get_parser` in the future - It's a bit unintuitive since many other `get_*` style functions conventionally return `nil` if no object is found (e.g. `get_node`, `get_lang`, `query.get`, etc.) **Solution:** Return `nil` if no parser can be found or created - This requires a function signature change, and some new assertions in places where the parser will always (or should always) be found. - This commit starts by making this change internally, since it is breaking. Eventually it will be rolled out to the public API.
* feat(treesitter)!: default to correct behavior for quantified captures (#30193)Gregory Anders2024-09-01
| | | | | | | | | | | | 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.
* fix(treesitter.foldexpr): robustness against ctrl-cJaehwang Jung2024-07-08
| | | | | | | | | | | | | | Problem: Exiting the insert mode with ctrl-c does not trigger InsertLeave autocmd. This may lead to nil error in treesitter foldexpr. Solution: Check nil. Folds still can be stale after exiting the insert mode with ctrl-c, but it will be eventually updated correctly. An alternative solution would be to ensure that exiting the insert mode always triggers do_foldupdate. This can be done either by "fixing" ctrl-c or with on_key callback that checks ctrl-c (nvim-cmp does this).
* perf(treesitter): remove unnecessary foldexpr loopRiley Bruins2024-06-24
| | | | | | Instead of looping over all captured nodes, just take the end range from the last node in the list. This uses the fact that nodes returned by iter_matches are ordered by their range (earlier to later).
* fix(treesitter): don't open fold when o/O adds a line below #28709Jaehwang Jung2024-06-20
| | | | | | | | | | | Problem: `o`-ing on a folded line opens the fold, because the new line gets the fold level from the above line (level '='), which extends the fold to the new line. `O` has a similar problem when run on the line below a fold. Solution: Use -1 for the added line to get the lower level from the above/below line.
* refactor(lua): improve type annotationsLewis Russell2024-06-11
|
* fix(treesitter): clip end row earlyJaehwang Jung2024-05-07
| | | | | | | | Problem: UINT32_MAX + 1 passed to vim._foldupdate. Solution: Clip the end row from treesitter asap to avoid such issues.
* fix(treesitter.foldexpr): check for all insert submodesTheLeoP2024-04-26
|
* perf(treesitter): incremental foldupdateJaehwang Jung2024-04-21
| | | | | | | | | | | Problem: While the fold level computation is incremental, the evaluation of the foldexpr is done on the full buffer. Despite that the foldexpr reads from the cache, it can take tens of milliseconds for moderately big (10K lines) buffers. Solution: Track the range of lines on which the foldexpr should be evaluated.
* feat(treesitter): handle quantified fold capturesRiley Bruins2024-04-20
|
* revert: "feat(treesitter): add foldtext with treesitter highlighting"Till Bungert2024-01-27
| | | This reverts commit 9ce1623 in favor of #20750.
* fix(treesitter): improve vim.treesitter.foldexprJaehwang Jung2023-12-12
| | | | | | | | | | | | * Collect on_bytes and flush at the invocation of the scheduled callback to take account of commands that triggers multiple on_bytes. * More accurately track movement of folds so that foldexpr returns reasonable values even when the scheduled computation is not run yet. * Start computing folds from the line above (+ foldminlines) the changed lines to handle the folds that are removed due to the size limit. * Shrink folds that end at the line at which another fold starts to assign proper level to that line. * Use level '=' for lines that are not computed yet.
* fix(treesitter): fix indexing in foldexprJaehwang Jung2023-12-12
|
* fix(treesitter): make Visual hl work consistently with foldtext (#25484)zeertzjq2023-10-03
| | | | | Problem: Visual highlight is inconsistent on a folded line with treesitter foldtext. Solution: Don't added Folded highlight as it is already in background.
* feat(treesitter): add foldtext with treesitter highlighting (#25391)Till Bungert2023-10-01
|
* fix(treesitter): don't update fold if tree is unchangedJaehwang Jung2023-09-13
| | | | | | | | | | | Problem: Folds are opened when the visible range changes even if there are no modifications to the buffer, e.g, when using zM for the first time. If the parsed tree was invalid, on_win re-parses and gets empty tree changes, which triggers fold updates. Solution: Don't update folds in on_changedtree if there are no changes.
* fix(treesitter): update folds only once on InsertLeaveJaehwang Jung2023-08-29
| | | | | | | | | | Problem: With treesitter fold, InsertLeave can be slow, because a single session of insert mode may schedule multiple fold updates in on_bytes and on_changedtree. Solution: Don't create duplicate autocmds.
* feat(treesitter)!: incremental injection parsingLewis Russell2023-08-12
| | | | | | | | | | | | | | | | | | | | | Problem: Treesitter highlighting is slow for large files with lots of injections. Solution: Only parse injections we are going to render during a redraw cycle. --- - `LanguageTree:parse()` will no longer parse injections by default and now requires an explicit range argument to be passed. - `TSHighlighter` now parses injections incrementally during on_win callbacks for the line range being rendered. - Plugins which require certain injections to be parsed must run `parser:parse({ start_row, end_row })` before using the tree.
* fix(treesitter): update folds in all relevant windows (#24230)Jaehwang Jung2023-07-07
| | | | | | | | | Problem: When using treesitter foldexpr, * :diffput/get open diff folds, and * folds are not updated in other windows that contain the updated buffer. Solution: Update folds in all windows that contain the updated buffer and use expr foldmethod.
* fix(treesitter): make foldexpr work without highlighting (#24167)Jaehwang Jung2023-06-27
| | | | | | | | | | | | | | | Problem: Treesitter fold is not updated if treesitter hightlight is not active. More precisely, updating folds requires `LanguageTree:parse()`. Solution: Call `parse()` before computing folds and compute folds when lines are added/removed. This doesn't guarantee correctness of the folds, because some changes that don't add/remove line won't update the folds even if they should (e.g. adding pair of braces). But it is good enough for most cases, while not introducing big overhead. Also, if highlighting is active, it is likely that `TSHighlighter._on_buf` already ran `parse()` (or vice versa).
* fix(treesitter): allow foldexpr without highlights (#23672)Lewis Russell2023-05-18
| | | Ref nvim-treesitter/nvim-treesitter#4748
* perf(treesitter): insert/remove items efficiently (#23443)Lewis Russell2023-05-02
|
* fix(treesitter): do not calc folds on unloaded buffersLewis Russell2023-05-02
| | | Fixes #23423
* fix(treesitter): foldexpr tweaksLewis Russell2023-05-01
| | | Some small general fixes found working on developing async parsing.
* docs: fix typosdundargoc2023-04-04
| | | | | | Co-authored-by: Gregory Anders <greg@gpanders.com> Co-authored-by: Raphael <glephunter@gmail.com> Co-authored-by: C.D. MacEachern <craig.daniel.maceachern@gmail.com> Co-authored-by: himanoa <matsunoappy@gmail.com>
* fix(treesitter): add missing deprecateLewis Russell2023-03-24
|
* fix(treesitter): annotationsLewis Russell2023-03-23
| | | | | | - Begin using `@package` in place of `@private` for functions that are accessed internally but outside their defined class. - Rename Node -> TSP.Node
* fix(treesitter): foldexpr (#22652)Lewis Russell2023-03-13
| | | The ranges passed to foldinfo.remove_range were in the wrong order.
* feat(treesitter)!: consolidate query util functionsLewis Russell2023-03-10
| | | | | | - And address more type errors. - Removed the `concat` option from `get_node_text` since it was applied inconsistently and made typing awkward.
* perf(treesitter): more efficient foldexprLewis Russell2023-03-10
|
* feat(treesitter): upstream foldexpr from nvim-treesitterLewis Russell2023-02-23