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 above
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 committed Sep 3, 2022
1 parent e917a8e commit 18f603d
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions runtime/queries/nix/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
; mark arbitary languages with a comment
(
((comment) @injection.language) . [
(indented_string_expression (_) @injection.content)
(_ (_)* (indented_string_expression (_) @injection.content))
(_ (_)* (_ (_)* (indented_string_expression (_) @injection.content)))
(_ (_)* (_ (_)* (_ (_)* (indented_string_expression (_) @injection.content))))
(_ (_)* (_ (_)* (_ (_)* (_ (_)* (indented_string_expression (_) @injection.content)))))])

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

((apply_expression
function: (apply_expression function: (_) @_func)
argument: (indented_string_expression (string_fragment) @injection.content))
(#match? @_func "(^|\\.)writeShellScript(Bin)?$")
(#set! injection.language "bash"))

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

(apply_expression
function: ((_) @_func)
argument: (_ (_)* (_ (_)* (binding
attrpath: (attrpath (identifier) @_path)
expression: [
(indented_string_expression (string_fragment) @injection.content)
(_ (_)* (indented_string_expression (string_fragment) @injection.content) .)
(_ (_)* (_ (_)* (indented_string_expression (string_fragment) @injection.content)))
])))
(#match? @_func "(^|\\.)writeShellApplication$")
(#match? @_path "^text$")
(#set! injection.language "bash"))

0 comments on commit 18f603d

Please sign in to comment.