Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

queries/nix: add injections for builtins and writers #5629

Merged
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions runtime/queries/nix/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
(indented_string_expression (string_fragment) @injection.content))
(#set! injection.combined))

; Common attribute keys corresponding to scripts,
; such as those of stdenv.mkDerivation.
((binding
attrpath: (attrpath (identifier) @_path)
expression: (indented_string_expression
Expand All @@ -14,13 +16,34 @@
(#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))

; 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
Expand All @@ -30,6 +53,7 @@
(#set! injection.language "bash")
(#set! injection.combined))

; trivial-builders.nix pkgs.writeShellApplication { text = content; }
(apply_expression
function: ((_) @_func)
argument: (_ (_)* (_ (_)* (binding
Expand All @@ -40,3 +64,89 @@
(#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 "(^|\\.)writeCBin$")
pacien marked this conversation as resolved.
Show resolved Hide resolved
(#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.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.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))