aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter
Commit message (Collapse)AuthorAge
* fix(treesitter): adjust indentation in inspector highlights (#26302)Gregory Anders2023-11-29
|
* docs: document TSNode:byte_length() (#26287)Gregory Anders2023-11-29
| | | | Also update the type annotation of TSNode:id(), which returns a string, not an integer.
* fix(treesitter): make InspectTree correctly handle nested injections (#26085)Pham Huy Hoang2023-11-29
| | | | | | | Problem: Only injections under the top level tree are found. Solution: Iterate through all trees to find injections. When two injections are contained within the same node in the parent tree, prefer the injection with the larger byte length.
* fix(treesitter): use proper query syntax for inspector (#26274)Gregory Anders2023-11-29
|
* fix(treesitter): don't invalidate parser when discovering injectionsDmytro Soltys2023-11-27
| | | | | | | | | When parsing with a range, languagetree looks up injections and adds them if needed. This explicitly invalidates parser, making `is_valid` report `false` both when including and excluding children. This is an attempt to describe desired behaviour of `is_valid` in tests, with what ended up being a single line change to satisfy them.
* fix(treesitter): set cursor position when opening inspectorMaria José Solano2023-10-19
|
* fix(docs): fix TSNode incorrect signaturesPham Huy Hoang2023-10-19
|
* fix(treesitter): check that buf is loaded in autocommands (#25679)Maria José Solano2023-10-17
|
* docs: small fixesdundargoc2023-10-10
| | | | | | Co-authored-by: Wansmer <wansmer@gmail.com> Co-authored-by: Andrew Voynov <andrewvoynov.b@gmail.com> Co-authored-by: David Moberg <david.moberg@mediatek.com>
* 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
|
* docs: fix type warningsMaria José Solano2023-09-23
|
* fix(languagetree): don't treat unparsed nodes as occupying full rangeL Lllvvuu2023-09-22
| | | | | | | | | | | | | | | | | | | | | | | | | This is incorrect in the following scenario: 1. The language tree is Lua > Vim > Lua. 2. An edit simultaneously wipes out the `_regions` of all nodes, while taking the Vim injection off-screen. 3. The Vim injection is not re-parsed, so the child Lua `_regions` is still `nil`. 4. The child Lua is assumed, incorrectly, to occupy the whole document. 5. This causes the injections to be parsed again, resulting in Lua > Vim > Lua > Vim. 6. Now, by the same process, Vim ends up with its range assumed over the whole document. Now the parse is broken and results in broken highlighting and poor performance. It should be fine to instead treat an unparsed node as occupying nothing (i.e. effectively non-existent). Since, either: - The parent was just parsed, hence defining `_regions` - The parent was not just parsed, in which case this node doesn't need to be parsed either. Also, the name `has_regions` is confusing; it seems to simply mean the opposite of "root" or "full_document". However, this PR does not touch it.
* feat(lua): add vim.func._memoizeLewis Russell2023-09-20
| | | | | | | | | | | | | | | Memoizes a function, using a custom function to hash the arguments. Private for now until: - There are other places in the codebase that could benefit from this (e.g. LSP), but might require other changes to accommodate. - Invalidation of the cache needs to be controllable. Using weak tables is an acceptable invalidation policy, but it shouldn't be the only one. - I don't think the story around `hash_fn` is completely thought out. We may be able to have a good default hash_fn by hashing each argument, so basically a better 'concat'.
* docs: misc #24561Justin M. Keyes2023-09-20
| | | | fix #24699 fix #25253
* fix(treesitter): _trees may not be list-likeJaehwang Jung2023-09-17
| | | | | | | | | | | Problem: With incremental injection parsing, injected languages' parsers parse only the relevant regions and stores the result in _trees with the index of the corresponding region. Therefore, there can be holes in _trees. Solution: * Use generic table functions where appropriate. * Fix type annotations and docs.
* feat(treesitter): add lang parameter to the query editor (#25181)Maria José Solano2023-09-16
|
* fix(treesitter): properly combine injection.combined regionsJaehwang Jung2023-09-16
| | | | | | | | | Problem: It doesn't make much sense to flatten each region (= list of ranges). This coincidentally worked for region with a single range. Solution: Custom function for combining regions.
* fix(treesitter): fix trim predicateLewis Russell2023-09-16
|
* perf(treesitter): do not scan past given line for predicate matchL Lllvvuu2023-09-16
| | | | | | | | | | | | | | | Problem --- If a highlighter query returns a significant number of predicate non-matches, the highlighter will scan well past the end of the window. Solution --- In the iterator returned from `iter_captures`, accept an optional parameter `end_line`. If no parameter provided, the behavior is unchanged, hence this is a non-invasive tweak. Fixes: #25113 nvim-treesitter/nvim-treesitter#5057
* fix(languagetree): apply `resolve_lang` to `metadata['injection.language']`L Lllvvuu2023-09-16
| | | | | | | | | | | | | `resolve_lang` is applied to `@injection.language` when it's supplied as a capture: https://github.com/neovim/neovim/blob/f5953edbac14febce9d4f8a3c35bdec1eae26fbe/runtime/lua/vim/treesitter/languagetree.lua#L766-L768 If we want to support `metadata['injection.language']` (as per #22518 and [tree-sitter upstream](https://tree-sitter.github.io/tree-sitter/syntax-highlighting#language-injection)) then the behavior should be consistent. Fixes: nvim-treesitter/nvim-treesitter#4918
* refactor(treesitter): remove duplicated diagnostic code (#24976)Maria José Solano2023-09-15
| | | | | | | * refactor(treesitter): remove duplicated diagnostic code * fixup!: fix type errors * fixup!: add type namespace
* refactor(treesitter): rename "preview" => "edit" #25161Maria José Solano2023-09-15
| | | | | | "Edit" more closely describes the generic application than "Preview", though the buffer contents don't (yet) map to an actual file on disk. https://github.com/neovim/neovim/pull/24703#discussion_r1321719133
* docs: replace <pre> with ``` (#25136)Gregory Anders2023-09-14
|
* refactor(treesitter): deprecate for_each_child #25118LW2023-09-14
| | | | | | | The name for_each_child is misleading and caused bugs. After #25111, #25115, there are no more usages of `for_each_child` in Nvim. In the future if we want to restore this functionality we can consider a generalized vim.traverse(node, key, visitor) function.
* fix(treesitter): `language.add` - only register parser if it existsL Lllvvuu2023-09-14
| | | | Fixes: #24531
* 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): fixup for InspectTreeLewis Russell2023-09-12
| | | | Fixes #25120
* fix(treesitter): remove more double recursionLewis Russell2023-09-12
| | | | Do not call `for_each_child` in functions that are already recursive.
* fix(languagetree): remove double recursion in LanguageTree:parseL Lllvvuu2023-09-12
| | | | | | | | | | | | | | | | `LanguageTree:parse` is recursive, and calls `LanguageTree:for_each_child`, which is also recursive. That means that, starting from the third level (child of child of root), nodes will be parsed twice. Which then means that if the tree is N layers deep, there will be ~2^N parses even if the branching factor is 1. Now, why was the tree deepening with each character inserted? And why did this only regress in #24647? These are mysteries for another time. Fixes: #25104
* fix(decorations): better approximation of botline #24794Jaehwang Jung2023-09-11
| | | | | | | | | | | | | | | | Problem: * The guessed botline might be smaller than the actual botline e.g. when there are folds and the user is typing in insert mode. This may result in incorrect treesitter highlights for injections. * botline can be larger than the last line number of the buffer, which results in errors when placing extmarks. Solution: * Take a more conservative approximation. I am not sure if it is sufficient to guarantee correctness, but it seems to be good enough for the case mentioned above. * Clamp it to the last line number. Co-authored-by: Lewis Russell <me@lewisr.dev>
* 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.
* fix(treesitter): validate window before updating preview highlightsMaria José Solano2023-08-27
|
* feat(treesitter): add a query editor (#24703)Maria José Solano2023-08-25
|
* feat(treesitter): add 'injection.self' and 'injection.parent'Amaan Qureshi2023-08-24
| | | | Co-authored-by: ObserverOfTime <chronobserver@disroot.org>
* docs(lua): add missing fields to treesitter/_metaPham Huy Hoang2023-08-16
| | | | | | | | According to `:h TSNode` docs, there's also `TSNode:sexpr()` and `TSNode:has_error()` that is part of `TSNode` class, but this wasn't documented in `treesitter/_meta.lua`. Adding missing fields in so the types is similar to `:h TSNode`
* fix(treesitter)!: remove deprecated legacy injection formatChristian Clason2023-08-14
|
* fix(treesitter): logger memory leakLewis Russell2023-08-13
|
* 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.
* feat(treesitter): add injection language fallback (#24659)Christian Clason2023-08-11
| | | | | | | | | | | | * feat(treesitter): add injection language fallback Problem: injection languages are often specified via aliases (e.g., filetype or in upper case), requiring custom directives. Solution: include lookup logic (try as parser name, then filetype, then lowercase) in LanguageTree itself and remove `#inject-language` directive. Co-authored-by: Lewis Russell <me@lewisr.dev>
* fix(lua): annotate that TSNode functions can return nil (#24621)Kyuuhachi2023-08-09
|
* fix(lua): improve annotations for stricter luals diagnostics (#24609)Christian Clason2023-08-09
| | | | | | | | | | | | | | | Problem: luals returns stricter diagnostics with bundled luarc.json Solution: Improve some function and type annotations: * use recognized uv.* types * disable diagnostic for global `vim` in shared.lua * docs: don't start comment lines with taglink (otherwise LuaLS will interpret it as a type) * add type alias for lpeg pattern * fix return annotation for `vim.secure.trust` * rename local Range object in vim.version (shadows `Range` in vim.treesitter) * fix some "missing fields" warnings * add missing required fields for test functions in eval.lua * rename lsp meta files for consistency
* fix(treesitter): make sure injections don't return empty ranges (#24595)Lewis Russell2023-08-07
| | | | | | | | | | | | | | | | | | | | When an injection has not set include children, make sure not to add the injection if no ranges are determined. This could happen when there is an injection with a child that has the same range as itself. e.g. consider this Makefile snippet ```make foo: $(VAR) ``` Line 2 has an injection for bash and a make variable reference. If include-children isn't set (default), then there is no range on line 2 to inject since the variable reference needs to be excluded. This caused the language tree to return an empty range, which the parser now interprets to mean the full buffer. This caused makefiles to have completely broken highlighting.
* fix(treesitter): escape quotes in :InspectTree view #24582ObserverOfTime2023-08-07
| | | | Problem: Anonymous nodes containing double quotes break the highlighting. Solution: Escape double quotes in anonymous nodes.
* docs(lua): more improvements (#24387)Lewis Russell2023-07-18
| | | | | | | | | | | | | | | | | * docs(lua): teach lua2dox how to table * docs(lua): teach gen_vimdoc.py about local functions No more need to mark local functions with @private * docs(lua): mention @nodoc and @meta in dev-lua-doc * fixup! Co-authored-by: Justin M. Keyes <justinkz@gmail.com> --------- Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
* 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.
* perf(treesitter): cache fold query (#24222)Jaehwang Jung2023-07-02
| | | | | | | | | | | | | | | | | | | | | perf(treesitter): cache vim.treesitter.query.get Problem: vim.treesitter.query.get searches and reads query files every time it's called, if user hasn't overridden the query. So this can incur slowdown when called frequently. This can happen when using treesitter foldexpr. For example, when using `:h :range!` in markdown file to format fenced codeblock, on_changedtree in _fold.lua is triggered many times despite that the tree doesn't have syntactic changes (might be a bug in LanguageTree). (Incidentally, the resulting fold is incorrect due to a bug in `:h range!`.) on_changedtree calls vim.treesitter.query.get for each tree changes. In addition, it may request folds queries for injected languages without fold queries, such as markdown_inline. Solution: * Cache the result of vim.treesitter.query.get. * If query file was not found, fail quickly at later calls.
* feat(treesitter): bundle markdown parser and queries (#22481)Christian Clason2023-07-01
| | | | | | | * bundle split Markdown parser from https://github.com/MDeiml/tree-sitter-markdown * add queries from https://github.com/nvim-treesitter/nvim-treesitter/tree/main * upstream `#trim!` and `#inject-language!` directives Co-authored-by: dundargoc <gocdundar@gmail.com>
* fix(treesitter): handle empty region when logging (#24173)Jaehwang Jung2023-06-27
|
* 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).