summaryrefslogtreecommitdiffstatshomepage
path: root/runtime/lua/vim/treesitter.lua
AgeCommit message (Collapse)AuthorFiles
2026-03-13refactor(treesitter)!: get_parser return nil on error #37276nikolightsaber1
2026-03-12docs: use "ev" convention in event-handlersJustin M. Keyes1
Problem: In autocmd examples, using "args" as the event-object name is vague and may be confused with a user-command. Solution: Use "ev" as the conventional event-object name.
2025-11-22docs: misc, build, lspJustin M. Keyes1
2025-06-14docs: miscdundargoc1
Co-authored-by: Jan Weinkauff <jan@weinkauff.cloud> Co-authored-by: MeanderingProgrammer <meanderingprogrammer@gmail.com> Co-authored-by: Yochem van Rosmalen <git@yochem.nl> Co-authored-by: phanium <91544758+phanen@users.noreply.github.com>
2025-06-13feat(treesitter)!: apply `offset!` directive to all captures #34383Riley Bruins1
This commit changes the `offset!` directive so that instead of setting a `metadata.range` value for the entire pattern, it will set a `metadata.offset` value. This offset will be applied to the range only in `vim.treesitter.get_range()`, rather than at directive application time. This allows the offset to be applied to any and all nodes captured by the given pattern, and removes the requirement that `#offset!` be applied to only a single node. The downside of this change is that plugins which read from `metadata.range` may be thrown off course, but such plugins should prefer `vim.treesitter.get_range()` when retrieving ranges anyway. Note that `#trim!` still sets `metadata.range`, and `vim.treesitter.get_range()` still reads from `metadata.range`, if it exists.
2025-06-06fix: type fixesLewis Russell1
Type fixes caught by emmylua
2025-03-11feat(treesitter): allow disabling captures and patterns on TSQuery (#32790)Ian Chamberlain1
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!`).
2025-02-27doc: clarify window-id, tab-id, nvim_set_current_x #32528David Briscoe1
Problem: Descriptions are somewhat vague. nvim_set_current_line modifies contents but nvim_set_current_buf does not, etc. Solution: - Make it clear that these functions accept or return a winid/tabid by linking to that concept in help. - Only these few files use the term "handles", so replace them with the more conventional terminology. - Add a new help section for tab-ID. This concept is unique to neovim because vim exposes tabnr, but not tab handles. This section is modelled after `:h winid`.
2025-02-19fix(treesitter)!: enforce buffer is loaded when creating parserLuuk van Baal1
Problem: `vim.treesitter._create_parser()` silently loads the buffer, bypassing the swapfile prompt. Solution: Error for an unloaded buffer, ensure buffer is loaded in `vim.treesitter.start()` instead.
2025-01-27fix: resolve all remaining LuaLS diagnosticsLewis Russell1
2025-01-12feat(treesitter)!: don't parse tree in get_parser() or start()Riley Bruins1
**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.
2025-01-12feat(treesitter): async parsingRiley Bruins1
**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>
2024-12-11feat(treesitter): include capture id in return value of ↵Riley Bruins1
`get_captures_at_pos()` #30559 **Problem:** Currently, it is difficult to get node(s)-level metadata for a capture returned by `get_captures_at_pos()`. This is because it is stored in `metadata[id]` and we do not have access to the value of `id`, so to get this value we have to iterate over the keys of `metadata`. See [this commit](https://github.com/neovim/neovim/commit/d63622930001b39b12f14112fc3abb55b760c447#diff-8bd4742121c2f359d0345f3c6c253a58220f1a28670cc4e1c957992232059a6cR16). Things would be much simpler if we were given the `id` of the capture so we could use it to just index `metadata` directly. **Solution:** Include `id` in the data returned by `get_captures_at_pos()`
2024-12-07refactor: add vim._resolve_bufnrLewis Russell1
2024-10-31fix: another round of type annotation fixesLewis Russell1
2024-10-21feat(vim.validate): improve fast form and deprecate spec formLewis Russell1
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.
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-11feat(treesitter): introduce child_with_descendant()Riley Bruins1
This commit also marks `child_containing_descendant()` as deprecated (per upstream's documentation), and uses `child_with_descendant()` in its place. Minimum required tree-sitter version will now be `0.24`.
2024-10-04docs: render `@since` versions, 0 means experimental #30649Justin M. Keyes1
An implication of this current approach is that `NVIM_API_LEVEL` should be bumped when a new Lua function is added. TODO(future): add a lint check which requires `@since` on all new functions. ref #25416
2024-09-29feat(treesitter)!: add default fallback to `ft_to_lang` lookupsChristian Clason1
Problem: Language names are only registered for filetype<->language lookups when parsers are actually loaded; this means users cannot rely on `vim.treesitter.language.get_lang()` or `get_filetypes()` to return the correct value when language and filetype coincide and always need to add explicit fallbacks. Solution: Always return the language name as valid filetype in `get_filetypes()`, and default to the filetype in `get_lang()`. Document this behavior.
2024-09-29docs: misc (#30177)dundargoc1
Co-authored-by: Christian Clason <c.clason@uni-graz.at> Co-authored-by: Riley Bruins <ribru17@hotmail.com> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2024-09-28fix(treesitter): suppress get_parser warnings via opts.errorRiley Bruins1
2024-09-25perf(treesitter): use `child_containing_descendant()` in `is_ancestor()`Riley Bruins1
**Problem:** `is_ancestor()` uses a slow, bottom-up parent lookup which has performance pitfalls detailed in #28512. **Solution:** Take `is_ancestor()` from $O(n^2)$ to $O(n)$ by incorporating the use of the `child_containing_descendant()` function
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-29feat(treesitter): allow get_node to return anonymous nodesRiley Bruins1
Adds a new field `include_anonymous` to the `get_node` options to allow anonymous nodes to be returned.
2024-06-04refactor(lua): use tuple syntax everywhere #29111Ilia Choly1
2024-05-05docs: fix lua type warnings (#28633)Maria José Solano1
2024-04-26fix: lua annotationsLewis Russell1
2024-03-09docs: support inline markdownLewis Russell1
- Tags are now created with `[tag]()` - References are now created with `[tag]` - Code spans are no longer wrapped
2024-03-09feat!: remove deprecated functionsdundargoc1
2024-03-06docs(treesitter): fix ambiguous parameter description about `lang`Yi Ming1
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-27feat(docs): replace lua2dox.luaLewis Russell1
Problem: The documentation flow (`gen_vimdoc.py`) has several issues: - it's not very versatile - depends on doxygen - doesn't work well with Lua code as it requires an awkward filter script to convert it into pseudo-C. - The intermediate XML files and filters makes it too much like a rube goldberg machine. Solution: Re-implement the flow using Lua, LPEG and treesitter. - `gen_vimdoc.py` is now replaced with `gen_vimdoc.lua` and replicates a portion of the logic. - `lua2dox.lua` is gone! - No more XML files. - Doxygen is now longer used and instead we now use: - LPEG for comment parsing (see `scripts/luacats_grammar.lua` and `scripts/cdoc_grammar.lua`). - LPEG for C parsing (see `scripts/cdoc_parser.lua`) - Lua patterns for Lua parsing (see `scripts/luacats_parser.lua`). - Treesitter for Markdown parsing (see `scripts/text_utils.lua`). - The generated `runtime/doc/*.mpack` files have been removed. - `scripts/gen_eval_files.lua` now instead uses `scripts/cdoc_parser.lua` directly. - Text wrapping is implemented in `scripts/text_utils.lua` and appears to produce more consistent results (the main contributer to the diff of this change).
2024-02-25refactor(types): fix miscellaneous type warningsMaria José Solano1
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-03refactor: create function for deferred loadingdundargoc1
The benefit of this is that users only pay for what they use. If e.g. only `vim.lsp.buf_get_clients()` is called then they don't need to load all modules under `vim.lsp` which could lead to significant startuptime saving. Also `vim.lsp.module` is a bit nicer to user compared to `require("vim.lsp.module")`. This isn't used for some nested modules such as `filetype` as it breaks tests with error messages such as "attempt to index field 'detect'". It's not entirely certain the reason for this, but it is likely it is due to filetype being precompiled which would imply deferred loading isn't needed for performance reasons.
2024-01-27revert: "feat(treesitter): add foldtext with treesitter highlighting"Till Bungert1
This reverts commit 9ce1623 in favor of #20750.
2024-01-24fix(treesitter): prefix treesitter types with vimPhạm Huy Hoàng1
2023-12-04fix(treesitter): allow passing lang to vim.treesitter.get_node() now ↵Jongwook Choi1
correctly takes opts.lang (#26360) PROBLEM: `vim.treesitter.get_node()` does not recognize the `lang` in the option table. This option was used in somewhere else, for instance, `vim.treesitter.dev` (for `inspect_tree`) but was never implemented. SOLUTION: Make `get_node()` correctly use `opts.lang` when getting a treesitter parser.
2023-11-04docs(treesitter): add disclaimer about needing to parse before `get_node()`L Lllvvuu1
Problem: --- Misuse of `get_node()` is common: https://github.com/search?q=get_node_at_cursor+language%3Alua&type=code Solution: --- Add a note clarifying proper usage.
2023-10-01feat(treesitter): add foldtext with treesitter highlighting (#25391)Till Bungert1
2023-09-23docs: fix type warningsMaria José Solano1
2023-09-15refactor(treesitter): rename "preview" => "edit" #25161Maria José Solano1
"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
2023-09-14docs: replace <pre> with ``` (#25136)Gregory Anders1
2023-08-25feat(treesitter): add a query editor (#24703)Maria José Solano1
2023-07-24fix(treesitter): stop() should treat 0 as current buffer #24450Micah Halter1
2023-07-18docs(lua): more improvements (#24387)Lewis Russell1
* 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>
2023-06-06refactor!: rename "playground" => "dev" #23919Justin M. Keyes1
Problem: "playground" is new jargon that overlaps with existing concepts: "dev" (`:help dev`) and "view" (also "scratch" `:help scratch-buffer`) . Solution: We should consistently use "dev" as the namespace for where "developer tools" live. For purposes of a "throwaway sandbox object", we can use the name "view". - Rename `TSPlayground` => `TSView` - Rename `playground.lua` => `dev.lua`
2023-05-18fix(treesitter): allow foldexpr without highlights (#23672)Lewis Russell1
Ref nvim-treesitter/nvim-treesitter#4748
2023-04-05refactor: rename local API alias from a to apiLewis Russell1
Problem: Codebase inconsistently binds vim.api onto a or api. Solution: Use api everywhere. a as an identifier is too short to have at the module level.