summaryrefslogtreecommitdiffstats
path: root/docs/manual/configuring/queries.md
blob: f07c8bf37a6fae89c51b29002114d545c47b54f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Queries (`vim.treesitter.queries`)

Queries allow you to change Neovim's behavior based on Tree-sitter.\
Read more about it in the
[neovim docs](https://neovim.io/doc/user/treesitter/#_treesitter-queries).

**Example:**

In the following example, we are creating a custom injection, to highlight the
Lua string after `mkLuaInline`.

```nix
let
  inherit (lib.generators) mkLuaInline;
in {
  foo = mkLuaInline ''
    function bar()
      return 'foobar'
    end
  '';
}
```

```nix
{
  vim.treesitter.queries = [{
    type = "injections";
    filetypes = ["nix"];
    loadtype = "extends";
    query = ''
      (apply_expression
        function: (variable_expression
          name: (identifier) @_func
          (#eq? @_func "mkLuaInline"))
        argument: (indented_string_expression
          (string_fragment) @injection.content)
        (#set! injection.language "lua")
        (#set! injection.combined))
    '';
  }];
}
```

This will generate a `queries/nix/injections.scm` in a Neovim runtime directory.

> [!NOTE]
> When multiple queries match the same `filetype` and `type`, they are merged.