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.line.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 ; Function-valued arguments of Nix builtins and nixpkgs lib functions.
92 ; Applications are left-associative, so each argument position has a
93 ; differently nested `apply_expression`.
94 ((apply_expression
95 function: [
96 (variable_expression (identifier) @_higher_order @function)
97 (select_expression
98 attrpath: (attrpath
99 attr: (identifier) @_higher_order @function .))]
100 argument: [
101 (variable_expression (identifier) @function)
102 (select_expression
103 attrpath: (attrpath
104 attr: (identifier) @function .))])
105 (#any-of? @_higher_order
106 "all" "any" "collect" "compareLists" "composeExtensions" "concatImapStrings"
107 "concatMap" "concatMapAttrs" "concatMapStrings" "converge" "count" "crossLists"
108 "extends" "filter" "filterAttrs" "filterAttrsRecursive" "filterSource" "findFirst"
109 "findFirstIndex" "findSingle" "fix" "fix'" "flip" "fold" "foldAttrs" "foldl"
110 "foldl'" "foldlAttrs" "foldr" "functionArgs" "genList" "groupBy" "groupBy'"
111 "ifilter0" "imap0" "imap1" "makeExtensible" "makeOverridable" "makeScope"
112 "makeScopeWithSplicing" "map" "mapAttrs" "mapAttrs'" "mapAttrsRecursive"
113 "mapAttrsRecursiveCond" "mapAttrsToList" "mapAttrsToListRecursive"
114 "mapAttrsToListRecursiveCond" "mapCartesianProduct" "mapCrossIndex" "mapDerivationAttrset"
115 "mapNullable" "mirrorFunctionArgs" "mkAliasAndWrapDefinitions" "optionDescriptionPhrase"
116 "partition" "recursiveUpdateUntil"
117 "setFunctionArgs" "sort" "sortOn" "splitByAndCompare" "splitStringBy" "stringAsChars"
118 "toposort" "traceValFn" "traceValSeqFn" "traceValSeqNFn" "updateName"
119 "zipAttrsWith" "zipListsWith"))
120
121 ((apply_expression
122 function: (apply_expression
123 function: [
124 (variable_expression (identifier) @_higher_order @function)
125 (select_expression
126 attrpath: (attrpath
127 attr: (identifier) @_higher_order @function .))])
128 argument: [
129 (variable_expression (identifier) @function)
130 (select_expression
131 attrpath: (attrpath
132 attr: (identifier) @function .))])
133 (#any-of? @_higher_order
134 "addCheck" "coercedTo" "composeExtensions" "concatImapStringsSep"
135 "concatMapAttrsStringSep" "concatMapStringsSep" "extends" "forEach" "genAttrs"
136 "genAttrs'" "listDfs" "makeExtensibleWithCustomName" "makeScope"
137 "makeScopeWithSplicing" "mapAttrsRecursiveCond" "mapAttrsToListRecursiveCond"
138 "mirrorFunctionArgs" "mkDerivedConfig" "overrideDerivation" "splitByAndCompare"
139 "zipAttrsWithNames"))
140
141 ((apply_expression
142 function: (apply_expression
143 function: (apply_expression
144 function: [
145 (variable_expression (identifier) @_higher_order @function)
146 (select_expression
147 attrpath: (attrpath
148 attr: (identifier) @_higher_order @function .))]))
149 argument: [
150 (variable_expression (identifier) @function)
151 (select_expression
152 attrpath: (attrpath
153 attr: (identifier) @function .))])
154 (#any-of? @_higher_order
155 "groupBy'" "mkChangedOptionModule" "mkMergedOptionModule" "splitByAndCompare"
156 "traceFnSeqN"))
157
158 ; Pipe operators evaluate the side pointed to by the operator as a function:
159 ; `value |> lib.foo` and `lib.foo <| value`.
160 (binary_expression
161 operator: "|>"
162 right: [
163 (variable_expression (identifier) @function)
164 (select_expression
165 attrpath: (attrpath
166 attr: (identifier) @function .))])
167
168 (binary_expression
169 left: [
170 (variable_expression (identifier) @function)
171 (select_expression
172 attrpath: (attrpath
173 attr: (identifier) @function .))]
174 operator: "<|")
175
176 (binding
177 attrpath: (attrpath
178 attr: (identifier) @function)
179 expression: (function_expression))
180
181 ; Builtins ------------------------------------------------------------
182
183 ; `builtins.*` method-style calls: highlight the attr as a builtin
184 ; function. `builtins` itself is painted by the @constant.builtin rule
185 ; further down.
186 ((select_expression
187 expression: (variable_expression
188 name: (identifier) @_id)
189 attrpath: (attrpath
190 attr: (identifier) @function.builtin))
191 (#eq? @_id "builtins"))
192
193 ; In apply position: `map f xs` -> `map` is a function builtin.
194 ((apply_expression
195 function: (variable_expression
196 (identifier) @function.builtin))
197 (#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)$"))
198
199 ; `import` behaves like a keyword.
200 ((variable_expression (identifier) @keyword.control.import)
201 (#eq? @keyword.control.import "import"))
202
203 ; `abort` / `throw` are control-flow exceptions.
204 ((variable_expression (identifier) @keyword.control.exception)
205 (#any-of? @keyword.control.exception "abort" "throw"))
206
207 ; Booleans / constants ------------------------------------------------
208
209 ((variable_expression (identifier) @constant.builtin.boolean)
210 (#any-of? @constant.builtin.boolean "true" "false"))
211
212 ((variable_expression (identifier) @constant.builtin)
213 (#any-of? @constant.builtin
214 "builtins" "null"
215 "__curPos" "__currentSystem" "__currentTime" "__langVersion"
216 "__nixPath" "__nixVersion" "__storeDir"))
217
218 ; Operators -----------------------------------------------------------
219
220 (unary_expression
221 operator: _ @operator)
222
223 (binary_expression
224 operator: _ @operator)
225
226 [
227 "="
228 "@"
229 ] @operator
230
231 ; Punctuation ---------------------------------------------------------
232
233 [
234 ";"
235 "."
236 ","
237 ":"
238 ] @punctuation.delimiter
239
240 [
241 "("
242 ")"
243 "["
244 "]"
245 "{"
246 "}"
247 ] @punctuation.bracket
248
249 (interpolation
250 "${" @punctuation.special
251 "}" @punctuation.special) @embedded
252
253 (has_attr_expression
254 expression: (_)
255 "?" @operator
256 attrpath: (attrpath
257 attr: (identifier) @variable.other.member))