From 18f603db3bee36d3fd7b03eb187e4c32d42363bc Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 28 Aug 2022 20:16:10 -0600 Subject: [PATCH] nix: add language injections 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. --- runtime/queries/nix/injections.scm | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 runtime/queries/nix/injections.scm diff --git a/runtime/queries/nix/injections.scm b/runtime/queries/nix/injections.scm new file mode 100644 index 0000000000000..6545522349b39 --- /dev/null +++ b/runtime/queries/nix/injections.scm @@ -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")) \ No newline at end of file