From 4d93fae5a3764451dacd94796d0de16a752ae3eb Mon Sep 17 00:00:00 2001 From: Baraa Homsi <49784526+bodby@users.noreply.github.com> Date: Mon, 20 Jan 2025 03:03:13 +0000 Subject: [PATCH] fix(nix): highlight functions when part of a set (#7547) * feat(nix): Fix function highlights when part of a set * fix(nix): Highlight only the last identifier node in functions * fix(nix): Higher precedence for builtins compared to functions and member vars --- queries/nix/highlights.scm | 64 ++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/queries/nix/highlights.scm b/queries/nix/highlights.scm index 7cdcc3e1d..785d249b9 100644 --- a/queries/nix/highlights.scm +++ b/queries/nix/highlights.scm @@ -90,6 +90,44 @@ name: (identifier) @boolean (#any-of? @boolean "true" "false")) +; string interpolation (this was very annoying to get working properly) +(interpolation + "${" @punctuation.special + (_) + "}" @punctuation.special) @none + +(select_expression + expression: (_) @_expr + attrpath: (attrpath + attr: (identifier) @variable.member) + (#not-eq? @_expr "builtins")) + +(attrset_expression + (binding_set + (binding + . + (attrpath + (identifier) @variable.member)))) + +(rec_attrset_expression + (binding_set + (binding + . + (attrpath + (identifier) @variable.member)))) + +(apply_expression + function: [ + (select_expression + attrpath: (attrpath + . + attr: (identifier) @function.call .)) + (select_expression + attrpath: (attrpath + (_) + attr: (identifier) @function.call .)) + ]) + ; builtin functions (with builtins prefix) (select_expression expression: (variable_expression @@ -138,32 +176,6 @@ ; nix eval --impure --expr 'with builtins; filter (x: !(isFunction builtins.${x} || isBool builtins.${x})) (attrNames builtins)' "builtins" "currentSystem" "currentTime" "langVersion" "nixPath" "nixVersion" "null" "storeDir")) -; string interpolation (this was very annoying to get working properly) -(interpolation - "${" @punctuation.special - (_) - "}" @punctuation.special) @none - -(select_expression - expression: (_) @_expr - attrpath: (attrpath - attr: (identifier) @variable.member) - (#not-eq? @_expr "builtins")) - -(attrset_expression - (binding_set - (binding - . - (attrpath - (identifier) @variable.member)))) - -(rec_attrset_expression - (binding_set - (binding - . - (attrpath - (identifier) @variable.member)))) - ; function definition (binding attrpath: (attrpath