summaryrefslogtreecommitdiffstatshomepage
path: root/runtime/lua/vim/treesitter/dev.lua
AgeCommit message (Collapse)AuthorFiles
2026-04-08feat(api): rename buffer to buf #35330Jordan1
Problem: `:help dev-name-common` states that "buf" should be used instead of "buffer" but there are cases where buffer is mentioned in the lua API. Solution: - Rename occurrences of "buffer" to "buf" for consistency with the documentation. - Support (but deprecate) "buffer" for backwards compatibility. Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2026-03-13refactor(treesitter)!: get_parser return nil on error #37276nikolightsaber1
2026-02-24fix(treesitter): InspectTree only show the largest injection #37906phanium1
Problem: :InspectTree don't show luadoc injection lua file. Since luadoc share the same "root" with comment in their common primary (lua) tree. Current logic simply show the largest (comment injection) and ignore all smaller one (luadoc injection). Solution: Handle different lang injections separately. Then sort them by byte_length to ensure the draw tree consistent.
2026-02-19fix(treesitter): :InspectTree wrong title for non-relative path #37965zeertzjq1
Problem: :InspectTree sets wrong title for file with non-relative path. Solution: Use full path if relpath() returns nil.
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.
2026-01-28refactor(lua): use vim.fs instead of fnamemodifyYochem van Rosmalen1
Although powerful -- especially with chained modifiers --, the readability (and therefore maintainability) of `fnamemodify()` and its modifiers is often worse than a function name, giving less context and having to rely on `:h filename-modifiers`. However, it is used plenty in the Lua stdlib: - 16x for the basename: `fnamemodify(path, ':t')` - 7x for the parents: `fnamemodify(path, ':h')` - 7x for the stem (filename w/o extension): `fnamemodify(path, ':r')` - 6x for the absolute path: `fnamemodify(path, ':p')` - 2x for the suffix: `fnamemodify(path, ':e')` - 2x relative to the home directory: `fnamemodify(path, ':~')` - 1x relative to the cwd: `fnamemodify(path, ':.')` The `fs` module in the stdlib provides a cleaner interface for most of these path operations: `vim.fs.basename` instead of `':t'`, `vim.fs.dirname` instead of `':h'`, `vim.fs.abspath` instead of `':p'`. This commit refactors the runtime to use these instead of fnamemodify. Not all fnamemodify calls are removed; some have intrinsic differences in behavior with the `vim.fs` replacement or do not yet have a replacement in the Lua module, i.e. `:~`, `:.`, `:e` and `:r`.
2025-12-30fix(treesitter): use metadata in :EditQuery captures #37116Peter Cardenas1
Problem: When the `#offset!` directive is used with `:EditQuery`, the query does not take the offset into consideration when creating the extmark to preview the capture. Solution: Use the capture metadata to modify the node range before creating the extmark.
2025-12-02fix(treesitter): missing `nowait` for :InspectTree keymaps #36804Chris Grieser1
2025-08-28refactor(lua): consistent use of local aliasesChristian Clason1
2025-08-12fix(treesitter): set local values of window optionsJaehwang Jung1
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-06-25fix: map wincmd instead of remap #34635phanium1
Same issue: a59b052857ca43997b9e8be0a1d5c870ce172807
2025-06-06fix: type fixesLewis Russell1
Type fixes caught by emmylua
2025-05-02fix(treesitter): close `:InspectTree` with `q`Christian Clason1
Problem: `:InspectTree` window does not follow precedent for focused "info windows" (like `checkhealth`, `Man`, etc.). Solution: Map `q` to `<C-w>c`.
2025-04-16fix(treesitter): fix `:InspectTree` incorrect injectionsyuukibarns1
2025-03-11fix: warn when :InspectTree on buffer with no parser #32783phanium1
Problem: `InspectTree` error on buffer without ts parser attached. Solution: show a more correct warning.
2025-02-05feat(treesitter): show which nodes are missing in InspectTreeRiley Bruins1
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>
2025-01-27fix: resolve all remaining LuaLS diagnosticsLewis Russell1
2025-01-14refactor: use nvim.foo.bar format for autocommand groupsMaria José Solano1
2025-01-14refactor: use nvim.foo.bar format for namespacesMaria José Solano1
2024-11-14fix(treesitter): keep treeview open if source window is still open #31198Hyker1
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
2024-11-12fix(treesitter): add 'QuitPre' event to autocommands in inspect_treehykerr1
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.
2024-11-03fix(treesitter): close InspectTree/EditQuery window on BufUnload (#31036)zeertzjq1
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.
2024-10-17perf(validate): use lighter versionLewis Russell1
- Also fix `vim.validate()` for PUC Lua when showing errors for values that aren't string or number.
2024-10-01fix(treesitter): indent size for inspect_tree #28727Jongwook Choi1
Problem: For :InspectTree, indent size (`&shiftwidth`) for the tree viewer may be incorrect. This is because the tree viewer buffer with the filetype `query` does not explicitly configures the tab size, which can mismatch with the default indent size (2) assumed by TSTreeView's implementation. Solution: Set shiftwidth to be the same as TSTreeViewOpts specifies, which defaults to 2.
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-27fix(treesitter): EditQuery shows swapfile ATTENTION #30536Justin M. Keyes1
Problem: EditQuery shows swapfile ATTENTION, but this buffer is not intended for preservation (and the dialog breaks the UX). Solution: Set 'noswapfile' on the buffer before renaming it.
2024-09-13feat(treesitter): start moving get_parser to return nil #30313Riley Bruins1
**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.
2024-07-29fix(treesitter): highlight anonymous nodes in inspect_treeRiley Bruins1
**Problem:** With anonymous nodes toggled in the inspect tree, only named nodes will be highlighted when moving the cursor in the source code buffer. **Solution:** Retrieve the anonymous node at the cursor (when toggled on in the inspect tree) and highlight them when appropriate, for better clarity/specificity.
2024-07-05fix(treesitter): display fields for anonymous nodes in :InspectTreeRiley Bruins1
2024-06-04refactor(lua): use tuple syntax everywhere #29111Ilia Choly1
2024-05-27fix(treesitter): find buffer in multiple windows #28922Guilherme Soares1
Problem: 1. When interacting with multiple :InspectTree and the source buffer windows there is a high chance of errors due to the window ids not being updated and validated. 2. Not all InspectTree windows were closed when the source buffer was closed. Solution: 1. Update InspectTree window id on `CursorMoved` event and validate source buffer window id before trying to navigate to it. 2. Close all InspectTree windows
2024-05-03fix(treesitter): escape "\" in :InspectTree #28613Riley Bruins1
Some parsers for, e.g., LaTeX or PHP have anonymous nodes like `"\"` or `"\text"` that behave wonkily (especially the first example) in the `InspectTree` window, so this PR escapes them by adding another backslash in front of them
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-22feat(treesitter): add folding for `InspectTree` (#27518)再生花1
As the InspectTree buffer is now a valid tree-sitter query tree, we can use the bundled fold queries to have folding for the tree.
2024-02-06feat(treesitter): show root nodes in :InspectTree (#26944)altermo1
Co-authored-by: altermo <> Co-authored-by: Jongwook Choi <wookayin@gmail.com>
2024-02-05feat(treesitter): use 0-based indexing to show ranges in `:InspectTree`Jongwook Choi1
Problem: - `:InspectTree` was showing node ranges in 1-based indexing, i.e., in vim cursor position (lnum, col). However, treesitter API adopts 0-based indexing to represent ranges (Range4). This can often be confusing for developers and plugin authors when debugging code written with treesiter APIs. Solution: - Change to 0-based indexing from 1-based indexing to show node ranges in `:InspectTree`. - Note: To make things not complicated, we do not provide an option or keymap to configure which indexing mode to use.
2024-02-04fix(treesitter): inspect-tree remember opts on buf changealtermo1
2024-01-28docs: enforce "treesitter" spelling #27110Jongwook Choi1
It's the "tree-sitter" project, but "treesitter" in our code and docs.
2024-01-08docs(treesitter): improve 'no parser' error message for InspectTreeJongwook Choi1
Improve error messages for `:InspectTree`, when no parsers are available for the current buffer and filetype. We can show more informative and helpful error message for users (e.g., which lang was searched for): ``` ... No parser available for the given buffer: +... no parser for 'custom_ft' language, see :help treesitter-parsers ``` Also improve the relevant docs for *treesitter-parsers*.
2023-11-30fix: Remove nested for_each_tree in TSTreeView (#26328)Pham Huy Hoang1
Problem: `LanguageTree:for_each_tree` calls itself for child nodes, so when we calls `for_each_tree` inside `for_each_tree`, this quickly leads to exponential tree calls. Solution: Use `pairs(child:trees())` directly in this case, as we don't need the extra callback for each children, this is already handled from the outer `for_each_tree` call
2023-11-30fix(treesitter): fix parens stacking in inspector display (#26304)Gregory Anders1
When first opened, the tree-sitter inspector traverses all of the nodes in the buffer to calculate an array of nodes. This traversal is done only once, and _all_ nodes (both named and anonymous) are included. Toggling anonymous nodes in the inspector only changes how the tree is drawn in the buffer, but does not affect the underlying data structure at all. When the buffer is traversed and the list of nodes is calculated, we don't know whether or not anonymous nodes will be displayed in the inspector or not. Thus, we cannot determine during traversal where to put closing parentheses. Instead, this must be done when drawing. When we draw, the tree structure has been flatted into a single array, so we lose parent-child relationships that would otherwise make determining the number of closing parentheses straightforward. However, we can instead rely on the fact that a delta between the depth of a node and the depth of the successive node _must_ mean that more closing parentheses are required: (foo (bar) (baz) ↑ │ └ (bar) and (baz) have different depths, so (bar) must have an extra closing parenthesis This does not depend on whether or not anonymous nodes are displayed and so works in both cases.
2023-11-29fix(treesitter): adjust indentation in inspector highlights (#26302)Gregory Anders1
2023-11-29docs: document TSNode:byte_length() (#26287)Gregory Anders1
Also update the type annotation of TSNode:id(), which returns a string, not an integer.
2023-11-29fix(treesitter): make InspectTree correctly handle nested injections (#26085)Pham Huy Hoang1
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.
2023-11-29fix(treesitter): use proper query syntax for inspector (#26274)Gregory Anders1
2023-10-19fix(treesitter): set cursor position when opening inspectorMaria José Solano1
2023-10-17fix(treesitter): check that buf is loaded in autocommands (#25679)Maria José Solano1
2023-09-23docs: fix type warningsMaria José Solano1