Debian Codegraph @

runtime/queries/nix/highlights.scm

raw symbols SCIP
1 ; tree-sitter highlighting resolves in .scm order. For a given byte
2 ; offset, the last matching capture wins. This file is ordered from
3 ; generic to specific: base variables and keywords first, then more
4 ; targeted builtin / call / member patterns that override them.
5
6 ; Base ----------------------------------------------------------------
7
8 ; Generic identifier reference. Specific rules (builtins, calls,
9 ; booleans, constants) later in the file override this.
10 (variable_expression (identifier) @variable)
11
12 ; Comments ------------------------------------------------------------
13
14 (comment) @comment
15 (doc_comment) @comment.documentation
16
17 ; Keywords ------------------------------------------------------------
18
19 [
20 "assert"
21 "in"
22 "inherit"
23 "let"
24 "rec"
25 "with"
26 ] @keyword
27
28 [
29 "if"
30 "then"
31 "else"
32 ] @keyword.control.conditional
33
34 "or" @keyword.operator
35
36 ; Literals ------------------------------------------------------------
37
38 (integer_expression) @constant.numeric.integer
39 (float_expression) @constant.numeric.float
40
41 [
42 (string_expression)
43 (indented_string_expression)
44 ] @string
45
46 (escape_sequence) @constant.character.escape
47 (dollar_escape) @constant.character.escape
48
49 [
50 (path_expression)
51 (hpath_expression)
52 (spath_expression)
53 ] @string.special.path
54
55 (uri_expression) @string.special.url
56
57 ; Functions -----------------------------------------------------------
58
59 ; Parameters: `x: body` and `{ a, b }: body`.
60 (function_expression
61 universal: (identifier) @variable.parameter)
62
63 (formal
64 name: (identifier) @variable.parameter
65 "?"? @punctuation.delimiter)
66
67 (ellipses) @variable.parameter.builtin
68
69 ; Attrset members -----------------------------------------------------
70
71 (binding
72 attrpath: (attrpath (identifier)) @variable.other.member)
73
74 (select_expression
75 attrpath: (attrpath (identifier)) @variable.other.member)
76
77 (inherit attrs: (inherited_attrs attr: (identifier) @variable.other.member))
78 (inherit_from attrs: (inherited_attrs attr: (identifier) @variable.other.member))
79
80 ; Function calls ------------------------------------------------------
81 ; After member rules so `lib.isBool` in apply position is @function,
82 ; not @variable.other.member.
83
84 (apply_expression
85 function: [
86 (variable_expression (identifier) @function)
87 (select_expression
88 attrpath: (attrpath
89 attr: (identifier) @function .))])
90
91 (binding
92 attrpath: (attrpath
93 attr: (identifier) @function)
94 expression: (function_expression))
95
96 ; Builtins ------------------------------------------------------------
97
98 ; `builtins.*` method-style calls: highlight the attr as a builtin
99 ; function. `builtins` itself is painted by the @constant.builtin rule
100 ; further down.
101 ((select_expression
102 expression: (variable_expression
103 name: (identifier) @_id)
104 attrpath: (attrpath
105 attr: (identifier) @function.builtin))
106 (#eq? @_id "builtins"))
107
108 ; In apply position: `map f xs` -> `map` is a function builtin.
109 ((apply_expression
110 function: (variable_expression
111 (identifier) @function.builtin))
112 (#match? @function.builtin "^(__add|__addDrvOutputDependencies|__addErrorContext|__all|__any|__appendContext|__attrNames|__attrValues|__bitAnd|__bitOr|__bitXor|__catAttrs|__ceil|__compareVersions|__concatLists|__concatMap|__concatStringsSep|__convertHash|__deepSeq|__div|__elem|__elemAt|__fetchurl|__filter|__filterSource|__findFile|__flakeRefToString|__floor|__foldl'|__fromJSON|__functionArgs|__genList|__genericClosure|__getAttr|__getContext|__getEnv|__getFlake|__groupBy|__hasAttr|__hasContext|__hashFile|__hashString|__head|__intersectAttrs|__isAttrs|__isBool|__isFloat|__isFunction|__isInt|__isList|__isPath|__isString|__length|__lessThan|__listToAttrs|__mapAttrs|__match|__mul|__parseDrvName|__parseFlakeRef|__partition|__path|__pathExists|__readDir|__readFile|__readFileType|__replaceStrings|__seq|__sort|__split|__splitVersion|__storePath|__stringLength|__sub|__substring|__tail|__toFile|__toJSON|__toPath|__toXML|__trace|__traceVerbose|__tryEval|__typeOf|__unsafeDiscardOutputDependency|__unsafeDiscardStringContext|__unsafeGetAttrPos|__warn|__zipAttrsWith|baseNameOf|break|derivation|derivationStrict|dirOf|fetchGit|fetchMercurial|fetchTarball|fetchTree|fromTOML|isNull|map|placeholder|removeAttrs|scopedImport|toString)$"))
113
114 ; `import` behaves like a keyword.
115 ((variable_expression (identifier) @keyword.control.import)
116 (#eq? @keyword.control.import "import"))
117
118 ; `abort` / `throw` are control-flow exceptions.
119 ((variable_expression (identifier) @keyword.control.exception)
120 (#any-of? @keyword.control.exception "abort" "throw"))
121
122 ; Booleans / constants ------------------------------------------------
123
124 ((variable_expression (identifier) @constant.builtin.boolean)
125 (#any-of? @constant.builtin.boolean "true" "false"))
126
127 ((variable_expression (identifier) @constant.builtin)
128 (#any-of? @constant.builtin
129 "builtins" "null"
130 "__curPos" "__currentSystem" "__currentTime" "__langVersion"
131 "__nixPath" "__nixVersion" "__storeDir"))
132
133 ; Operators -----------------------------------------------------------
134
135 (unary_expression
136 operator: _ @operator)
137
138 (binary_expression
139 operator: _ @operator)
140
141 [
142 "="
143 "@"
144 ] @operator
145
146 ; Punctuation ---------------------------------------------------------
147
148 [
149 ";"
150 "."
151 ","
152 ":"
153 ] @punctuation.delimiter
154
155 [
156 "("
157 ")"
158 "["
159 "]"
160 "{"
161 "}"
162 ] @punctuation.bracket
163
164 (interpolation
165 "${" @punctuation.special
166 "}" @punctuation.special) @embedded
167
168 (has_attr_expression
169 expression: (_)
170 "?" @operator
171 attrpath: (attrpath
172 attr: (identifier) @variable.other.member))