queries/nix: highlight function arguments in known higher-order calls (#16068)

This commit is contained in:
Vinicius Deolindo authored and GitHub committed 2026-07-20 10:39:37 -05:00
1 parent 94e233800c
commit 703fa83597
2 files changed
+104

No files matched your search

+67
View File
@@ -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
+37
View File
@@ -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
}