diff --git a/runtime/queries/nix/highlights.scm b/runtime/queries/nix/highlights.scm index 7a1a7cf4..66d80645 100644 --- a/runtime/queries/nix/highlights.scm +++ b/runtime/queries/nix/highlights.scm @@ -88,6 +88,73 @@ attrpath: (attrpath attr: (identifier) @function .))]) +; Function-valued arguments of Nix builtins and nixpkgs lib functions. +; Applications are left-associative, so each argument position has a +; differently nested `apply_expression`. +((apply_expression + function: [ + (variable_expression (identifier) @_higher_order @function) + (select_expression + attrpath: (attrpath + attr: (identifier) @_higher_order @function .))] + argument: [ + (variable_expression (identifier) @function) + (select_expression + attrpath: (attrpath + attr: (identifier) @function .))]) + (#any-of? @_higher_order + "all" "any" "collect" "compareLists" "composeExtensions" "concatImapStrings" + "concatMap" "concatMapAttrs" "concatMapStrings" "converge" "count" "crossLists" + "extends" "filter" "filterAttrs" "filterAttrsRecursive" "filterSource" "findFirst" + "findFirstIndex" "findSingle" "fix" "fix'" "flip" "fold" "foldAttrs" "foldl" + "foldl'" "foldlAttrs" "foldr" "functionArgs" "genList" "groupBy" "groupBy'" + "ifilter0" "imap0" "imap1" "makeExtensible" "makeOverridable" "makeScope" + "makeScopeWithSplicing" "map" "mapAttrs" "mapAttrs'" "mapAttrsRecursive" + "mapAttrsRecursiveCond" "mapAttrsToList" "mapAttrsToListRecursive" + "mapAttrsToListRecursiveCond" "mapCartesianProduct" "mapCrossIndex" "mapDerivationAttrset" + "mapNullable" "mirrorFunctionArgs" "mkAliasAndWrapDefinitions" "optionDescriptionPhrase" + "partition" "recursiveUpdateUntil" + "setFunctionArgs" "sort" "sortOn" "splitByAndCompare" "splitStringBy" "stringAsChars" + "toposort" "traceValFn" "traceValSeqFn" "traceValSeqNFn" "updateName" + "zipAttrsWith" "zipListsWith")) + +((apply_expression + function: (apply_expression + function: [ + (variable_expression (identifier) @_higher_order @function) + (select_expression + attrpath: (attrpath + attr: (identifier) @_higher_order @function .))]) + argument: [ + (variable_expression (identifier) @function) + (select_expression + attrpath: (attrpath + attr: (identifier) @function .))]) + (#any-of? @_higher_order + "addCheck" "coercedTo" "composeExtensions" "concatImapStringsSep" + "concatMapAttrsStringSep" "concatMapStringsSep" "extends" "forEach" "genAttrs" + "genAttrs'" "listDfs" "makeExtensibleWithCustomName" "makeScope" + "makeScopeWithSplicing" "mapAttrsRecursiveCond" "mapAttrsToListRecursiveCond" + "mirrorFunctionArgs" "mkDerivedConfig" "overrideDerivation" "splitByAndCompare" + "zipAttrsWithNames")) + +((apply_expression + function: (apply_expression + function: (apply_expression + function: [ + (variable_expression (identifier) @_higher_order @function) + (select_expression + attrpath: (attrpath + attr: (identifier) @_higher_order @function .))])) + argument: [ + (variable_expression (identifier) @function) + (select_expression + attrpath: (attrpath + attr: (identifier) @function .))]) + (#any-of? @_higher_order + "groupBy'" "mkChangedOptionModule" "mkMergedOptionModule" "splitByAndCompare" + "traceFnSeqN")) + ; Pipe operators evaluate the side pointed to by the operator as a function: ; `value |> lib.foo` and `lib.foo <| value`. (binary_expression diff --git a/tests/query/highlights/nix/calls.nix b/tests/query/highlights/nix/calls.nix index acb65388..90c68c92 100644 --- a/tests/query/highlights/nix/calls.nix +++ b/tests/query/highlights/nix/calls.nix @@ -1,6 +1,8 @@ { x = map double items; # ^ @function.builtin +# ^ @function +# ^ @variable y = builtins.length items; # ^ @constant.builtin # ^ @function.builtin @@ -8,4 +10,39 @@ # ^ @function w = lib.foo <| value; # ^ @function + merged = lib.foldr lib.recursiveUpdate { } foo; +# ^ @function +# ^ @function +# ^ @variable + generated = lib.forEach items lib.makeThing; +# ^ @function +# ^ @variable +# ^ @function + walked = lib.mapAttrsRecursiveCond lib.recurse lib.transform attrs; +# ^ @function +# ^ @function +# ^ @function +# ^ @variable + grouped = lib.groupBy' lib.merge { } lib.keyFor items; +# ^ @function +# ^ @function +# ^ @function +# ^ @variable + traced = lib.traceFnSeqN 2 "value" lib.render value; +# ^ @function +# ^ @function +# ^ @variable + local = let transform = x: x; in map transform items; +# ^ @function.builtin +# ^ @function + localSecond = let transform = x: x; in lib.forEach items transform; +# ^ @function +# ^ @variable +# ^ @function + extension = lib.toExtension overrides; +# ^ @function +# ^ @variable + package = lib.callPackageWith pkgs packageFile { }; +# ^ @function +# ^ @variable }