Skip to content

Commit 436b3f9

Browse files
authored
improve language injections (nushell#211)
- refactor: simplify queries and reformat - allow additional formatting with `@string.code`
1 parent ef69435 commit 436b3f9

File tree

2 files changed

+60
-58
lines changed

2 files changed

+60
-58
lines changed

queries/nu/highlights.scm

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -276,26 +276,32 @@ key: (identifier) @property
276276
(parameter
277277
(comment) @comment.documentation @spell)
278278

279-
((command
280-
head: ((cmd_identifier) @_cmd (#any-of? @_cmd
281-
"find"
282-
"parse"
283-
"split"
284-
"str"
285-
" find"
286-
" parse"
287-
" split"
288-
" str"
289-
))
290-
flag: [
291-
(short_flag name: (_) @_sflag (#eq? @_sflag "r"))
292-
(long_flag name: (_) @_lflag (#eq? @_lflag "regex"))
293-
]
294-
.
295-
arg: (_ (string_content) @string.regexp)
296-
))
297-
298-
((_
299-
opr: ["=~" "!~" "like" "not-like"]
300-
rhs: (_ (string_content) @string.regexp)
301-
))
279+
(command
280+
head: ((cmd_identifier) @_cmd
281+
(#match? @_cmd "^\\s*(find|parse|split|str)$"))
282+
flag: (_
283+
name: (_) @_flag
284+
(#any-of? @_flag "r" "regex"))
285+
.
286+
arg: (_
287+
(string_content) @string.regexp))
288+
289+
(_
290+
opr: [
291+
"=~"
292+
"!~"
293+
"like"
294+
"not-like"
295+
]
296+
rhs: (_
297+
(string_content) @string.regexp))
298+
299+
(command
300+
head: ((_) @_cmd
301+
(#any-of? @_cmd "nu" "$nu.current-exe"))
302+
flag: (_
303+
name: (_) @_flag
304+
(#any-of? @_flag "c" "e" "commands" "execute"))
305+
.
306+
arg: (_
307+
(string_content) @string.code))

queries/nu/injections.scm

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
((comment) @injection.content
2-
(#set! injection.language "comment"))
2+
(#set! injection.language "comment"))
33

4-
((command
5-
head: ((cmd_identifier) @_cmd (#any-of? @_cmd
6-
"find"
7-
"parse"
8-
"split"
9-
"str"
10-
" find"
11-
" parse"
12-
" split"
13-
" str"
14-
))
15-
flag: [
16-
(short_flag name: (_) @_sflag (#eq? @_sflag "r"))
17-
(long_flag name: (_) @_lflag (#eq? @_lflag "regex"))
18-
]
19-
.
20-
arg: (_ (string_content) @injection.content)
21-
(#set! injection.language "regex")
22-
))
4+
(command
5+
head: ((cmd_identifier) @_cmd
6+
(#match? @_cmd "^\\s*(find|parse|split|str)$"))
7+
flag: (_
8+
name: (_) @_flag
9+
(#any-of? @_flag "r" "regex"))
10+
.
11+
arg: (_
12+
(string_content) @injection.content
13+
(#set! injection.language "regex")))
2314

24-
((_
25-
opr: ["=~" "!~" "like" "not-like"]
26-
rhs: (_ (string_content) @injection.content)
27-
(#set! injection.language "regex")
28-
))
15+
(_
16+
opr: [
17+
"=~"
18+
"!~"
19+
"like"
20+
"not-like"
21+
]
22+
rhs: (_
23+
(string_content) @injection.content
24+
(#set! injection.language "regex")))
2925

30-
((command
31-
head: (_) @_cmd (#any-of? @_cmd "nu" "$nu.current-exe")
32-
flag: [
33-
(short_flag name: (_) @_sflag (#any-of? @_sflag "c" "e"))
34-
(long_flag name: (_) @_lflag (#any-of? @_lflag "commands" "execute"))
35-
]
36-
.
37-
arg: (_ (string_content) @injection.content)
38-
(#set! injection.language "nu")
39-
))
26+
(command
27+
head: (_) @_cmd
28+
(#any-of? @_cmd "nu" "$nu.current-exe")
29+
flag: (_
30+
name: (_) @_flag
31+
(#any-of? @_flag "c" "e" "commands" "execute"))
32+
.
33+
arg: (_
34+
(string_content) @injection.content
35+
(#set! injection.language "nu")))

0 commit comments

Comments
 (0)