diff options
| author | Marc Jakobi <marc.jakobi@tiko.energy> | 2023-10-12 21:04:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-12 19:04:55 +0000 |
| commit | 783e5fc3079680b307e8ac518935317907e71a59 (patch) | |
| tree | 88e7a7a1b0d71c03e140622c92e38a00387b69b0 | |
| parent | Update parsers: wing (diff) | |
| download | nvim-treesitter-783e5fc3079680b307e8ac518935317907e71a59.tar nvim-treesitter-783e5fc3079680b307e8ac518935317907e71a59.tar.gz nvim-treesitter-783e5fc3079680b307e8ac518935317907e71a59.tar.bz2 nvim-treesitter-783e5fc3079680b307e8ac518935317907e71a59.tar.lz nvim-treesitter-783e5fc3079680b307e8ac518935317907e71a59.tar.xz nvim-treesitter-783e5fc3079680b307e8ac518935317907e71a59.tar.zst nvim-treesitter-783e5fc3079680b307e8ac518935317907e71a59.zip | |
feat(nix): some highlight improvements
- functions
- builtin functions with prefix
- add test file
| -rw-r--r-- | queries/nix/highlights.scm | 15 | ||||
| -rw-r--r-- | tests/query/highlights/nix/test.nix | 16 |
2 files changed, 30 insertions, 1 deletions
diff --git a/queries/nix/highlights.scm b/queries/nix/highlights.scm index b83a81027..97e5303ba 100644 --- a/queries/nix/highlights.scm +++ b/queries/nix/highlights.scm @@ -89,7 +89,14 @@ name: (identifier) @boolean (#any-of? @boolean "true" "false")) -; builtin functions +; builtin functions (with builtins prefix) +(select_expression + expression: (variable_expression name: (identifier) @_id) + attrpath: (attrpath attr: (identifier) @function.builtin) + (#eq? @_id "builtins") +) + +; builtin functions (without builtins prefix) (variable_expression name: (identifier) @function.builtin (#any-of? @function.builtin ; nix eval --impure --expr 'with builtins; filter (x: !(elem x [ "abort" "derivation" "import" "throw" ]) && isFunction builtins.${x}) (attrNames builtins)' "add" "addErrorContext" "all" "any" "appendContext" "attrNames" "attrValues" "baseNameOf" "bitAnd" "bitOr" "bitXor" "break" "catAttrs" "ceil" "compareVersions" "concatLists" "concatMap" "concatStringsSep" "deepSeq" "derivationStrict" "dirOf" "div" "elem" "elemAt" "fetchGit" "fetchMercurial" "fetchTarball" "fetchTree" "fetchurl" "filter" "filterSource" "findFile" "floor" "foldl'" "fromJSON" "fromTOML" "functionArgs" "genList" "genericClosure" "getAttr" "getContext" "getEnv" "getFlake" "groupBy" "hasAttr" "hasContext" "hashFile" "hashString" "head" "intersectAttrs" "isAttrs" "isBool" "isFloat" "isFunction" "isInt" "isList" "isNull" "isPath" "isString" "length" "lessThan" "listToAttrs" "map" "mapAttrs" "match" "mul" "parseDrvName" "partition" "path" "pathExists" "placeholder" "readDir" "readFile" "removeAttrs" "replaceStrings" "scopedImport" "seq" "sort" "split" "splitVersion" "storePath" "stringLength" "sub" "substring" "tail" "toFile" "toJSON" "toPath" "toString" "toXML" "trace" "traceVerbose" "tryEval" "typeOf" "unsafeDiscardOutputDependency" "unsafeDiscardStringContext" "unsafeGetAttrPos" "zipAttrsWith" @@ -114,6 +121,11 @@ (attrset_expression (binding_set (binding . (attrpath (identifier) @field)))) (rec_attrset_expression (binding_set (binding . (attrpath (identifier) @field)))) +; function definition +(binding + attrpath: (attrpath attr: (identifier) @function) + expression: (function_expression)) + ; unary operators (unary_expression operator: _ @operator) @@ -131,3 +143,4 @@ (unary_expression "-" (float_expression)) (float_expression) ] @float + diff --git a/tests/query/highlights/nix/test.nix b/tests/query/highlights/nix/test.nix new file mode 100644 index 000000000..d5fb13de8 --- /dev/null +++ b/tests/query/highlights/nix/test.nix @@ -0,0 +1,16 @@ +{ + func1 = param: builtins.readFile param; + # ^ @function + # ^ @parameter + # ^ @constant.builtin + # ^ @function.builtin + func2 = { p1, p2 }: p2; + # ^ @function + # ^ @parameter + readFile' = readFile; + # ^ @function.builtin + x = func1 ./path/to/file.nix; +# ^ @field + # ^ @function.call + # ^ @string.special +} |
