summaryrefslogtreecommitdiffstatshomepage
path: root/test/functional/treesitter/parser_spec.lua
AgeCommit message (Collapse)AuthorFiles
2026-04-16fix(treesitter): restore highlighting on 32 bit systems #39091Barrett Ruth1
Problem: Treesitter highlighting regressed on 32-bit builds because ranges that should cover the whole buffer were corrupted when passed into Lua. Solution: Round-trip those range values through Lua and validate them so treesitter sees the same ranges on 32 and 64-bit builds.
2026-03-13refactor(treesitter)!: get_parser return nil on error #37276nikolightsaber1
2026-03-11docs: api, messages, lsp, trustJustin M. Keyes1
gen_vimdoc.lua: In prepare for the upcoming release, comment-out the "Experimental" warning for prerelease features.
2026-03-04fix(treesitter): normalize language aliasesStefan VanBuren1
Hyphenated language names are silently dropped when used as injections (see #38132). This combines the normalization of language aliases into `resolve_lang`, and also adds the normalization of hyphens to underscores, which allows for handling of injected language tags with hyphens in their names. Fixes #38132.
2025-12-15Revert "refactor(treesitter): use scratch buffer for string parser" #36964Riley Bruins1
This reverts commit 2a7cb32959b4c616bd2c76ae1933f8e068e391ad.
2025-10-02refactor(treesitter): use scratch buffer for string parser #35988Riley Bruins1
This commit changes `languagetree.lua` so that it creates a scratch buffer under the hood when dealing with string parsers. This will make it much easier to just use extmarks whenever we need to track injection trees in `languagetree.lua`. This also allows us to remove the `treesitter.c` code for parsing a string directly. Note that the string parser's scratch buffer has `set noeol nofixeol` so that the parsed source exactly matches the passed in string.
2025-10-01fix(treesitter): don't add final newline if not present #35970Riley Bruins1
**Problem(?):** Buffers that (for whatever reason) aren't meant to have a final newline are still parsed with a final newline in `treesitter.c`. **Solution:** Don't add the newline to the last buffer line if it shouldn't be there. (This more closely matches the approach of `read_buffer_into()`.) This allows us to, say, use a scratch buffer with `noeol` and `nofixeol` behind the scenes in `get_string_parser()`. ...which would allow us to track injection trees with extmarks in that case. ...which would allow us to not drop previous trees after reparsing a different range with `get_parser():parse()`. ...which would prevent flickering when editing a buffer that has 2+ windows to it in view at a time. ...which would allow us to keep our sanity!!! (one step at a time...)
2025-06-13docs: vim.fs., diagnostics, lsp #34402Justin M. Keyes1
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-05-24fix(treesitter): properly clip nested injectionsRiley Bruins1
2025-03-28refactor(treesitter): simplify injection retrieval #33104Riley Bruins1
Simplify the logic for retrieving the injection ranges for the language tree. The trees are now also sorted by starting position, regardless of whether they are part of a combined injection or not. This would be helpful if ranges are ever to be stored in an interval tree or other kind of sorted tree structure.
2025-02-25test: combined injections (#32611)Artem1
* refactor: rewrite test without trailing whitespace * test: combined injection tests
2025-02-21perf(treesitter): only search for injections within the parse rangeRiley Bruins1
Co-authored-by: Jaehwang Jung <tomtomjhj@gmail.com>
2025-02-02feat(treesitter): allow LanguageTree:is_valid() to accept a rangeRiley Bruins1
When given, only that range will be checked for validity rather than the entire tree. This is used in the highlighter to save CPU cycles since we only need to parse a certain region at a time anyway.
2025-02-01fix(treesitter): nil access when running string parser asyncRiley Bruins1
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-07fix(treesitter): #trim! range for nodes ending at col 0 #31488Riley Bruins1
Problem: char-wise folding for `#trim!` ranges are improperly calculated for nodes that end at column 0, due to the way `get_node_text` works. Solution: Add the blank line that `get_node_text` removes for for nodes ending at column 0. Also properly set column positions when performing linewise trims.
2024-12-06test(treesitter): add a simple testutil fileRiley Bruins1
The util file, for now, just abstracts the common `run_query` function.
2024-12-06feat(treesitter): #trim! can trim all whitespaceRiley Bruins1
This commit also implements more generic trimming, acting on all whitespace (charwise) rather than just empty lines. It will unblock https://github.com/nvim-treesitter/nvim-treesitter/pull/3442 and allow for properly concealing markdown bullet markers regardless of indent width, e.g.
2024-10-11fix(treesitter): remove duplicate symbol names in language.inspect()Riley Bruins1
**Problems:** - `vim.treesitter.language.inspect()` returns duplicate symbol names, sometimes up to 6 of one kind in the case of `markdown` - The list-like `symbols` table can have holes and is thus not even a valid msgpack table anyway, mentioned in a test **Solution:** Return symbols as a map, rather than a list, where field names are the names of the symbol. The boolean value associated with the field encodes whether or not the symbol is named. Note that anonymous nodes are surrounded with double quotes (`"`) to prevent potential collisions with named counterparts that have the same identifier.
2024-09-28fix(treesitter): suppress get_parser warnings via opts.errorRiley Bruins1
2024-09-21test: support upvalues in exec_luaLewis Russell1
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-09-01feat(treesitter)!: default to correct behavior for quantified captures (#30193)Gregory Anders1
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.
2024-08-02test: allow exec_lua to handle functionsLewis Russell1
Problem: Tests have lots of exec_lua calls which input blocks of code provided as unformatted strings. Solution: Teach exec_lua how to handle functions.
2024-05-14fix(treesitter): allow optional directive captures (#28664)Riley Bruins1
2024-04-23test: improve test conventionsdundargoc1
Specifically, functions that are run in the context of the test runner are put in module `test/testutil.lua` while the functions that are run in the context of the test session are put in `test/functional/testnvim.lua`. Closes https://github.com/neovim/neovim/issues/27004.
2024-04-10refactor(test): inject after_each differentlyLewis Russell1
2024-04-08test: improve test conventionsdundargoc1
Work on https://github.com/neovim/neovim/issues/27004.
2024-03-24test(treesitter): separate out query-related tests into query_specJongwook Choi1
Move test cases that are more about treesitter query API rather than parser API or LanguageTree out of "treesitter/parser_spec", and collect them in another test suite "treesitter/query_spec".
2024-03-23test(treesitter): improve the style of treesitter/parser_specJongwook Choi1
General refactoring, including: - Improve whitespace and indentation - Prefix captures with `@` - Add more comments on `iter_capture()` tests - Move `test_query` up closer to the fixture source string No behavioral changes are made.
2024-03-11test: correct order of arguments to eq() (#27816)zeertzjq1
2024-03-09feat!: remove deprecated functionsdundargoc1
2024-02-21test(treesitter): fix obsolete predicatesChristian Clason1
2024-02-16fix(treesitter): correctly handle query quantifiers (#24738)Thomas Vigouroux1
Query patterns can contain quantifiers (e.g. (foo)+ @bar), so a single capture can map to multiple nodes. The iter_matches API can not handle this situation because the match table incorrectly maps capture indices to a single node instead of to an array of nodes. The match table should be updated to map capture indices to an array of nodes. However, this is a massively breaking change, so must be done with a proper deprecation period. `iter_matches`, `add_predicate` and `add_directive` must opt-in to the correct behavior for backward compatibility. This is done with a new "all" option. This option will become the default and removed after the 0.10 release. Co-authored-by: Christian Clason <c.clason@uni-graz.at> Co-authored-by: MDeiml <matthias@deiml.net> Co-authored-by: Gregory Anders <greg@gpanders.com>
2024-01-03refactor: format test/*Justin M. Keyes1
2023-12-24fix(treesitter): outdated highlight due to tree with outdated regionJaehwang Jung1
Problem: A region managed by an injected parser may shrink after re-running the injection query. If the updated region goes out of the range to be parsed, then the corresponding tree will remain outdated, possibly retaining the nodes that shouldn't exist anymore. This results in outdated highlights. Solution: Re-parse an invalid tree if its region intersects the range to be parsed.
2023-11-27fix(treesitter): don't invalidate parser when discovering injectionsDmytro Soltys1
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.
2023-08-31fix(query_error): multiline bugLewis Russell1
2023-08-31feat(treesitter): improve query error messageAmaan Qureshi1
2023-08-24feat(treesitter): add 'injection.self' and 'injection.parent'Amaan Qureshi1
Co-authored-by: ObserverOfTime <chronobserver@disroot.org>
2023-08-14fix(treesitter)!: remove deprecated legacy injection formatChristian Clason1
2023-08-13fix(treesitter): logger memory leakLewis Russell1
2023-08-12feat(treesitter)!: incremental injection parsingLewis Russell1
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.
2023-08-11feat(treesitter): add injection language fallback (#24659)Christian Clason1
* 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>
2023-08-07fix(treesitter): make sure injections don't return empty ranges (#24595)Lewis Russell1
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.
2023-07-27build(deps): bump tree-sitter-c to v0.20.4 (#24495)Christian Clason1
2023-07-07fix(treesitter): update folds in all relevant windows (#24230)Jaehwang Jung1
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.
2023-07-01feat(treesitter): bundle markdown parser and queries (#22481)Christian Clason1
* 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>