Skip to content

Commit cc7ce20

Browse files
clasonlewis6991
authored andcommitted
ci: update and add query validation
using https://github.com/ribru17/ts_query_ls * bump nvim to v0.11.5 * update checkout action to v5 * add query lint job * add query format job * add query validation job
1 parent 7783c5e commit cc7ce20

File tree

4 files changed

+326
-7
lines changed

4 files changed

+326
-7
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- name: Checkout
21-
uses: actions/checkout@v4
21+
uses: actions/checkout@v5
2222

2323
- name: Download stylua
2424
run: make stylua
@@ -30,7 +30,7 @@ jobs:
3030
runs-on: ubuntu-latest
3131
steps:
3232
- name: Checkout
33-
uses: actions/checkout@v4
33+
uses: actions/checkout@v5
3434

3535
- uses: lewis6991/gh-actions-lua@master
3636
with:
@@ -44,21 +44,39 @@ jobs:
4444
- name: LuaLS
4545
run: make luals-check
4646

47+
tsqueryls:
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v5
52+
53+
- name: Download tsqueryls
54+
run: make tsqueryls
55+
56+
- name: Lint
57+
run: make tsqueryls-lint
58+
59+
- name: Format
60+
if: always()
61+
run: |
62+
make tsqueryls-format
63+
git diff --exit-code
64+
4765
test:
4866
runs-on: ubuntu-latest
4967

5068
strategy:
5169
fail-fast: false
5270
matrix:
5371
neovim_version:
54-
- 'v0.11.1'
72+
- 'v0.11.5'
5573

5674
env:
5775
NVIM_TEST_VERSION: ${{ matrix.neovim_version }}
5876

5977
steps:
6078
- name: Checkout
61-
uses: actions/checkout@v4
79+
uses: actions/checkout@v5
6280

6381
- uses: lewis6991/gh-actions-lua@master
6482
with:
@@ -88,3 +106,10 @@ jobs:
88106

89107
- name: Run Test
90108
run: make test
109+
110+
- name: Download tsqueryls
111+
run: make tsqueryls
112+
113+
- name: Validate queries
114+
run: make tsqueryls-check
115+

.github/workflows/nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
steps:
2121
- name: Checkout
22-
uses: actions/checkout@v4
22+
uses: actions/checkout@v5
2323

2424
- uses: leafo/gh-actions-lua@v11
2525
with:

.tsqueryrc.json

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/ribru17/ts_query_ls/refs/heads/master/schemas/config.json",
3+
"parser_install_directories": ["deps/nvim-treesitter-data/parser", "${HOME}/.local/share/nvim/site/parser"],
4+
"parser_aliases": {
5+
"ecma": "javascript",
6+
"jsx": "javascript"
7+
},
8+
"valid_captures": {
9+
"context": {
10+
"context": "specifies that the first line of this node will be used for the context",
11+
"context.start": "specifies that the context starts with the start of this node",
12+
"context.end": "specifies that the context ends before the start of this node",
13+
"context.final": "specifies that the context ends before the end of this node"
14+
}
15+
},
16+
"valid_predicates": {
17+
"eq": {
18+
"any": true,
19+
"parameters": [
20+
{
21+
"type": "capture",
22+
"arity": "required"
23+
},
24+
{
25+
"type": "any",
26+
"arity": "required"
27+
}
28+
],
29+
"description": "checks for equality between two nodes, or a node and a string"
30+
},
31+
"any-of": {
32+
"parameters": [
33+
{
34+
"type": "capture",
35+
"arity": "required"
36+
},
37+
{
38+
"type": "string",
39+
"arity": "required"
40+
},
41+
{
42+
"type": "string",
43+
"arity": "required"
44+
},
45+
{
46+
"type": "string",
47+
"arity": "variadic"
48+
}
49+
],
50+
"description": "match any of the given strings against the text corresponding to a node"
51+
},
52+
"contains": {
53+
"any": true,
54+
"parameters": [
55+
{
56+
"type": "capture",
57+
"arity": "required"
58+
},
59+
{
60+
"type": "string",
61+
"arity": "required"
62+
},
63+
{
64+
"type": "string",
65+
"arity": "variadic"
66+
}
67+
],
68+
"description": "match a string against parts of the text corresponding to a node"
69+
},
70+
"match": {
71+
"any": true,
72+
"parameters": [
73+
{
74+
"type": "capture",
75+
"arity": "required"
76+
},
77+
{
78+
"type": "string",
79+
"arity": "required"
80+
}
81+
],
82+
"description": "Match a regexp against the text corresponding to a node"
83+
},
84+
"lua-match": {
85+
"any": true,
86+
"parameters": [
87+
{
88+
"type": "capture",
89+
"arity": "required"
90+
},
91+
{
92+
"type": "string",
93+
"arity": "required"
94+
}
95+
],
96+
"description": "match a Lua pattern against the text corresponding to a node"
97+
},
98+
"has-ancestor": {
99+
"parameters": [
100+
{
101+
"type": "capture",
102+
"arity": "required"
103+
},
104+
{
105+
"type": "string",
106+
"arity": "required",
107+
"constraint": "named_node"
108+
},
109+
{
110+
"type": "string",
111+
"arity": "variadic",
112+
"constraint": "named_node"
113+
}
114+
],
115+
"description": "match any of the given node types against all ancestors of a node"
116+
},
117+
"has-parent": {
118+
"parameters": [
119+
{
120+
"type": "capture",
121+
"arity": "required"
122+
},
123+
{
124+
"type": "string",
125+
"arity": "required",
126+
"constraint": "named_node"
127+
},
128+
{
129+
"type": "string",
130+
"arity": "variadic",
131+
"constraint": "named_node"
132+
}
133+
],
134+
"description": "match any of the given node types against the direct ancestor of a node"
135+
},
136+
"kind-eq": {
137+
"parameters": [
138+
{
139+
"type": "capture",
140+
"arity": "required"
141+
},
142+
{
143+
"type": "string",
144+
"arity": "required",
145+
"constraint": "named_node"
146+
},
147+
{
148+
"type": "string",
149+
"arity": "variadic",
150+
"constraint": "named_node"
151+
}
152+
],
153+
"description": "checks whether a capture corresponds to a given set of nodes"
154+
}
155+
},
156+
"valid_directives": {
157+
"set": {
158+
"parameters": [
159+
{
160+
"type": "any",
161+
"arity": "required"
162+
},
163+
{
164+
"type": "any",
165+
"arity": "optional"
166+
},
167+
{
168+
"type": "any",
169+
"arity": "optional"
170+
}
171+
],
172+
"description": "sets key/value metadata for a specific match or capture"
173+
},
174+
"offset": {
175+
"parameters": [
176+
{
177+
"type": "capture",
178+
"arity": "required"
179+
},
180+
{
181+
"type": "string",
182+
"arity": "required",
183+
"constraint": "integer"
184+
},
185+
{
186+
"type": "string",
187+
"arity": "required",
188+
"constraint": "integer"
189+
},
190+
{
191+
"type": "string",
192+
"arity": "required",
193+
"constraint": "integer"
194+
},
195+
{
196+
"type": "string",
197+
"arity": "required",
198+
"constraint": "integer"
199+
}
200+
],
201+
"description": "Takes the range of the captured node and applies an offset. This will set a new range in the form of a list like { {start_row}, {start_col}, {end_row}, {end_col} } for the captured node with `capture_id` as `metadata[capture_id].range`."
202+
},
203+
"gsub": {
204+
"parameters": [
205+
{
206+
"type": "capture",
207+
"arity": "required"
208+
},
209+
{
210+
"type": "string",
211+
"arity": "required"
212+
},
213+
{
214+
"type": "string",
215+
"arity": "required"
216+
}
217+
],
218+
"description": "Transforms the content of the node using a Lua pattern. This will set a new `metadata[capture_id].text`."
219+
},
220+
"trim": {
221+
"parameters": [
222+
{
223+
"type": "capture",
224+
"arity": "required"
225+
},
226+
{
227+
"type": "string",
228+
"arity": "optional",
229+
"constraint": {
230+
"enum": ["0", "1"]
231+
}
232+
},
233+
{
234+
"type": "string",
235+
"arity": "optional",
236+
"constraint": {
237+
"enum": ["0", "1"]
238+
}
239+
},
240+
{
241+
"type": "string",
242+
"arity": "optional",
243+
"constraint": {
244+
"enum": ["0", "1"]
245+
}
246+
},
247+
{
248+
"type": "string",
249+
"arity": "optional",
250+
"constraint": {
251+
"enum": ["0", "1"]
252+
}
253+
}
254+
],
255+
"description": "Trims whitespace from the node. Sets a new `metadata[capture_id].range`. Takes a capture ID and, optionally, four integers to customize trimming behavior (`1` meaning trim, `0` meaning don't trim). When only given a capture ID, trims blank lines (lines that contain only whitespace, or are empty) from the end of the node (for backwards compatibility). Can trim all whitespace from both sides of the node if parameters are given."
256+
}
257+
}
258+
}

