Skip to content

Commit da605af

Browse files
Merge pull request #159 from ember-tooling/sync-injections-with-nvim-treesitter
Sync injections with nvim treesitter
2 parents 5b54907 + 69b18de commit da605af

File tree

7 files changed

+623
-65
lines changed

7 files changed

+623
-65
lines changed

Diff for: .github/workflows/linting.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Linting
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
- main
9+
10+
concurrency:
11+
group: ${{github.workflow}}-${{github.ref}}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
js:
16+
name: "JavaScript"
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
- uses: actions/setup-node@v4
22+
- run: npm install
23+
- run: npm exec prettier --check .
24+
25+
format-queries:
26+
name: Queries
27+
runs-on: ubuntu-latest
28+
env:
29+
NVIM_TAG: nightly
30+
# NVIM_TAG: stable
31+
steps:
32+
- uses: actions/checkout@v4
33+
- name: Prepare
34+
run: |
35+
bash ./scripts/ci-install.sh
36+
37+
- name: Lint
38+
run: |
39+
nvim --version
40+
nvim --headless -c "TSInstallSync query" -c "q"
41+
nvim -l scripts/format-queries.lua
42+
git diff --exit-code

Diff for: queries/glimmer/folds.scm

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[
2-
(element_node (element_node_start))
3-
(block_statement)
2+
(element_node
3+
(element_node_start))
4+
(block_statement)
45
] @fold

Diff for: queries/glimmer/highlights.scm

