| 1 | ## Adding tags queries |
| 2 | |
| 3 | See tree-sitter's documentation on [Code Navigation Systems] for more |
| 4 | background on tags queries. |
| 5 | |
| 6 | Helix provides LSP-like features such as document and workspace symbol pickers |
| 7 | out-of-the-box for languages with `tags.scm` queries based on syntax trees. To |
| 8 | be analyzed a language must have a tree-sitter grammar and a `tags.scm` query |
| 9 | file which pattern matches interesting nodes from syntax trees. |
| 10 | |
| 11 | Query files should be placed in `runtime/queries/{language}/tags.scm` |
| 12 | when contributing to Helix. You may place these under your local runtime |
| 13 | directory (`~/.config/helix/runtime` in Linux for example) for the sake of |
| 14 | testing. |
| 15 | |
| 16 | ## Captures |
| 17 | |
| 18 | ### `@definition.*` |
| 19 | |
| 20 | Marks a node as a symbol definition. The following definition captures are |
| 21 | recognized: |
| 22 | |
| 23 | | Capture name | |
| 24 | |--- | |
| 25 | | `definition.class` | |
| 26 | | `definition.constant` | |
| 27 | | `definition.enum` | |
| 28 | | `definition.field` | |
| 29 | | `definition.function` | |
| 30 | | `definition.interface` | |
| 31 | | `definition.macro` | |
| 32 | | `definition.module` | |
| 33 | | `definition.section` | |
| 34 | | `definition.struct` | |
| 35 | | `definition.type` | |
| 36 | |
| 37 | Captures outside this list are ignored by the symbol pickers, so map a |
| 38 | language-specific construct onto the closest listed kind rather than inventing a |
| 39 | new one. |
| 40 | |
| 41 | ### `@name` |
| 42 | |
| 43 | Marks the name identifier node within a match. `@definition.*` should capture |
| 44 | the entire definition node, and `@name` should capture the name identifier |
| 45 | within that same match: |
| 46 | |
| 47 | ```scm |
| 48 | (function_definition |
| 49 | name: (identifier) @name) @definition.function |
| 50 | |
| 51 | (class_definition |
| 52 | name: (identifier) @name) @definition.class |
| 53 | ``` |
| 54 | |
| 55 | ### `@reference.*` |
| 56 | |
| 57 | Marks a node as a call site or type reference. These are used by workspace |
| 58 | symbol search to locate usages. `@reference.call` and `@reference.class` are |
| 59 | the common variants. As with definitions, `@name` captures the identifier: |
| 60 | |
| 61 | ```scm |
| 62 | (call |
| 63 | function: (identifier) @name) @reference.call |
| 64 | ``` |
| 65 | |
| 66 | [Example query files][example-queries] can be found in the Helix GitHub |
| 67 | repository. |
| 68 | |
| 69 | [Code Navigation Systems]: https://tree-sitter.github.io/tree-sitter/4-code-navigation.html |
| 70 | [example-queries]: https://github.com/search?q=repo%3Ahelix-editor%2Fhelix+path%3A%2A%2A/tags.scm&type=Code |