Makefile

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ $(NVIM_TS):
2424

2525
FILTER=.*
2626

27-
export NVIM_TEST_VERSION ?= v0.11.1
28-
export NVIM_RUNNER_VERSION ?= v0.11.1
27+
export NVIM_TEST_VERSION ?= v0.11.5
28+
export NVIM_RUNNER_VERSION ?= v0.11.5
2929

3030
NVIM_TEST := deps/nvim-test
3131
NVIM_TEST_REV = v1.1.0
@@ -127,3 +127,39 @@ stylua-check: $(STYLUA)
127127
stylua-run: $(STYLUA)
128128
$(STYLUA) $(LUA_FILES)
129129
perl -pi -e 's/---@/--- @/g' $(LUA_FILES)
130+
131+
# ------------------------------------------------------------------------------
132+
# Tsqueryls
133+
# ------------------------------------------------------------------------------
134+
ifeq ($(shell uname -s),Darwin)
135+
TSQUERYLS_PLATFORM := aarch64-apple-darwin
136+
else
137+
TSQUERYLS_PLATFORM := x86_64-unknown-linux-gnu
138+
endif
139+
140+
TSQUERYLS := deps/ts_query_ls-$(TSQUERYLS_PLATFORM)
141+
TSQUERYLS_TARBALL := $(TSQUERYLS).tar.gz
142+
TSQUERYLS_URL := https://github.com/ribru17/ts_query_ls/releases/latest/download/$(notdir $(TSQUERYLS_TARBALL))
143+
144+
.PHONY: tsqueryls
145+
tsqueryls: $(TSQUERYLS)
146+
147+
$(TSQUERYLS):
148+
wget --directory-prefix=$(dir $@) $(TSQUERYLS_URL)
149+
mkdir -p $@
150+
tar -xf $(TSQUERYLS_TARBALL) -C $@
151+
rm -rf $(TSQUERYLS_TARBALL)
152+
153+
QUERIES := queries/
154+
155+
.PHONY: tsqueryls-lint
156+
tsqueryls-lint: $(TSQUERYLS)
157+
$(TSQUERYLS)/ts_query_ls lint $(QUERIES)
158+
159+
.PHONY: tsqueryls-format
160+
tsqueryls-format: $(TSQUERYLS)
161+
$(TSQUERYLS)/ts_query_ls format $(QUERIES)
162+
163+
.PHONY: tsqueryls-check
164+
tsqueryls-check: $(TSQUERYLS)
165+
$(TSQUERYLS)/ts_query_ls check $(QUERIES)

0 commit comments

Comments
 (0)