feat(highlight): migrate to tree-house with Helix queries
Replace tree-sitter-highlight dep with tree-house crate from Helix editor. Add ropey dependency required by tree-house. Reorganize query files from Helix's runtime/queries/ for all 14 supported languages: - bash, c, css, go, html, javascript, json, markdown, nix, python, rust, toml, typescript, yaml - Include ecma, _javascript, _typescript base dirs for JS/TS inheritance - Copy highlights.scm, injections.scm, locals.scm where available This commit establishes the foundation; highlight.rs implementation will follow in subsequent commits.
This commit is contained in:
112
queries/nix/highlights.scm
Normal file
112
queries/nix/highlights.scm
Normal file
@@ -0,0 +1,112 @@
|
||||
(comment) @comment
|
||||
|
||||
[
|
||||
";"
|
||||
"."
|
||||
","
|
||||
"="
|
||||
":"
|
||||
(ellipses)
|
||||
] @punctuation.delimiter
|
||||
|
||||
[
|
||||
"("
|
||||
")"
|
||||
"["
|
||||
"]"
|
||||
"{"
|
||||
"}"
|
||||
] @punctuation.bracket
|
||||
|
||||
"assert" @keyword.control.exception
|
||||
"or" @keyword.operator
|
||||
"rec" @keyword.control.repeat
|
||||
|
||||
[
|
||||
"if"
|
||||
"then"
|
||||
"else"
|
||||
] @keyword.control.conditional
|
||||
|
||||
[
|
||||
"let"
|
||||
"inherit"
|
||||
"in"
|
||||
"with"
|
||||
] @keyword
|
||||
|
||||
(variable_expression name: (identifier) @variable)
|
||||
|
||||
(select_expression
|
||||
attrpath: (attrpath attr: (identifier)) @variable.other.member)
|
||||
|
||||
(apply_expression
|
||||
function: [
|
||||
(variable_expression name: (identifier) @function)
|
||||
(select_expression
|
||||
attrpath: (attrpath
|
||||
attr: (identifier) @function .))])
|
||||
|
||||
((identifier) @variable.builtin
|
||||
(#match? @variable.builtin "^(__currentSystem|__currentTime|__nixPath|__nixVersion|__storeDir|builtins)$")
|
||||
(#is-not? local))
|
||||
|
||||
((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))
|
||||
|
||||
[
|
||||
(string_expression)
|
||||
(indented_string_expression)
|
||||
] @string
|
||||
|
||||
[
|
||||
(path_expression)
|
||||
(hpath_expression)
|
||||
(spath_expression)
|
||||
] @string.special.path
|
||||
|
||||
(uri_expression) @string.special.uri
|
||||
|
||||
; boolean
|
||||
((identifier) @constant.builtin.boolean (#match? @constant.builtin.boolean "^(true|false)$")) @constant.builtin.boolean
|
||||
; null
|
||||
((identifier) @constant.builtin (#eq? @constant.builtin "null")) @constant.builtin
|
||||
|
||||
(integer_expression) @constant.numeric.integer
|
||||
(float_expression) @constant.numeric.float
|
||||
|
||||
(escape_sequence) @constant.character.escape
|
||||
(dollar_escape) @constant.character.escape
|
||||
|
||||
(function_expression
|
||||
"@"? @punctuation.delimiter
|
||||
universal: (identifier) @variable.parameter
|
||||
"@"? @punctuation.delimiter
|
||||
)
|
||||
|
||||
(formal
|
||||
name: (identifier) @variable.parameter
|
||||
"?"? @punctuation.delimiter)
|
||||
|
||||
(interpolation
|
||||
"${" @punctuation.special
|
||||
"}" @punctuation.special) @embedded
|
||||
|
||||
(unary_expression
|
||||
operator: _ @operator)
|
||||
|
||||
(binary_expression
|
||||
operator: _ @operator)
|
||||
|
||||
(binding
|
||||
attrpath: (attrpath attr: (identifier)) @variable.other.member)
|
||||
|
||||
(inherit_from attrs: (inherited_attrs attr: (identifier) @variable.other.member))
|
||||
(inherited_attrs attr: (identifier) @variable)
|
||||
|
||||
(has_attr_expression
|
||||
expression: (_)
|
||||
"?" @operator
|
||||
attrpath: (attrpath
|
||||
attr: (identifier) @variable.other.member))
|
||||
272
queries/nix/injections.scm
Normal file
272
queries/nix/injections.scm
Normal file
@@ -0,0 +1,272 @@
|
||||
((comment) @injection.content
|
||||
(#set! injection.language "comment"))
|
||||
|
||||
; mark arbitrary languages with a comment
|
||||
((((comment) @injection.language) .
|
||||
(indented_string_expression (string_fragment) @injection.content))
|
||||
(#set! injection.combined))
|
||||
((binding
|
||||
(comment) @injection.language
|
||||
expression: (indented_string_expression (string_fragment) @injection.content))
|
||||
(#set! injection.combined))
|
||||
|
||||
; Common attribute keys corresponding to Python scripts,
|
||||
; such as those for NixOS VM tests in nixpkgs/nixos/tests.
|
||||
((binding
|
||||
attrpath: (attrpath (identifier) @_path)
|
||||
expression: (indented_string_expression
|
||||
(string_fragment) @injection.content))
|
||||
(#match? @_path "(^|\\.)testScript$")
|
||||
(#set! injection.language "python")
|
||||
(#set! injection.combined))
|
||||
|
||||
; Common attribute keys corresponding to scripts,
|
||||
; such as those of stdenv.mkDerivation.
|
||||
((binding
|
||||
attrpath: (attrpath (identifier) @_path)
|
||||
expression: [
|
||||
(indented_string_expression (string_fragment) @injection.content)
|
||||
(binary_expression (indented_string_expression (string_fragment) @injection.content))
|
||||
])
|
||||
(#match? @_path "(^\\w*Phase|command|(pre|post)\\w*|(.*\\.)?\\w*([sS]cript|[hH]ook)|(.*\\.)?startup)$")
|
||||
(#set! injection.language "bash")
|
||||
(#set! injection.combined))
|
||||
|
||||
; builtins.{match,split} regex str
|
||||
; Example: nix/tests/lang/eval-okay-regex-{match,split}.nix
|
||||
((apply_expression
|
||||
function: (_) @_func
|
||||
argument: (indented_string_expression (string_fragment) @injection.content))
|
||||
(#match? @_func "(^|\\.)match|split$")
|
||||
(#set! injection.language "regex")
|
||||
(#set! injection.combined))
|
||||
|
||||
; builtins.fromJSON json
|
||||
; Example: nix/tests/lang/eval-okay-fromjson.nix
|
||||
((apply_expression
|
||||
function: (_) @_func
|
||||
argument: (indented_string_expression (string_fragment) @injection.content))
|
||||
(#match? @_func "(^|\\.)fromJSON$")
|
||||
(#set! injection.language "json")
|
||||
(#set! injection.combined))
|
||||
|
||||
; builtins.fromTOML toml
|
||||
; Example: https://github.com/NixOS/nix/blob/3e8cd2ffe6c2c6ed8aae7853ddcfcc6d2a49b0ce/tests/functional/lang/eval-okay-fromTOML.nix
|
||||
((apply_expression
|
||||
function: (_) @_func
|
||||
argument: (indented_string_expression (string_fragment) @injection.content))
|
||||
(#match? @_func "(^|\\.)fromTOML$")
|
||||
(#set! injection.language "toml")
|
||||
(#set! injection.combined))
|
||||
|
||||
; trivial-builders.nix pkgs.writeShellScript[Bin] name content
|
||||
((apply_expression
|
||||
function: (apply_expression function: (_) @_func)
|
||||
argument: (indented_string_expression (string_fragment) @injection.content))
|
||||
(#match? @_func "(^|\\.)writeShellScript(Bin)?$")
|
||||
(#set! injection.language "bash")
|
||||
(#set! injection.combined))
|
||||
|
||||
; trivial-builders.nix, aliases.nix
|
||||
; pkgs.runCommand[[No]CC][Local] name attrs content
|
||||
(apply_expression
|
||||
(apply_expression
|
||||
function: (apply_expression
|
||||
function: ((_) @_func)))
|
||||
argument: (indented_string_expression (string_fragment) @injection.content)
|
||||
(#match? @_func "(^|\\.)runCommand(((No)?(CC))?(Local)?)?$")
|
||||
(#set! injection.language "bash")
|
||||
(#set! injection.combined))
|
||||
|
||||
; trivial-builders.nix pkgs.writeShellApplication { text = content; }
|
||||
(apply_expression
|
||||
function: ((_) @_func)
|
||||
argument: (_ (_)* (_ (_)* (binding
|
||||
attrpath: (attrpath (identifier) @_path)
|
||||
expression: (indented_string_expression
|
||||
(string_fragment) @injection.content))))
|
||||
(#match? @_func "(^|\\.)writeShellApplication$")
|
||||
(#match? @_path "^text$")
|
||||
(#set! injection.language "bash")
|
||||
(#set! injection.combined))
|
||||
|
||||
; trivial-builders.nix pkgs.writeCBin name content
|
||||
((apply_expression
|
||||
function: (apply_expression function: (_) @_func)
|
||||
argument: (indented_string_expression (string_fragment) @injection.content))
|
||||
(#match? @_func "(^|\\.)writeC(Bin)?$")
|
||||
(#set! injection.language "c")
|
||||
(#set! injection.combined))
|
||||
|
||||
; pkgs.writers.* usage examples: nixpkgs/pkgs/build-support/writers/test.nix
|
||||
|
||||
; pkgs.writers.write{Bash,Dash}[Bin] name content
|
||||
((apply_expression
|
||||
function: (apply_expression function: (_) @_func)
|
||||
argument: (indented_string_expression (string_fragment) @injection.content))
|
||||
(#match? @_func "(^|\\.)write[BD]ash(Bin)?$")
|
||||
(#set! injection.language "bash")
|
||||
(#set! injection.combined))
|
||||
|
||||
; pkgs.writers.writeFish[Bin] name content
|
||||
((apply_expression
|
||||
function: (apply_expression function: (_) @_func)
|
||||
argument: (indented_string_expression (string_fragment) @injection.content))
|
||||
(#match? @_func "(^|\\.)writeFish(Bin)?$")
|
||||
(#set! injection.language "fish")
|
||||
(#set! injection.combined))
|
||||
|
||||
; pkgs.writers.writeRust[Bin] name attrs content
|
||||
(apply_expression
|
||||
(apply_expression
|
||||
function: (apply_expression
|
||||
function: ((_) @_func)))
|
||||
argument: (indented_string_expression (string_fragment) @injection.content)
|
||||
(#match? @_func "(^|\\.)writeRust(Bin)?$")
|
||||
(#set! injection.language "rust")
|
||||
(#set! injection.combined))
|
||||
|
||||
; pkgs.writers.writeHaskell[Bin] name attrs content
|
||||
(apply_expression
|
||||
(apply_expression
|
||||
function: (apply_expression
|
||||
function: ((_) @_func)))
|
||||
argument: (indented_string_expression (string_fragment) @injection.content)
|
||||
(#match? @_func "(^|\\.)writeHaskell(Bin)?$")
|
||||
(#set! injection.language "haskell")
|
||||
(#set! injection.combined))
|
||||
|
||||
; pkgs.writers.writeNim[Bin] name attrs content
|
||||
(apply_expression
|
||||
(apply_expression
|
||||
function: (apply_expression
|
||||
function: ((_) @_func)))
|
||||
argument: (indented_string_expression (string_fragment) @injection.content)
|
||||
(#match? @_func "(^|\\.)writeNim(Bin)?$")
|
||||
(#set! injection.language "nim")
|
||||
(#set! injection.combined))
|
||||
|
||||
; pkgs.writers.writeJS[Bin] name attrs content
|
||||
(apply_expression
|
||||
(apply_expression
|
||||
function: (apply_expression
|
||||
function: ((_) @_func)))
|
||||
argument: (indented_string_expression (string_fragment) @injection.content)
|
||||
(#match? @_func "(^|\\.)writeJS(Bin)?$")
|
||||
(#set! injection.language "javascript")
|
||||
(#set! injection.combined))
|
||||
|
||||
; pkgs.writers.writePerl[Bin] name attrs content
|
||||
(apply_expression
|
||||
(apply_expression
|
||||
function: (apply_expression
|
||||
function: ((_) @_func)))
|
||||
argument: (indented_string_expression (string_fragment) @injection.content)
|
||||
(#match? @_func "(^|\\.)writePerl(Bin)?$")
|
||||
(#set! injection.language "perl")
|
||||
(#set! injection.combined))
|
||||
|
||||
; pkgs.writers.write{Python,PyPy}{2,3}[Bin] name attrs content
|
||||
(apply_expression
|
||||
(apply_expression
|
||||
function: (apply_expression
|
||||
function: ((_) @_func)))
|
||||
argument: (indented_string_expression (string_fragment) @injection.content)
|
||||
(#match? @_func "(^|\\.)write(Python|PyPy)[23](Bin)?$")
|
||||
(#set! injection.language "python")
|
||||
(#set! injection.combined))
|
||||
|
||||
; pkgs.writers.writeNu[Bin] name attrs content
|
||||
(apply_expression
|
||||
(apply_expression
|
||||
function: (apply_expression
|
||||
function: ((_) @_func)))
|
||||
argument: (indented_string_expression (string_fragment) @injection.content)
|
||||
(#match? @_func "(^|\\.)writeNu(Bin)?$")
|
||||
(#set! injection.language "nu")
|
||||
(#set! injection.combined))
|
||||
|
||||
; pkgs.writers.writeRuby[Bin] name attrs content
|
||||
(apply_expression
|
||||
(apply_expression
|
||||
function: (apply_expression
|
||||
function: ((_) @_func)))
|
||||
argument: (indented_string_expression (string_fragment) @injection.content)
|
||||
(#match? @_func "(^|\\.)writeRuby(Bin)?$")
|
||||
(#set! injection.language "ruby")
|
||||
(#set! injection.combined))
|
||||
|
||||
; pkgs.writers.writeLua[Bin] name attrs content
|
||||
(apply_expression
|
||||
(apply_expression
|
||||
function: (apply_expression
|
||||
function: ((_) @_func)))
|
||||
argument: (indented_string_expression (string_fragment) @injection.content)
|
||||
(#match? @_func "(^|\\.)writeLua(Bin)?$")
|
||||
(#set! injection.language "lua")
|
||||
(#set! injection.combined))
|
||||
|
||||
; pkgs.writers.writeNginxConfig name attrs content
|
||||
(apply_expression
|
||||
(apply_expression
|
||||
function: (apply_expression
|
||||
function: ((_) @_func)))
|
||||
argument: (indented_string_expression (string_fragment) @injection.content)
|
||||
(#match? @_func "(^|\\.)writeNginxConfig$")
|
||||
(#set! injection.language "nginx")
|
||||
(#set! injection.combined))
|
||||
|
||||
; pkgs.writers.writeGuile[Bin] name attrs content
|
||||
(apply_expression
|
||||
(apply_expression
|
||||
function: (apply_expression
|
||||
function: ((_) @_func)))
|
||||
argument: (indented_string_expression (string_fragment) @injection.content)
|
||||
(#match? @_func "(^|\\.)writeGuile(Bin)?$")
|
||||
(#set! injection.language "scheme") ; Guile is a GNU specific implementation of scheme
|
||||
(#set! injection.combined))
|
||||
|
||||
|
||||
; pkgs.writers.writeBabashka[Bin] name attrs content
|
||||
(apply_expression
|
||||
(apply_expression
|
||||
function: (apply_expression
|
||||
function: ((_) @_func)))
|
||||
argument: (indented_string_expression (string_fragment) @injection.content)
|
||||
(#match? @_func "(^|\\.)writeBabashka(Bin)?$")
|
||||
(#set! injection.language "clojure")
|
||||
(#set! injection.combined))
|
||||
|
||||
; pkgs.writers.writeFSharp[Bin] name content
|
||||
; No query available for f-sharp as of the time of writing
|
||||
; See: https://github.com/helix-editor/helix/issues/4943
|
||||
; ((apply_expression
|
||||
; function: (apply_expression function: (_) @_func)
|
||||
; argument: (indented_string_expression (string_fragment) @injection.content))
|
||||
; (#match? @_func "(^|\\.)writeFSharp(Bin)?$")
|
||||
; (#set! injection.language "f-sharp")
|
||||
; (#set! injection.combined))
|
||||
|
||||
((apply_expression
|
||||
function: (apply_expression function: (_) @_func
|
||||
argument: (string_expression (string_fragment) @injection.filename))
|
||||
argument: (indented_string_expression (string_fragment) @injection.content))
|
||||
(#match? @_func "(^|\\.)write(Text|Script(Bin)?)$")
|
||||
(#set! injection.combined))
|
||||
|
||||
((indented_string_expression (string_fragment) @injection.shebang @injection.content)
|
||||
(#set! injection.combined))
|
||||
|
||||
; string contents of lib.literalExpression is nix code
|
||||
((apply_expression
|
||||
function: [
|
||||
(select_expression) ; `lib.literalExpression`
|
||||
(variable_expression) ; `literalExpression` this is the case when the symbol is brougth into scope e.g. `let inherit (lib) literalExpression; in`
|
||||
] @_func
|
||||
argument: [
|
||||
(indented_string_expression (string_fragment) @injection.content) ; lib.literalExpression ''...''
|
||||
(string_expression (string_fragment) @injection.content) ; lib.literalExpression "..."
|
||||
])
|
||||
(#any-of? @_func "lib.literalExpression" "literalExpression")
|
||||
(#set! injection.language "nix")
|
||||
(#set! injection.combined))
|
||||
Reference in New Issue
Block a user