Skip to content

Commit

Permalink
nix: add language injections
Browse files Browse the repository at this point in the history
By simply placing a comment with the name of the desired language just
before a multi-line string, that language will be injected.

Also, common functions and attributes which are expected to be shell
code are automatically injected.
  • Loading branch information
nrdxp authored and the-mikedavis committed Sep 6, 2022
1 parent 43b31f7 commit 665e27f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions runtime/queries/nix/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
; mark arbitary languages with a comment
((((comment) @injection.language) .
(indented_string_expression (string_fragment) @injection.content))
(#set! injection.combined))

((binding
attrpath: (attrpath (identifier) @_path)
expression: (indented_string_expression
(string_fragment) @injection.content))
(#match? @_path "(^\\w*Phase|(pre|post)\\w*|(.*\\.)?\\w*([sS]cript|[hH]ook)|(.*\\.)?startup)$")
(#set! injection.language "bash")
(#set! injection.combined))

((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))

(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))

(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))

0 comments on commit 665e27f

Please sign in to comment.