diff --git a/queries/nix-highlights.scm b/queries/nix-highlights.scm new file mode 100644 index 0000000..1f92a15 --- /dev/null +++ b/queries/nix-highlights.scm @@ -0,0 +1,133 @@ +; Nix syntax highlighting queries (adapted from Helix editor) +; Maps to standard tree-sitter capture names for compatibility with tree-sitter-highlight + +(comment) @comment + +; Punctuation +[ + ";" + "." + "," + "=" + ":" + (ellipses) +] @punctuation.delimiter + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +; Keywords +"assert" @keyword +"or" @keyword +"rec" @keyword + +[ + "if" + "then" + "else" +] @keyword + +[ + "let" + "inherit" + "in" + "with" +] @keyword + +; Variables and identifiers +(variable_expression name: (identifier) @variable) + +; Attribute access (properties) +(select_expression + attrpath: (attrpath attr: (identifier)) @property) + +; Function calls +(apply_expression + function: [ + (variable_expression name: (identifier) @function) + (select_expression + attrpath: (attrpath + attr: (identifier) @function .))]) + +; Builtin variables +((identifier) @variable.builtin + (#match? @variable.builtin "^(__currentSystem|__currentTime|__nixPath|__nixVersion|__storeDir|builtins)$") + (#is-not? local)) + +; Builtin functions +((identifier) @function.builtin + (#match? @function.builtin "^(__add|__addErrorContext|__all|__any|__appendContext|__attrNames|__attrValues|__bitAnd|__bitOr|__bitXor|__catAttrs|__compareVersions|__concatLists|__concatMap|__concatStringsSep|__deepSeq|__div|__elem|__elemAt|__fetchurl|__filter|__filterSource|__findFile|__foldl'|__fromJSON|__functionArgs|__genList|__genericClosure|__getAttr|__getContext|__getEnv|__hasAttr|__hasContext|__hashFile|__hashString|__head|__intersectAttrs|__isAttrs|__isBool|__isFloat|__isFunction|__isInt|__isList|__isPath|__isString|__langVersion|__length|__lessThan|__listToAttrs|__mapAttrs|__match|__mul|__parseDrvName|__partition|__path|__pathExists|__readDir|__readFile|__replaceStrings|__seq|__sort|__split|__splitVersion|__storePath|__stringLength|__sub|__substring|__tail|__toFile|__toJSON|__toPath|__toXML|__trace|__tryEval|__typeOf|__unsafeDiscardOutputDependency|__unsafeDiscardStringContext|__unsafeGetAttrPos|__valueSize|abort|baseNameOf|derivation|derivationStrict|dirOf|fetchGit|fetchMercurial|fetchTarball|fromTOML|import|isNull|map|placeholder|removeAttrs|scopedImport|throw|toString)$") + (#is-not? local)) + +; Strings +[ + (string_expression) + (indented_string_expression) +] @string + +; Special string types (paths, URIs) +[ + (path_expression) + (hpath_expression) + (spath_expression) +] @string.special.path + +(uri_expression) @string.special.uri + +; Boolean constants +((identifier) @constant.builtin (#match? @constant.builtin "^(true|false)$")) + +; Null constant +((identifier) @constant.builtin (#eq? @constant.builtin "null")) + +; Numbers +(integer_expression) @number +(float_expression) @number + +; Escape sequences +(escape_sequence) @escape +(dollar_escape) @escape + +; Function parameters +(function_expression + "@"? @punctuation.delimiter + universal: (identifier) @variable.parameter + "@"? @punctuation.delimiter +) + +(formal + name: (identifier) @variable.parameter + "?"? @punctuation.delimiter) + +; String interpolation +(interpolation + "${" @punctuation.special + "}" @punctuation.special) @embedded + +; Operators +(unary_expression + operator: _ @operator) + +(binary_expression + operator: _ @operator) + +; Attribute bindings +(binding + attrpath: (attrpath attr: (identifier)) @property) + +; Inherit expressions +(inherit_from attrs: (inherited_attrs attr: (identifier) @property)) +(inherited_attrs attr: (identifier) @variable) + +; Has attribute expression +(has_attr_expression + expression: (_) + "?" @operator + attrpath: (attrpath + attr: (identifier) @property)) diff --git a/src/highlight.rs b/src/highlight.rs index 1c3dd19..dd37fed 100644 --- a/src/highlight.rs +++ b/src/highlight.rs @@ -145,7 +145,7 @@ fn get_config(lang: Language) -> HighlightConfiguration { Language::Nix => ( tree_sitter_nix::LANGUAGE.into(), "nix", - tree_sitter_nix::HIGHLIGHTS_QUERY, + include_str!("../queries/nix-highlights.scm"), ), Language::Python => ( tree_sitter_python::LANGUAGE.into(), diff --git a/static/style.css b/static/style.css index a210ad0..9113a26 100644 --- a/static/style.css +++ b/static/style.css @@ -278,10 +278,10 @@ article.post header { --hl-type: #005cc5; --hl-number: #005cc5; --hl-operator: #d73a49; - --hl-variable: #24292e; + --hl-variable: #e36209; --hl-constant: #005cc5; --hl-property: #005cc5; - --hl-punctuation: #24292e; + --hl-punctuation: #586069; --hl-punctuation-special: #d73a49; --hl-attribute: #22863a; --hl-escape: #005cc5; @@ -298,10 +298,10 @@ article.post header { --hl-type: #79b8ff; --hl-number: #79b8ff; --hl-operator: #f97583; - --hl-variable: #e1e4e8; + --hl-variable: #ffab70; --hl-constant: #79b8ff; --hl-property: #79b8ff; - --hl-punctuation: #e1e4e8; + --hl-punctuation: #a0a0a0; --hl-punctuation-special: #f97583; --hl-attribute: #85e89d; --hl-escape: #79b8ff;