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 2, 2022
1 parent e066782 commit 2daca5a
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions runtime/queries/nix/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
; 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
(#match? @_func "(^|\\.)runCommand(CC|NoCC|Local|NoCCLocal)?$"))))
argument: (indented_string_expression (string_fragment) @injection.content
(#set! injection.language "bash")))

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

0 comments on commit 2daca5a

Please sign in to comment.