mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-15 01:40:02 -04:00
ci: check capture names in queries
This commit is contained in:
parent
4b578c52bd
commit
5d2b866518
2 changed files with 70 additions and 25 deletions
|
|
@ -84,19 +84,20 @@ are optional and will not have any effect for now.
|
||||||
```
|
```
|
||||||
@embedded
|
@embedded
|
||||||
@injection
|
@injection
|
||||||
language
|
@injection.language
|
||||||
content
|
@injection.content
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Constants
|
#### Constants
|
||||||
|
|
||||||
```
|
```
|
||||||
@constant
|
@constant
|
||||||
builtin
|
@constant.builtin
|
||||||
macro
|
@constant.macro
|
||||||
@string
|
@string
|
||||||
regex
|
@string.regex
|
||||||
escape
|
@string.escape
|
||||||
|
@string.special
|
||||||
@character
|
@character
|
||||||
@number
|
@number
|
||||||
@boolean
|
@boolean
|
||||||
|
|
@ -107,13 +108,13 @@ are optional and will not have any effect for now.
|
||||||
|
|
||||||
```
|
```
|
||||||
@function
|
@function
|
||||||
builtin
|
@function.builtin
|
||||||
macro
|
@function.macro
|
||||||
@parameter
|
@parameter
|
||||||
reference references to parameters
|
|
||||||
|
|
||||||
@method
|
@method
|
||||||
@field or @property
|
@field
|
||||||
|
@property
|
||||||
|
|
||||||
@constructor
|
@constructor
|
||||||
```
|
```
|
||||||
|
|
@ -126,19 +127,20 @@ are optional and will not have any effect for now.
|
||||||
@label for C/Lua-like labels
|
@label for C/Lua-like labels
|
||||||
@operator
|
@operator
|
||||||
@keyword
|
@keyword
|
||||||
function
|
@keyword.function
|
||||||
@exception
|
@exception
|
||||||
@include keywords for including modules (e.g. import/from in Python)
|
@include keywords for including modules (e.g. import/from in Python)
|
||||||
|
|
||||||
@type
|
@type
|
||||||
builtin
|
@type.builtin
|
||||||
@structure
|
@structure
|
||||||
|
@attribute for e.g. Python decorators
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Variables
|
#### Variables
|
||||||
```
|
```
|
||||||
@variable
|
@variable
|
||||||
builtin
|
@variable.builtin
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Text
|
#### Text
|
||||||
|
|
@ -158,15 +160,19 @@ Mainly for markup languages.
|
||||||
### Locals
|
### Locals
|
||||||
```
|
```
|
||||||
@definition for various definitions
|
@definition for various definitions
|
||||||
function
|
@definition.function
|
||||||
method
|
@definition.method
|
||||||
var
|
@definition.var
|
||||||
macro
|
@definition.parameter
|
||||||
type
|
@definition.macro
|
||||||
field
|
@definition.type
|
||||||
namespace for modules or C++ namespaces
|
@definition.field
|
||||||
import for imported names
|
@definition.enum
|
||||||
doc for documentation adjacent to a definition. E.g.
|
@definition.namespace for modules or C++ namespaces
|
||||||
|
@definition.import for imported names
|
||||||
|
|
||||||
|
@definition.associated to determine the type of a variable
|
||||||
|
@definition.doc for documentation adjacent to a definition. E.g.
|
||||||
```
|
```
|
||||||
|
|
||||||
```scheme
|
```scheme
|
||||||
|
|
@ -178,6 +184,7 @@ Mainly for markup languages.
|
||||||
```
|
```
|
||||||
@scope
|
@scope
|
||||||
@reference
|
@reference
|
||||||
|
@constructor
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Definition Scope
|
#### Definition Scope
|
||||||
|
|
@ -208,7 +215,11 @@ Possible scope values are:
|
||||||
|
|
||||||
### Folds
|
### Folds
|
||||||
|
|
||||||
You can define folds for a given language by adding a `fold.scm` query.
|
You can define folds for a given language by adding a `fold.scm` query :
|
||||||
The `@fold` capture is used to fold a node.
|
|
||||||
|
```
|
||||||
|
@fold
|
||||||
|
```
|
||||||
|
|
||||||
If the `fold.scm` query is not present, this will fallback to the `@scope` captures in the `locals`
|
If the `fold.scm` query is not present, this will fallback to the `@scope` captures in the `locals`
|
||||||
query.
|
query.
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,47 @@
|
||||||
-- Execute as `nvim --headless -c "luafile ./scripts/check-queries.lua"`
|
-- Execute as `nvim --headless -c "luafile ./scripts/check-queries.lua"`
|
||||||
|
|
||||||
|
local function extract_captures()
|
||||||
|
local lines = vim.fn.readfile("CONTRIBUTING.md")
|
||||||
|
local captures = {}
|
||||||
|
local current_query
|
||||||
|
|
||||||
|
for _, line in ipairs(lines) do
|
||||||
|
if vim.startswith(line, "### ") then
|
||||||
|
current_query = vim.fn.tolower(line:sub(5))
|
||||||
|
elseif vim.startswith(line, "@") and current_query then
|
||||||
|
if not captures[current_query] then
|
||||||
|
captures[current_query] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(captures[current_query], vim.split(line:sub(2), " ", true)[1])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return captures
|
||||||
|
end
|
||||||
|
|
||||||
local function do_check()
|
local function do_check()
|
||||||
local parsers = require 'nvim-treesitter.parsers'.available_parsers()
|
local parsers = require 'nvim-treesitter.parsers'.available_parsers()
|
||||||
local queries = require 'nvim-treesitter.query'
|
local queries = require 'nvim-treesitter.query'
|
||||||
local query_types = queries.built_in_query_groups
|
local query_types = queries.built_in_query_groups
|
||||||
|
|
||||||
|
local captures = extract_captures()
|
||||||
|
|
||||||
for _, lang in pairs(parsers) do
|
for _, lang in pairs(parsers) do
|
||||||
for _, query_type in pairs(query_types) do
|
for _, query_type in pairs(query_types) do
|
||||||
print('Checking '..lang..' '..query_type)
|
print('Checking '..lang..' '..query_type)
|
||||||
queries.get_query(lang, query_type)
|
local query = queries.get_query(lang, query_type)
|
||||||
|
|
||||||
|
if query then
|
||||||
|
for _, capture in ipairs(query.captures) do
|
||||||
|
if not vim.startswith(capture, "_") -- We ignore things like _helper
|
||||||
|
and captures[query_type]
|
||||||
|
and not capture:find("^[A-Z]") -- Highlight groups
|
||||||
|
and not vim.tbl_contains(captures[query_type], capture) then
|
||||||
|
error(string.format("Invalid capture @%s in %s for %s.", capture, query_type, lang))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue