aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter.lua
Commit message (Collapse)AuthorAge
* feat(inspector): support ranges in vim.inspect_posLewis Russell4 days
| | | | | | | | | | | | | | | | Problem: Highlight inspection is limited to a single position, and its result types do not document the fields shared by different highlight sources. Solution: Accept end_row/end_col in vim.inspect_pos to inspect a range. Keep range ends exclusive and retain the existing single-position behavior. Support Ex line ranges in :Inspect, including Visual selections. Document named result types, expose shared highlight fields, and keep the existing extmark details and buffer field for compatibility. AI-assisted
* Merge pull request #42134 from lewis6991/emmyluaLewis Russell2026-09-30
|\ | | | | fix(lua): enable param-type-mismatch diagnostic
| * fix(lua): enable param-type-mismatch diagnosticLewis Russell2026-09-28
| | | | | | | | | | | | | | | | | | Problem: Argument type mismatches are excluded from EmmyLua checks. Solution: Correct runtime annotations and calls, document local checker workarounds, and enable the diagnostic. AI-assisted
* | feat(treesitter): add get_captures() for positions and rangesLewis Russell2026-09-28
|/ | | | | | | | | | | | | | | | | Problem: get_captures_at_pos() only returns captures at one position. It cannot query a whole line or range. It can also miss captures from injected languages outside the visible area. Solution: Add vim.treesitter.get_captures() with a required start and an optional exclusive stop. Accept row numbers or {row, col} positions. Without a stop, query one position or a whole line. Parse the requested range and return capture coordinates. Deprecate get_captures_at_pos() with a compatibility wrapper and migrate its internal callers. Keep get_captures_at_cursor() for capture names at a window's cursor. AI-assisted
* fix(lua): add missing param annotations (#41911)Lewis Russell2026-09-15
|
* build: enable more EmmyLua checksLewis Russell2026-09-09
| | | | | | | | | | Enable checks for unused code, deprecated calls, return types, and annotations. Fix the warnings and replace the deprecated highlight function. Keep exceptions where old APIs are still needed or the checker gets it wrong. AI-assisted
* docs: func/expr options, misc #41102Justin M. Keyes2026-08-01
|
* refactor(api): omit optional paramJustin M. Keyes2026-07-13
|
* build(zig): run oldtests in zig builds with new lua runnerbfredl2026-06-02
| | | | | | | | | | | | | | | | | The new lua based runner replaces Makefile, runnvim.sh and runnvim.vim As it happens, we run a `--headless` nvim inside a `:terminal` layer, this is pointless. Also there is still a lot remnants for oldesttests, but we don't have any except for test1.in which just checks the environment for following, nonexistant oldesttests. so just skip that. For now, the actual vimscript code which runs in vim-under-test is completely unchanged. On macos, luajit is finally working with the latest ziglua master. Also fix some minor bugs regarding locales, such as incorrect HAVE_WORKING_LIBINTL checks
* docs(treesitter): describe pattern_id of capturesatusy2026-05-29
|
* fix(treesitter): drop select() kwargs #39646Justin M. Keyes2026-05-07
| | | | | | | Problem: Unnecessary kwargs. Solution: Use param instead of kwargs.
* docs: misc, rename "tabpage"Justin M. Keyes2026-05-07
| | | | | | Co-authored-by: michael-grunder <michael.grunder@gmail.com> Co-authored-by: Olivia Kinnear <git@superatomic.dev> Co-authored-by: Felipe Matarazzo <felipemps@protonmail.com>
* feat(lua)!: vim.isnil, vim.nonnil, deprecate vim.F #39495Olivia Kinnear2026-05-06
|
* feat(treesitter): provide select() #39069Nathan Zeng2026-05-06
| | | | | Problem: No public method for treesitter incremental selection. Solution: Add `vim.treesitter.select()`.
* fix(treesitter): get_node_text() inconsistent trailing newline #39409David Balatero2026-05-03
| | | | | | | | | | | | | | | | | | Problem: `get_node_text()` returned inconsistent results between buffer and string sources when a node's range ends at `end_col == 0` (i.e. the node ends with a newline). The buffer path dropped the trailing newline; the string path included it correctly. Solution: Append `'\n'` in `buf_range_get_text()` when `end_col == 0` and `start_row ~= end_row`. The `start_row ~= end_row` guard excludes zero-width nodes at column 0, which should return `""`. Remove the workaround in the `#trim!` directive that manually compensated for the missing newline. Strip whitespace in `resolve_lang()` so injection language nodes ending at `end_col == 0` (e.g. `">lua\n"`) still resolve correctly.
* build(lint): allow "bufnr" as positional param #39515Justin M. Keyes2026-04-30
| | | | | Allow `bufnr` as a positional param name because it is very common. However as a field name, or part of a function name, it is usually a mistake.
* docs: sort quasi-keysetsJustin M. Keyes2026-04-26
|
* refactor(treesitter)!: get_parser return nil on error #37276nikolightsaber2026-03-13
|
* docs: use "ev" convention in event-handlersJustin M. Keyes2026-03-12
| | | | | | | | | 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.
* docs: misc, build, lspJustin M. Keyes2025-11-22
|
* docs: miscdundargoc2025-06-14
| | | | | | | 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>
* feat(treesitter)!: apply `offset!` directive to all captures #34383Riley Bruins2025-06-13
| | | | | | | | | | | | | | | | | 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.
* fix: type fixesLewis Russell2025-06-06
| | | | Type fixes caught by emmylua
* feat(treesitter): allow disabling captures and patterns on TSQuery (#32790)Ian Chamberlain2025-03-11
| | | | | | | | | 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!`).
* doc: clarify window-id, tab-id, nvim_set_current_x #32528David Briscoe2025-02-27
| | | | | | | | | | | | | | 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`.
* fix(treesitter)!: enforce buffer is loaded when creating parserLuuk van Baal2025-02-19
| | | | | | | 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.
* fix: resolve all remaining LuaLS diagnosticsLewis Russell2025-01-27
|
* 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>
* feat(treesitter): include capture id in return value of ↵Riley Bruins2024-12-11
| | | | | | | | | | | | | | | `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()`
* refactor: add vim._resolve_bufnrLewis Russell2024-12-07
|
* fix: another round of type annotation fixesLewis Russell2024-10-31
|
* 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.
* perf(validate): use lighter versionLewis Russell2024-10-17
| | | | | - Also fix `vim.validate()` for PUC Lua when showing errors for values that aren't string or number.
* feat(treesitter): introduce child_with_descendant()Riley Bruins2024-10-11
| | | | | | 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`.
* docs: render `@since` versions, 0 means experimental #30649Justin M. Keyes2024-10-04
| | | | | | | | 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
* feat(treesitter)!: add default fallback to `ft_to_lang` lookupsChristian Clason2024-09-29
| | | | | | | | | | | | 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.
* docs: misc (#30177)dundargoc2024-09-29
| | | | | 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>
* fix(treesitter): suppress get_parser warnings via opts.errorRiley Bruins2024-09-28
|
* perf(treesitter): use `child_containing_descendant()` in `is_ancestor()`Riley Bruins2024-09-25
| | | | | | | | **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
* 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): allow get_node to return anonymous nodesRiley Bruins2024-07-29
| | | | | Adds a new field `include_anonymous` to the `get_node` options to allow anonymous nodes to be returned.
* refactor(lua): use tuple syntax everywhere #29111Ilia Choly2024-06-04
|
* docs: fix lua type warnings (#28633)Maria José Solano2024-05-05
|
* fix: lua annotationsLewis Russell2024-04-26
|
* docs: support inline markdownLewis Russell2024-03-09
| | | | | | - Tags are now created with `[tag]()` - References are now created with `[tag]` - Code spans are no longer wrapped
* feat!: remove deprecated functionsdundargoc2024-03-09
|
* docs(treesitter): fix ambiguous parameter description about `lang`Yi Ming2024-03-06
|
* docs: improve/add documentation of Lua typesLewis Russell2024-03-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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.
* feat(docs): replace lua2dox.luaLewis Russell2024-02-27
| | | | | | | | | | | | | | | | | | | | | | | | | | 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).