+68-39
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,113 @@
11
; === Tag Names ===
2-
32
; Tags that start with a lower case letter are HTML tags
43
; We'll also use this highlighting for named blocks (which start with `:`)
54
((tag_name) @tag
6-
(#match? @tag "^(:)?[a-z]"))
5+
(#lua-match? @tag "^:?[%l]"))
6+
77
; Tags that start with a capital letter are Glimmer components
88
((tag_name) @constructor
9-
(#match? @constructor "^[A-Z]"))
9+
(#lua-match? @constructor "^%u"))
1010

11-
(attribute_name) @property
11+
(attribute_name) @attribute
1212

1313
(string_literal) @string
14+
1415
(number_literal) @number
16+
1517
(boolean_literal) @boolean
1618

1719
(concat_statement) @string
1820

1921
; === Block Statements ===
20-
2122
; Highlight the brackets
2223
(block_statement_start) @tag.delimiter
24+
2325
(block_statement_end) @tag.delimiter
2426

2527
; Highlight `if`/`each`/`let`
26-
(block_statement_start path: (identifier) @conditional)
27-
(block_statement_end path: (identifier) @conditional)
28-
((mustache_statement (identifier) @conditional)
29-
(#match? @conditional "else"))
28+
(block_statement_start
29+
path: (identifier) @keyword.conditional)
3030

31-
; == Mustache Statements ===
31+
(block_statement_end
32+
path: (identifier) @keyword.conditional)
33+
34+
((mustache_statement
35+
(identifier) @keyword.conditional)
36+
(#lua-match? @keyword.conditional "else"))
3237

33-
; Hightlight the whole statement, to color brackets and separators
38+
; == Mustache Statements ===
39+
; Highlight the whole statement, to color brackets and separators
3440
(mustache_statement) @tag.delimiter
3541

3642
; An identifier in a mustache expression is a variable
37-
((mustache_statement [
38-
(path_expression (identifier) @variable)
39-
(identifier) @variable
43+
((mustache_statement
44+
[
45+
(path_expression
46+
(identifier) @variable)
47+
(identifier) @variable
4048
])
41-
(#not-match? @variable "yield|outlet|this|else"))
49+
(#not-any-of? @variable "yield" "outlet" "this" "else"))
50+
4251
; As are arguments in a block statement
43-
(block_statement_start argument: [
44-
(path_expression (identifier) @variable)
45-
(identifier) @variable
52+
(block_statement_start
53+
argument: [
54+
(path_expression
55+
(identifier) @variable)
56+
(identifier) @variable
4657
])
58+
4759
; As is an identifier in a block param
48-
(block_params (identifier) @variable)
60+
(block_params
61+
(identifier) @variable)
62+
4963
; As are helper arguments
50-
((helper_invocation argument: [
51-
(path_expression (identifier) @variable)
52-
(identifier) @variable
64+
((helper_invocation
65+
argument: [
66+
(path_expression
67+
(identifier) @variable)
68+
(identifier) @variable
5369
])
54-
(#not-match? @variable "this"))
70+
(#not-eq? @variable "this"))
71+
5572
; `this` should be highlighted as a built-in variable
5673
((identifier) @variable.builtin
57-
(#match? @variable.builtin "this"))
74+
(#eq? @variable.builtin "this"))
5875

5976
; If the identifier is just "yield" or "outlet", it's a keyword
60-
((mustache_statement (identifier) @keyword)
61-
(#match? @keyword "yield|outlet"))
77+
((mustache_statement
78+
(identifier) @keyword)
79+
(#any-of? @keyword "yield" "outlet"))
6280

6381
; Helpers are functions
64-
((helper_invocation helper: [
65-
(path_expression (identifier) @function)
66-
(identifier) @function
82+
((helper_invocation
83+
helper: [
84+
(path_expression
85+
(identifier) @function)
86+
(identifier) @function
6787
])
68-
(#not-match? @function "if|yield"))
69-
((helper_invocation helper: (identifier) @conditional)
70-
(#match? @conditional "if"))
71-
((helper_invocation helper: (identifier) @keyword)
72-
(#match? @keyword "yield"))
88+
(#not-any-of? @function "if" "yield"))
89+
90+
((helper_invocation
91+
helper: (identifier) @keyword.conditional)
92+
(#eq? @keyword.conditional "if"))
93+
94+
((helper_invocation
95+
helper: (identifier) @keyword)
96+
(#eq? @keyword "yield"))
97+
98+
(hash_pair
99+
key: (identifier) @property)
73100

74-
(hash_pair key: (identifier) @property)
101+
(comment_statement) @comment @spell
75102

76-
(comment_statement) @comment
103+
(attribute_node
104+
"=" @operator)
77105

78-
(attribute_node "=" @operator)
106+
(block_params
107+
"as" @keyword)
79108

80-
(block_params "as" @keyword)
81-
(block_params "|" @operator)
109+
(block_params
110+
"|" @operator)
82111

83112
[
84113
"<"

Diff for: queries/glimmer/indents.scm

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
[
2-
(element_node (element_node_start))
2+
(element_node
3+
(element_node_start))
34
(element_node_void)
4-
(block_statement (block_statement_start))
5+
(block_statement
6+
(block_statement_start))
57
(mustache_statement)
68
] @indent.begin
79

8-
(element_node (element_node_end [">"] @indent.end))
9-
(element_node_void "/>" @indent.end)
10+
(element_node
11+
(element_node_end
12+
">" @indent.end))
13+
14+
(element_node_void
15+
"/>" @indent.end)
16+
1017
[
11-
">"
12-
"/>"
13-
"</"
18+
">"
19+
"/>"
20+
"</"
1421
"{{/"
1522
"}}"
16-
] @indent.branch
23+
] @indent.branch
1724

1825
(mustache_statement
19-
(helper_invocation helper: (identifier) @_identifier (#lua-match? @_identifier "else"))
20-
) @indent.branch
21-
(mustache_statement ((identifier) @_identifier (#lua-match? @_identifier "else"))) @indent.branch
26+
(helper_invocation
27+
helper: (identifier) @_identifier
28+
(#eq? @_identifier "else"))) @indent.branch
29+
30+
(mustache_statement
31+
((identifier) @_identifier
32+
(#eq? @_identifier "else"))) @indent.branch
33+
2234
(comment_statement) @indent.ignore

Diff for: queries/glimmer/injections.scm

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
; comments
22
((comment_statement) @injection.content
3-
(#set! injection.language "comment"))
3+
(#set! injection.language "comment"))
44

55
; <style> tags
66
((element_node
77
(element_node_start
88
(tag_name) @_tag_name
9-
(#eq? @_tag_name "style")
10-
)
11-
)
12-
@injection.content
9+
(#eq? @_tag_name "style"))) @injection.content
1310
(#offset! @injection.content 0 7 0 -8)
1411
(#set! injection.language "css")
15-
(#set! injection.include-children)
16-
)
12+
(#set! injection.include-children))
1713

1814
; <script> tags
1915
((element_node
2016
(element_node_start
2117
(tag_name) @_tag_name
22-
(#eq? @_tag_name "script")
23-
)
24-
)
25-
@injection.content
18+
(#eq? @_tag_name "script"))) @injection.content
2619
(#offset! @injection.content 0 8 0 -9)
2720
(#set! injection.language "glimmer_javascript")
28-
(#set! injection.include-children)
29-
)
21+
(#set! injection.include-children))

Diff for: scripts/ci-install.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
mkdir -p /tmp/ci-linting/
6+
cd /tmp/ci-linting/
7+
git clone https://github.com/nvim-treesitter/nvim-treesitter.git
8+
cd nvim-treesitter
9+
10+
os=$(uname -s)
11+
if [[ $os == Linux ]]; then
12+
wget https://github.com/neovim/neovim/releases/download/${NVIM_TAG}/nvim-linux64.tar.gz
13+
tar -zxf nvim-linux64.tar.gz
14+
sudo ln -s "$PWD"/nvim-linux64/bin/nvim /usr/local/bin
15+
rm -rf "$PWD"/nvim-linux64/lib/nvim/parser
16+
mkdir -p ~/.local/share/nvim/site/pack/nvim-treesitter/start
17+
ln -s "$PWD" ~/.local/share/nvim/site/pack/nvim-treesitter/start
18+
elif [[ $os == Darwin ]]; then
19+
RELEASE_NAME="nvim-macos-$(uname -m)"
20+
curl -L "https://github.com/neovim/neovim/releases/download/${NVIM_TAG}/$RELEASE_NAME.tar.gz" | tar -xz
21+
sudo ln -s "$PWD/$RELEASE_NAME/bin/nvim" /usr/local/bin
22+
rm -rf "$PWD/$RELEASE_NAME/lib/nvim/parser"
23+
mkdir -p ~/.local/share/nvim/site/pack/nvim-treesitter/start
24+
ln -s "$PWD" ~/.local/share/nvim/site/pack/nvim-treesitter/start
25+
else
26+
curl -L https://github.com/neovim/neovim/releases/download/${NVIM_TAG}/nvim-win64.zip -o nvim-win64.zip
27+
unzip nvim-win64
28+
mkdir -p ~/AppData/Local/nvim/pack/nvim-treesitter/start
29+
mkdir -p ~/AppData/Local/nvim-data
30+
cp -r "$PWD" ~/AppData/Local/nvim/pack/nvim-treesitter/start
31+
fi

0 commit comments

Comments
 (0)