mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-14 01:10:02 -04:00
Initial Nix queries
This commit is contained in:
parent
e59a789289
commit
ee0e8e8518
3 changed files with 136 additions and 0 deletions
11
queries/nix/folds.scm
Normal file
11
queries/nix/folds.scm
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
; Nix doesn't really have blocks, so just guess what people might want folds for
|
||||||
|
[
|
||||||
|
(if)
|
||||||
|
(with)
|
||||||
|
(let)
|
||||||
|
(function)
|
||||||
|
(attrset)
|
||||||
|
(rec_attrset)
|
||||||
|
(list)
|
||||||
|
(indented_str)
|
||||||
|
] @fold
|
||||||
110
queries/nix/highlights.scm
Normal file
110
queries/nix/highlights.scm
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
; basic keywords
|
||||||
|
[
|
||||||
|
("assert")
|
||||||
|
("with")
|
||||||
|
("let")
|
||||||
|
("in")
|
||||||
|
("rec")
|
||||||
|
("inherit")
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
; if/then/else
|
||||||
|
[
|
||||||
|
("if")
|
||||||
|
("then")
|
||||||
|
("else")
|
||||||
|
] @conditional
|
||||||
|
|
||||||
|
; undocumented, I'm not actually sure what this does
|
||||||
|
("or") @keyword.operator
|
||||||
|
|
||||||
|
; comments
|
||||||
|
(comment) @comment
|
||||||
|
|
||||||
|
; strings
|
||||||
|
[ (string) (indented_string) ] @string
|
||||||
|
|
||||||
|
; paths and URLs
|
||||||
|
[ (path) (spath) (uri) ] @string.special
|
||||||
|
|
||||||
|
; delimiters
|
||||||
|
[
|
||||||
|
"."
|
||||||
|
";"
|
||||||
|
","
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
; brackets
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
; `?` in `{ x ? y }:`, used to set defaults for named function arguments
|
||||||
|
; I'm not really sure what group this should go in, but it should probably have highlighting, so I'm putting it in @punctuation.special
|
||||||
|
(formal "?" @punctuation.special)
|
||||||
|
|
||||||
|
; `...` in `{ ... }`, used to ignore unknown named function arguments (see above)
|
||||||
|
(ellipses) @punctuation.special
|
||||||
|
|
||||||
|
; `:` in `x: y`, used to separate function argument from body (see above)
|
||||||
|
(function ":" @punctuation.special)
|
||||||
|
|
||||||
|
; basic identifiers
|
||||||
|
(identifier) @variable
|
||||||
|
|
||||||
|
; builtin functions
|
||||||
|
((identifier) @_i (#match? @_i "^(builtins|baseNameOf|dirOf|fetchTarball|map|removeAttrs|toString)$")) @variable.builtin
|
||||||
|
|
||||||
|
; display entire builtins path as builtin (ex. `builtins.filter` is highlighted as one long builtin)
|
||||||
|
(select ((identifier) @_i (#eq? @_i "builtins")) (attrpath (identifier) @variable.builtin)) @variable.builtin
|
||||||
|
|
||||||
|
; import
|
||||||
|
((identifier) @_i (#eq? @_i "import")) @include
|
||||||
|
|
||||||
|
; these are technically functions but they act more like keywords (abort and throw are control flow, derivation is a core language construct)
|
||||||
|
((identifier) @_i (#match? @_i "^(abort|derivation|throw)$")) @keyword
|
||||||
|
|
||||||
|
; booleans
|
||||||
|
((identifier) @_i (#match? @_i "^(true|false)$")) @boolean
|
||||||
|
|
||||||
|
; string interpolation (this was very annoying to get working properly)
|
||||||
|
(interpolation "${" @punctuation.special (_) "}" @punctuation.special) @none
|
||||||
|
|
||||||
|
; integers, also highlight a unary -
|
||||||
|
[
|
||||||
|
(unary "-" (integer))
|
||||||
|
(integer)
|
||||||
|
] @number
|
||||||
|
|
||||||
|
; floats, also highlight a unary -
|
||||||
|
[
|
||||||
|
(unary "-" (float))
|
||||||
|
(float)
|
||||||
|
] @float
|
||||||
|
|
||||||
|
; unary operators
|
||||||
|
(unary "-" @operator)
|
||||||
|
(unary "!" @operator)
|
||||||
|
|
||||||
|
; binary operators
|
||||||
|
(binary "?" @operator)
|
||||||
|
(binary "++" @operator)
|
||||||
|
(binary "*" @operator)
|
||||||
|
(binary "/" @operator)
|
||||||
|
(binary "+" @operator)
|
||||||
|
(binary "-" @operator)
|
||||||
|
(binary "//" @operator)
|
||||||
|
(binary "<" @operator)
|
||||||
|
(binary "<=" @operator)
|
||||||
|
(binary ">" @operator)
|
||||||
|
(binary ">=" @operator)
|
||||||
|
(binary "==" @operator)
|
||||||
|
(binary "!=" @operator)
|
||||||
|
(binary "&&" @operator)
|
||||||
|
(binary "||" @operator)
|
||||||
|
(binary "->" @operator)
|
||||||
15
queries/nix/locals.scm
Normal file
15
queries/nix/locals.scm
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
; let bindings
|
||||||
|
(let (bind . (attrpath) @definition.var)) @scope
|
||||||
|
|
||||||
|
; rec attrsets
|
||||||
|
(rec_attrset (bind . (attrpath) @definition.field)) @scope
|
||||||
|
|
||||||
|
; functions and parameters
|
||||||
|
(function . [
|
||||||
|
(identifier) @definition.parameter
|
||||||
|
(formals (formal . (identifier) @definition.parameter))
|
||||||
|
]) @scope
|
||||||
|
((formals) "@" (identifier) @definition.parameter) ; I couldn't get this to work properly inside the (function)
|
||||||
|
|
||||||
|
; some identifiers can't be references, but @reference doesn't seem to have an inverse like @none
|
||||||
|
(identifier) @reference
|
||||||
Loading…
Add table
Add a link
Reference in a new issue