aboutsummaryrefslogtreecommitdiff
path: root/test/functional/treesitter/highlight_spec.lua
Commit message (Collapse)AuthorAge
* 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()`
* test(screen): adjust screen state per stylua #31441luukvbaal2024-12-04
| | | | | | | | | | | | | | | | | | | | | | | | | Before: screen:expect({ | screen:expect({ grid = [[ | grid = [[ {10:>!}a | | line ^1 | {7: }b | | {1:~ }|*4 {10:>>}c | | ]], messages={ { {7: }^ | | content = { { "\ntest\n[O]k: ", 6, 11 } }, {1:~ }|*9 | kind = "confirm" | | } } ]] | }) }) After: screen:expect([[ | screen:expect({ {10:>!}a | | grid = [[ {7: }b | | line ^1 | {10:>>}c | | {1:~ }|*4 {7: }^ | | ]], {1:~ }|*9 | messages = { { | | content = { { "\ntest\n[O]k: ", 6, 11 } }, ]]) | kind = "confirm" | } }, | })
* test(treesitter): global highlight definitions and fold test #31407luukvbaal2024-12-02
| | | | Add test for foldtext= highlighting. Change file to global highlight definitions while at it.
* fix(treesitter): update queriesChristian Clason2024-11-22
|
* fix(tests): needing two calls to setup a screen is cringebfredl2024-11-14
| | | | | | | | | | Before calling "attach" a screen object is just a dummy container for (row, col) values whose purpose is to be sent as part of the "attach" function call anyway. Just create the screen in an attached state directly. Keep the complete (row, col, options) config together. It is still completely valid to later detach and re-attach as needed, including to another session.
* feat(defaults): pretty :help headings #30544Justin M. Keyes2024-09-27
| | | | | | | | | | | | | | Problem: Headings in :help do not stand out visually. Solution: Define a non-standard `@markup.heading.1.delimiter` group and special-case it in `highlight_group.c`. FUTURE: This is a cheap workaround until we have #25718 which will enable: - fully driven by `vimdoc/highlights.scm` instead of using highlight tricks (`guibg=bg guifg=bg guisp=fg`) - better support of "cterm" ('notermguicolors')
* test: support upvalues in exec_luaLewis Russell2024-09-21
|
* test: allow exec_lua to handle functionsLewis Russell2024-08-02
| | | | | | | | | | | 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.
* fix(runtime): sync bundled treesitter queriesChristian Clason2024-07-24
|
* test: starting and stopping treesitter highlight (#29546)zeertzjq2024-07-03
|
* fix(treesitter): ensure syntaxset augroup exists (#29542)zeertzjq2024-07-03
| | | | | | | | Problem: Error when calling vim.treesitter.start() and vim.treesitter.stop() in init.lua. Solution: Ensure syntaxset augroup exists after loading synload.vim.
* fix(treesitter): do not modify highlight state for _on_spell_navLuuk van Baal2024-06-24
| | | | | | | | Problem: Treesitter highlighter clears the already populated highlight state when performing spell checking while drawing a smoothscrolled topline. Solution: Save and restore the highlight state in the highlighter's _on_spell_nav callback.
* fix(treesitter): enforce lowercase language names (#28546)Christian Clason2024-04-28
| | | | | | | | | | | * fix(treesitter): enforce lowercase language names Problem: On case-insensitive file systems (e.g., macOS), `has_parser` will return `true` for uppercase aliases, which will then try to inject the uppercase language unsuccessfully. Solution: Enforce and assume parser names to be lowercase when resolving language names.
* test: improve test conventionsdundargoc2024-04-23
| | | | | | | | | 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.
* refactor(test): inject after_each differentlyLewis Russell2024-04-10
|
* test: improve test conventionsdundargoc2024-04-08
| | | | Work on https://github.com/neovim/neovim/issues/27004.
* feat(treesitter): update Vimdoc parser and queries to v2.4.0Christian Clason2024-03-19
|
* fix(messages): allow more prompt in headless mode with UI (#27905)zeertzjq2024-03-18
| | | | | Problem: More prompt is not shown in headless mode even if there is a UI attached. Solution: Don't skip more prompt when there is a UI active.
* fix(treesitter): revert to using iter_captures in highlighterLewis Russell2024-03-17
| | | | Fixes #27895
* fix(treesitter): highlight injections properlyLewis Russell2024-03-14
| | | | | `on_line_impl` doesn't highlight single lines, so using pattern indexes to offset priority doesn't work.
* feat(treesitter): support URLs (#27132)Gregory Anders2024-03-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Tree-sitter queries can add URLs to a capture using the `#set!` directive, e.g. (inline_link (link_text) @text.reference (link_destination) @text.uri (#set! @text.reference "url" @text.uri)) The pattern above is included by default in the `markdown_inline` highlight query so that users with supporting terminals will see hyperlinks. For now, this creates a hyperlink for *all* Markdown URLs of the pattern [link text](link url), even if `link url` does not contain a valid protocol (e.g. if `link url` is a path to a file). We may wish to change this in the future to only linkify when the URL has a valid protocol scheme, but for now we delegate handling this to the terminal emulator. In order to support directives which reference other nodes, the highlighter must be updated to use `iter_matches` rather than `iter_captures`. The former provides the `match` table which maps capture IDs to nodes. However, this has its own challenges: - `iter_matches` does not guarantee the order in which patterns are iterated matches the order in the query file. So we must enforce ordering manually using "subpriorities" (#27131). The pattern index of each match dictates the extmark's subpriority. - When injections are used, the highlighter contains multiple trees. The pattern indices of each tree must be offset relative to the maximum pattern index from all previous trees to ensure that extmarks appear in the correct order. - The `iter_captures` implementation currently has a bug where the "match" table is only returned for the first capture within a pattern (see #27274). This bug means that `#set!` directives in a query apply only to the first capture within a pattern. Unfortunately, many queries in the wild have come to depend on this behavior. `iter_matches` does not share this flaw, so switching to `iter_matches` exposed bugs in existing highlight queries. These queries have been updated in this repo, but may still need to be updated by users. The `#set!` directive applies to the _entire_ query pattern when used without a capture argument. To make `#set!` apply only to a single capture, the capture must be given as an argument.
* test(treesitter): fix obsolete predicatesChristian Clason2024-02-21
|
* fix(treesitter): correctly handle query quantifiers (#24738)Thomas Vigouroux2024-02-16
| | | | | | | | | | | | | | | | | | | 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>
* fix(runtime): update 'vim' color scheme to use new tree-sitter groupsEvgeni Chasnovski2024-01-25
|
* fix(treesitter): update @markup default linksChristian Clason2024-01-23
| | | | | | | | * use `Special` as default for `@markup.*`, especially `@markup.raw` and `@markup.math` (`@markup` itself is never used) * use `Structure` for `@markup.environment` * highlight all of `@markup.link` as Underlined (otherwise concealed links are invisible)
* feat(treesitter)!: new standard capture namesChristian Clason2024-01-21
| | | | | | | | | | | | | | Problem: Sharing queries with upstream and Helix is difficult due to different capture names. Solution: Define and document a new set of standard captures that matches tree-sitter "standard captures" (where defined) and is closer to Helix' Atom-style nested groups. This is a breaking change for colorschemes that defined highlights based on the old captures. On the other hand, the default colorscheme now defines links for all standard captures (not just those used in bundled queries), improving the out-of-the-box experience.
* test: rename (meths, funcs) -> (api, fn)Lewis Russell2024-01-12
|
* test: normalise nvim bridge functionsLewis Russell2024-01-12
| | | | | - remove helpers.cur*meths - remove helpers.nvim
* test: typing for helpers.methsLewis Russell2024-01-12
|
* refactor: format test/*Justin M. Keyes2024-01-03
|
* test: avoid repeated screen lines in expected stateszeertzjq2023-12-09
| | | | | | This is the command invoked repeatedly to make the changes: :%s/^\(.*\)|\%(\*\(\d\+\)\)\?$\n\1|\%(\*\(\d\+\)\)\?$/\=submatch(1)..'|*'..(max([str2nr(submatch(2)),1])+max([str2nr(submatch(3)),1]))/g
* 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.
* 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
* fix(treesitter)!: remove deprecated legacy injection formatChristian Clason2023-08-14
|
* feat(treesitter): update C queries from upstreamChristian Clason2023-08-13
|
* fix(treesitter): redraw added/removed injections properly (#23287)Lewis Russell2023-04-30
| | | | | | When injections are added or removed make sure to: - invoke 'changedtree' callbacks for when new trees are added. - invoke 'changedtree' callbacks for when trees are invalidated - redraw regions when languagetree children are removed
* refactor: remove char_u (#22829)dundargoc2023-04-02
| | | Closes https://github.com/neovim/neovim/issues/459
* fix(tests): adapt treesitter/highlight_spec priority testChristian Clason2023-04-01
| | | | | Still relied on the old `@Foo`->`Foo` capture to highlight mechanism; use capture with default highlight instead.
* feat(treesitter)!: deprecate top level indexes to modules (#22761)Lewis Russell2023-03-24
| | | | | | | | | | | | | | | | | The following top level Treesitter functions have been moved: - vim.treesitter.inspect_language() -> vim.treesitter.language.inspect() - vim.treesitter.get_query_files() -> vim.treesitter.query.get_files() - vim.treesitter.set_query() -> vim.treesitter.query.set() - vim.treesitter.query.set_query() -> vim.treesitter.query.set() - vim.treesitter.get_query() -> vim.treesitter.query.get() - vim.treesitter.query.get_query() -> vim.treesitter.query.get() - vim.treesitter.parse_query() -> vim.treesitter.query.parse() - vim.treesitter.query.parse_query() -> vim.treesitter.query.parse() - vim.treesitter.add_predicate() -> vim.treesitter.query.add_predicate() - vim.treesitter.add_directive() -> vim.treesitter.query.add_directive() - vim.treesitter.list_predicates() -> vim.treesitter.query.list_predicates() - vim.treesitter.list_directives() -> vim.treesitter.query.list_directives() - vim.treesitter.query.get_range() -> vim.treesitter.get_range() - vim.treesitter.query.get_node_text() -> vim.treesitter.get_node_text()
* feat: `vim.inspect_pos`, `vim.show_pos`, `:Inspect`Folke Lemaitre2022-12-17
|
* refactor(treesitter): rename x_position => x_posJustin M. Keyes2022-09-25
| | | | | "pos" has a long precedent as "position" in vim, and there is no reason to use a verbose name here.
* fix(treesitter): return full metadata for get_captures_at_position (#20203)Christian Clason2022-09-16
| | | | | | | | fix(treesitter): get_captures_at_position returns metadata Return the full `metadata` table for the capture instead of just the priority. Further cleanup of related docs.
* fix(treesitter): do not link @error by defaultChristian Clason2022-09-06
| | | | | | | The @error capture is used for tree-sitter's ERROR node, which indicates a parsing error -- which can be quite frequent (and jarring) while typing. Users can still manually `hi link @error Error` in their config.
* feat(treesitter): add injectionsChristian Clason2022-09-06
|
* ci(tests): don't skip parsers on functionaltestChristian Clason2022-09-06
| | | | | Treesitter parsers are now a mandatory part of the installation and should be tested on all platforms. Remove `pending_c_parser` helper.
* fix(treesitter): make it get_captures_at_positionbfredl2022-08-26
|
* feat(treesitter)!: use @foo.bar style highlight groupsbfredl2022-08-26
| | | | | | | | | | | | This removes the support for defining links via vim.treesitter.highlighter.hl_map (never documented, but plugins did anyway), or the uppercase-only `@FooGroup.Bar` to `FooGroup` rule. The fallback is now strictly `@foo.bar.lang` to `@foo.bar` to `@foo`, and casing is irrelevant (as it already was outside of treesitter) For compatibility, define default links to builting syntax groups as defined by pre-existing color schemes
* feat(ui): allow conceal to be defined in decorationsbfredl2022-03-20
| | | | | | Unlike syntax conceal, change highlight of concealed char Can be used in tree-sitter using "conceal" metadata.
* feat(tree-sitter): allow Atom-style capture fallbacks (#14196)Stephan Seitz2022-02-16
| | | | | | | | | This allows falling back to `@definition` when we have no mapping `@definition.fancy-specialization`. This behavior is described in tree-sitter's documentation (https://tree-sitter.github.io/tree-sitter/syntax-highlighting#theme). Fixes https://github.com/nvim-treesitter/nvim-treesitter/issues/738
* feat(treesitter): allow to set highlight priority for queriesStephan Seitz2021-07-22
|