Skip to content

Commit 1fe3273

Browse files
nrdxpthe-mikedavis
authored andcommitted
nix: fix highlighting rules
* avoid coloring `identifier`s globally * fix function application when not part of `select_expression` * add `has_attribute_expression` highlighting * fix precendence for interpolation, which should be after select * highlight `@` as delimiter
1 parent b738031 commit 1fe3273

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

runtime/queries/nix/highlights.scm

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
(comment) @comment
22

3+
"assert" @keyword.control.exception
4+
"or" @keyword.operator
5+
"rec" @keyword.control.repeat
6+
37
[
48
"if"
59
"then"
610
"else"
11+
] @keyword.control.conditional
12+
13+
[
714
"let"
815
"inherit"
916
"in"
10-
"rec"
1117
"with"
12-
"assert"
13-
"or"
1418
] @keyword
1519

1620
((identifier) @variable.builtin
@@ -42,26 +46,27 @@
4246
(integer_expression) @constant.numeric.integer
4347
(float_expression) @constant.numeric.float
4448

45-
(interpolation
46-
"${" @punctuation.special
47-
"}" @punctuation.special) @embedded
48-
4949
(escape_sequence) @constant.character.escape
5050

5151
(function_expression
5252
universal: (identifier) @variable.parameter
53+
"@"? @punctuation.delimiter
5354
)
5455

5556
(formal
5657
name: (identifier) @variable.parameter
5758
"?"? @punctuation.delimiter)
5859

5960
(select_expression
60-
attrpath: (attrpath (identifier)) @variable.other.member)
61+
attrpath: (attrpath attr: (identifier)) @variable.other.member)
62+
63+
(interpolation
64+
"${" @punctuation.special
65+
"}" @punctuation.special) @embedded
6166

6267
(apply_expression
6368
function: [
64-
(variable_expression (identifier)) @function
69+
(variable_expression name: (identifier) @function)
6570
(select_expression
6671
attrpath: (attrpath
6772
attr: (identifier) @function .))])
@@ -72,14 +77,18 @@
7277
(binary_expression
7378
operator: _ @operator)
7479

75-
(variable_expression (identifier) @variable)
80+
(variable_expression name: (identifier) @variable)
7681

7782
(binding
78-
attrpath: (attrpath (identifier)) @variable.other.member)
83+
attrpath: (attrpath attr: (identifier)) @variable.other.member)
7984

80-
(identifier) @variable.other.member
85+
(inherit_from attrs: (inherited_attrs attr: (identifier) @variable))
8186

82-
(inherit_from attrs: (inherited_attrs attr: (identifier) @variable.other.member) )
87+
(has_attr_expression
88+
expression: (_)
89+
"?" @operator
90+
attrpath: (attrpath
91+
attr: (identifier) @variable.other.member))
8392

8493
[
8594
";"

0 commit comments

Comments
 (0)