diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 2d06c3525..cc0a385d4 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -318,19 +318,32 @@ query.
### Injections
Some captures are related to language injection (like markdown code blocks). They are used in `injections.scm`.
-You can directly use the name of the language that you want to inject (e.g. `@html` to inject html).
-If you want to dynamically detect the language (e.g. for Markdown blocks) use the `@language` to capture
-the node describing the language and `@content` to describe the injection region.
+If you want to dynamically detect the language (e.g. for Markdown blocks) use the `@injection.language` to capture
+the node describing the language and `@injection.content` to describe the injection region.
```scheme
-@{lang} ; e.g. @html to describe a html region
-
-@language ; dynamic detection of the injection language (i.e. the text of the captured node describes the language)
-@content ; region for the dynamically detected language
-@combined ; combine all matches of a pattern as one single block of content
+@injection.language ; dynamic detection of the injection language (i.e. the text of the captured node describes the language)
+@injection.content ; region for the dynamically detected language
```
+For example, to inject javascript into HTML's `
+```
+
+```query
+(script_element
+ (raw_text) @injection.content
+ (#set! injection.language "javascript")) ; set the parser language for @injection.content region to javascript
+```
+
+For regions that don't have a corresponding `@injection.language`, you need to manually set the language
+through `(#set injection.language "lang_name")`
+
+To combine all matches of a pattern as one single block of content, add `(#set! injection.combined)` to such pattern
+
### Indents
```scheme
diff --git a/lua/nvim-treesitter/query_predicates.lua b/lua/nvim-treesitter/query_predicates.lua
index ff0e9999a..7f2b73c54 100644
--- a/lua/nvim-treesitter/query_predicates.lua
+++ b/lua/nvim-treesitter/query_predicates.lua
@@ -153,10 +153,10 @@ query.add_directive("set-lang-from-mimetype!", function(match, _, bufnr, pred, m
local type_attr_value = vim.treesitter.get_node_text(node, bufnr)
local configured = html_script_type_languages[type_attr_value]
if configured then
- metadata.language = configured
+ metadata["injection.language"] = configured
else
local parts = vim.split(type_attr_value, "/", {})
- metadata.language = parts[#parts]
+ metadata["injection.language"] = parts[#parts]
end
end, true)
@@ -172,7 +172,7 @@ query.add_directive("set-lang-from-info-string!", function(match, _, bufnr, pred
return
end
local injection_alias = vim.treesitter.get_node_text(node, bufnr)
- metadata.language = get_parser_from_markdown_info_string(injection_alias)
+ metadata["injection.language"] = get_parser_from_markdown_info_string(injection_alias)
end, true)
-- Just avoid some annoying warnings for this directive
@@ -211,37 +211,6 @@ query.add_directive("downcase!", function(match, _, bufnr, pred, metadata)
end
end, true)
----@param match (TSNode|nil)[]
----@param _pattern string
----@param _bufnr integer
----@param pred string[]
----@param metadata table
----@return boolean|nil
-query.add_directive("exclude_children!", function(match, _pattern, _bufnr, pred, metadata)
- local capture_id = pred[2]
- local node = match[capture_id]
- local start_row, start_col, end_row, end_col = node:range()
- local ranges = {}
- for i = 0, node:named_child_count() - 1 do
- local child = node:named_child(i) ---@type TSNode
- local child_start_row, child_start_col, child_end_row, child_end_col = child:range()
- if child_start_row > start_row or child_start_col > start_col then
- table.insert(ranges, {
- start_row,
- start_col,
- child_start_row,
- child_start_col,
- })
- end
- start_row = child_end_row
- start_col = child_end_col
- end
- if end_row > start_row or end_col > start_col then
- table.insert(ranges, { start_row, start_col, end_row, end_col })
- end
- metadata.content = ranges
-end, true)
-
-- Trim blank lines from end of the region
-- Arguments are the captures to trim.
---@param match (TSNode|nil)[]
diff --git a/queries/arduino/injections.scm b/queries/arduino/injections.scm
index 240162b9b..15d3b1670 100644
--- a/queries/arduino/injections.scm
+++ b/queries/arduino/injections.scm
@@ -1,6 +1,15 @@
-((preproc_def (preproc_arg) @arduino)
- (#lua-match? @arduino "\n"))
-(preproc_function_def (preproc_arg) @arduino)
-(preproc_call (preproc_arg) @arduino)
+((preproc_def
+ (preproc_arg) @injection.content)
+ (#lua-match? @injection.content "\n")
+ (#set! injection.language "arduino"))
-(comment) @comment
+(preproc_function_def
+ (preproc_arg) @injection.content
+ (#set! injection.language "arduino"))
+
+(preproc_call
+ (preproc_arg) @injection.content
+ (#set! injection.language "arduino"))
+
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/astro/injections.scm b/queries/astro/injections.scm
index 60ea3f5c6..b8f1ccefc 100644
--- a/queries/astro/injections.scm
+++ b/queries/astro/injections.scm
@@ -1,19 +1,23 @@
-; inherits: html
+; inherits: html_tags
-((frontmatter
- (raw_text) @typescript))
+(frontmatter
+ (raw_text) @injection.content
+ (#set! injection.language "typescript"))
-((interpolation
- (raw_text) @tsx))
+(interpolation
+ (raw_text) @injection.content
+ (#set! injection.language "tsx"))
-((script_element
- (raw_text) @typescript))
+(script_element
+ (raw_text) @injection.content
+ (#set! injection.language "typescript"))
-((style_element
- (start_tag
- (attribute
- (attribute_name) @_lang_attr
- (quoted_attribute_value (attribute_value) @_lang_value)))
- (raw_text) @scss)
+(style_element
+ (start_tag
+ (attribute
+ (attribute_name) @_lang_attr
+ (quoted_attribute_value (attribute_value) @_lang_value)))
+ (raw_text) @injection.content
(#eq? @_lang_attr "lang")
- (#eq? @_lang_value "scss"))
+ (#eq? @_lang_value "scss")
+ (#set! injection.language "scss"))
diff --git a/queries/awk/injections.scm b/queries/awk/injections.scm
index 8cbffc623..e5e2b4d02 100644
--- a/queries/awk/injections.scm
+++ b/queries/awk/injections.scm
@@ -1,2 +1,5 @@
-(comment) @comment
-(regex) @regex
+((comment) @injection.content
+ (#set! injection.language "comment"))
+
+((regex) @injection.content
+ (#set! injection.language "regex"))
diff --git a/queries/bash/injections.scm b/queries/bash/injections.scm
index 86371b905..e5e2b4d02 100644
--- a/queries/bash/injections.scm
+++ b/queries/bash/injections.scm
@@ -1,3 +1,5 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
-(regex) @regex
+((regex) @injection.content
+ (#set! injection.language "regex"))
diff --git a/queries/bass/injections.scm b/queries/bass/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/bass/injections.scm
+++ b/queries/bass/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/bicep/injections.scm b/queries/bicep/injections.scm
index c85cfe3b6..d3ff30b60 100644
--- a/queries/bicep/injections.scm
+++ b/queries/bicep/injections.scm
@@ -1,4 +1,5 @@
-[
- (comment)
- (diagnostic_comment)
-] @comment
+([
+ (comment)
+ (diagnostic_comment)
+ ] @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/c/injections.scm b/queries/c/injections.scm
index 2ef8f85c1..a1913e664 100644
--- a/queries/c/injections.scm
+++ b/queries/c/injections.scm
@@ -1,10 +1,21 @@
-((preproc_def (preproc_arg) @c)
- (#lua-match? @c "\n"))
-(preproc_function_def (preproc_arg) @c)
-(preproc_call (preproc_arg) @c)
+((preproc_def
+ (preproc_arg) @injection.content)
+ (#lua-match? @injection.content "\n")
+ (#set! injection.language "c"))
-(comment) @comment
+(preproc_function_def
+ (preproc_arg) @injection.content
+ (#set! injection.language "c"))
+
+(preproc_call
+ (preproc_arg) @injection.content
+ (#set! injection.language "c"))
+
+((comment) @injection.content
+ (#set! injection.language "comment"))
; TODO: add when asm is added
-; (gnu_asm_expression assembly_code: (string_literal) @asm)
-; (gnu_asm_expression assembly_code: (concatenated_string (string_literal) @asm))
+; (gnu_asm_expression assembly_code: (string_literal) @injection.content
+; (#set! injection.language "asm"))
+; (gnu_asm_expression assembly_code: (concatenated_string (string_literal) @injection.content)
+; (#set! injection.language "asm"))
diff --git a/queries/c_sharp/injections.scm b/queries/c_sharp/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/c_sharp/injections.scm
+++ b/queries/c_sharp/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/capnp/injections.scm b/queries/capnp/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/capnp/injections.scm
+++ b/queries/capnp/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/chatito/injections.scm b/queries/chatito/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/chatito/injections.scm
+++ b/queries/chatito/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/clojure/injections.scm b/queries/clojure/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/clojure/injections.scm
+++ b/queries/clojure/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/cpon/injections.scm b/queries/cpon/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/cpon/injections.scm
+++ b/queries/cpon/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/cpp/injections.scm b/queries/cpp/injections.scm
index 1d8e11cb3..2349c92bf 100644
--- a/queries/cpp/injections.scm
+++ b/queries/cpp/injections.scm
@@ -1,10 +1,19 @@
-((preproc_def (preproc_arg) @cpp)
- (#lua-match? @cpp "\n"))
-(preproc_function_def (preproc_arg) @cpp)
-(preproc_call (preproc_arg) @cpp)
+((preproc_def
+ (preproc_arg) @injection.content)
+ (#lua-match? @injection.content "\n")
+ (#set! injection.language "cpp"))
-(comment) @comment
+(preproc_function_def
+ (preproc_arg) @injection.content
+ (#set! injection.language "cpp"))
+
+(preproc_call
+ (preproc_arg) @injection.content
+ (#set! injection.language "cpp"))
+
+((comment) @injection.content
+ (#set! injection.language "comment"))
(raw_string_literal
- delimiter: (raw_string_delimiter) @language
- (raw_string_content) @content)
+ delimiter: (raw_string_delimiter) @injection.language
+ (raw_string_content) @injection.content)
diff --git a/queries/css/injections.scm b/queries/css/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/css/injections.scm
+++ b/queries/css/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/cuda/injections.scm b/queries/cuda/injections.scm
index 09deac468..bb37accb1 100644
--- a/queries/cuda/injections.scm
+++ b/queries/cuda/injections.scm
@@ -1,6 +1,15 @@
-((preproc_def (preproc_arg) @cuda)
- (#lua-match? @cuda "\n"))
-(preproc_function_def (preproc_arg) @cuda)
-(preproc_call (preproc_arg) @cuda)
+((preproc_def
+ (preproc_arg) @injection.content)
+ (#lua-match? @injection.content "\n")
+ (#set! injection.language "cuda"))
-(comment) @comment
+(preproc_function_def
+ (preproc_arg) @injection.content
+ (#set! injection.language "cuda"))
+
+(preproc_call
+ (preproc_arg) @injection.content
+ (#set! injection.language "cuda"))
+
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/cue/injections.scm b/queries/cue/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/cue/injections.scm
+++ b/queries/cue/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/d/injections.scm b/queries/d/injections.scm
index d95514370..6dd8aeacf 100644
--- a/queries/d/injections.scm
+++ b/queries/d/injections.scm
@@ -1,7 +1,9 @@
-[
+([
(line_comment)
(block_comment)
(nesting_block_comment)
-] @comment
+ ] @injection.content
+ (#set! injection.language "comment"))
-(token_string_tokens) @d
+((token_string_tokens) @injection.content
+ (#set! injection.language "d"))
diff --git a/queries/dart/injections.scm b/queries/dart/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/dart/injections.scm
+++ b/queries/dart/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/devicetree/injections.scm b/queries/devicetree/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/devicetree/injections.scm
+++ b/queries/devicetree/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/dhall/injections.scm b/queries/dhall/injections.scm
index e48ce9af3..43ae7287b 100644
--- a/queries/dhall/injections.scm
+++ b/queries/dhall/injections.scm
@@ -1,4 +1,5 @@
-[
+([
(line_comment)
(block_comment)
-] @comment
+ ] @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/dockerfile/injections.scm b/queries/dockerfile/injections.scm
index c1fdd3f99..2a48ec4f6 100644
--- a/queries/dockerfile/injections.scm
+++ b/queries/dockerfile/injections.scm
@@ -1,3 +1,5 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
-(shell_command) @bash
+((shell_command) @injection.content
+ (#set! injection.language "bash"))
diff --git a/queries/dot/injections.scm b/queries/dot/injections.scm
index 529d04d4a..ac41393ab 100644
--- a/queries/dot/injections.scm
+++ b/queries/dot/injections.scm
@@ -1,2 +1,5 @@
-(html_internal) @html
-(comment) @comment
+((html_internal) @injection.content
+ (#set! injection.language "html"))
+
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/ecma/injections.scm b/queries/ecma/injections.scm
index ba0ea4fa1..3b55295ce 100644
--- a/queries/ecma/injections.scm
+++ b/queries/ecma/injections.scm
@@ -1,59 +1,67 @@
(((comment) @_jsdoc_comment
- (#lua-match? @_jsdoc_comment "^/[*][*][^*].*[*]/$")) @jsdoc)
+ (#lua-match? @_jsdoc_comment "^/[*][*][^*].*[*]/$")) @injection.content
+ (#set! injection.language "jsdoc"))
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
; html(`...`), html`...`, sql(...) etc
(call_expression
- function: ((identifier) @language)
+ function: ((identifier) @injection.language)
arguments: [
(arguments
- (template_string) @content)
- (template_string) @content
+ (template_string) @injection.content)
+ (template_string) @injection.content
]
- (#offset! @content 0 1 0 -1)
- (#not-eq? @content "svg"))
+ (#offset! @injection.content 0 1 0 -1)
+ (#not-eq? @injection.language "svg"))
; svg`...` or svg(`...`), which uses the html parser, so is not included in the previous query
(call_expression
function: ((identifier) @_name (#eq? @_name "svg"))
arguments: [
(arguments
- (template_string) @html)
- (template_string) @html
+ (template_string) @injection.content)
+ (template_string) @injection.content
]
- (#offset! @html 0 1 0 -1))
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "html"))
(call_expression
function: ((identifier) @_name
(#eq? @_name "gql"))
- arguments: ((template_string) @graphql
- (#offset! @graphql 0 1 0 -1)))
+ arguments: ((template_string) @injection.content
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "graphql")))
(call_expression
function: ((identifier) @_name
(#eq? @_name "hbs"))
- arguments: ((template_string) @glimmer
- (#offset! @glimmer 0 1 0 -1)))
+ arguments: ((template_string) @injection.content
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "glimmer")))
-((glimmer_template) @glimmer)
+((glimmer_template) @injection.content
+ (#set! injection.language "glimmer"))
; styled.div``
(call_expression
function: (member_expression
object: (identifier) @_name
(#eq? @_name "styled"))
- arguments: ((template_string) @css
- (#offset! @css 0 1 0 -1)))
+ arguments: ((template_string) @injection.content
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "css")))
; styled(Component)``
(call_expression
function: (call_expression
function: (identifier) @_name
(#eq? @_name "styled"))
- arguments: ((template_string) @css
- (#offset! @css 0 1 0 -1)))
+ arguments: ((template_string) @injection.content
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "css")))
; styled.div.attrs({ prop: "foo" })``
(call_expression
@@ -62,8 +70,9 @@
object: (member_expression
object: (identifier) @_name
(#eq? @_name "styled"))))
- arguments: ((template_string) @css
- (#offset! @css 0 1 0 -1)))
+ arguments: ((template_string) @injection.content
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "css")))
; styled(Component).attrs({ prop: "foo" })``
@@ -73,31 +82,34 @@
object: (call_expression
function: (identifier) @_name
(#eq? @_name "styled"))))
- arguments: ((template_string) @css
- (#offset! @css 0 1 0 -1)))
+ arguments: ((template_string) @injection.content
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "css")))
-(regex_pattern) @regex
+((regex_pattern) @injection.content
+ (#set! injection.language "regex"))
; ((comment) @_gql_comment
; (#eq? @_gql_comment "/* GraphQL */")
-; (template_string) @graphql)
+; (template_string) @injection.content
+; (#set! injection.language "graphql"))
-((template_string) @graphql
- (#lua-match? @graphql "^`#graphql")
- (#offset! @graphql 0 1 0 -1))
+((template_string) @injection.content
+ (#lua-match? @injection.content "^`#graphql")
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "graphql"))
; el.innerHTML = ``
-(assignment_expression
- left: (member_expression
- property: (property_identifier) @_prop
- (#any-of? @_prop "innerHTML" "outerHTML"))
- right: (template_string) @html
- (#offset! @html 0 1 0 -1))
-
; el.innerHTML = ''
(assignment_expression
- left: (member_expression
- property: (property_identifier) @_prop
- (#any-of? @_prop "innerHTML" "outerHTML"))
- right: (string) @html
- (#offset! @html 0 1 0 -1))
+ left:
+ (member_expression
+ property: (property_identifier) @_prop
+ (#any-of? @_prop "outerHTML" "innerHTML"))
+ right:
+ [
+ (template_string)
+ (string)
+ ] @injection.content
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "html"))
diff --git a/queries/eex/injections.scm b/queries/eex/injections.scm
index f43206f55..9331f5925 100644
--- a/queries/eex/injections.scm
+++ b/queries/eex/injections.scm
@@ -1,5 +1,8 @@
; EEx expressions are Elixir
-(expression) @elixir
+((expression) @injection.content
+ (#set! injection.language "elixir"))
; EEx expressions can span multiple interpolated lines
-(partial_expression) @elixir @combined
+((partial_expression) @injection.content
+ (#set! injection.language "elixir")
+ (#set! injection.combined))
diff --git a/queries/elixir/injections.scm b/queries/elixir/injections.scm
index 423fddea7..1f0b31f07 100644
--- a/queries/elixir/injections.scm
+++ b/queries/elixir/injections.scm
@@ -1,5 +1,6 @@
; Comments
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
; Documentation
(unary_operator
@@ -7,42 +8,49 @@
operand: (call
target: ((identifier) @_identifier (#any-of? @_identifier "moduledoc" "typedoc" "shortdoc" "doc"))
(arguments [
- (string (quoted_content) @markdown)
- (sigil (quoted_content) @markdown)
- ])))
+ (string (quoted_content) @injection.content)
+ (sigil (quoted_content) @injection.content)
+ ])
+ (#set! injection.language "markdown")))
; HEEx
(sigil
(sigil_name) @_sigil_name
- (quoted_content) @heex
-(#eq? @_sigil_name "H"))
+ (quoted_content) @injection.content
+ (#eq? @_sigil_name "H")
+ (#set! injection.language "heex"))
; Surface
(sigil
(sigil_name) @_sigil_name
- (quoted_content) @surface
-(#eq? @_sigil_name "F"))
+ (quoted_content) @injection.content
+ (#eq? @_sigil_name "F")
+ (#set! injection.language "surface"))
; Zigler
(sigil
(sigil_name) @_sigil_name
- (quoted_content) @eex
-(#any-of? @_sigil_name "E" "L"))
+ (quoted_content) @injection.content
+ (#any-of? @_sigil_name "E" "L")
+ (#set! injection.language "eex"))
(sigil
(sigil_name) @_sigil_name
- (quoted_content) @zig
-(#any-of? @_sigil_name "z" "Z"))
+ (quoted_content) @injection.content
+ (#any-of? @_sigil_name "z" "Z")
+ (#set! injection.language "zig"))
; Regex
(sigil
(sigil_name) @_sigil_name
- (quoted_content) @regex
-(#any-of? @_sigil_name "r" "R"))
+ (quoted_content) @injection.content
+ (#any-of? @_sigil_name "r" "R")
+ (#set! injection.language "regex"))
-; Jason
+; Json
(sigil
(sigil_name) @_sigil_name
- (quoted_content) @json
-(#any-of? @_sigil_name "j" "J"))
+ (quoted_content) @injection.content
+ (#any-of? @_sigil_name "j" "J")
+ (#set! injection.language "json"))
diff --git a/queries/elm/injections.scm b/queries/elm/injections.scm
index 6395776e1..b8b3e9943 100644
--- a/queries/elm/injections.scm
+++ b/queries/elm/injections.scm
@@ -1,3 +1,8 @@
-[(line_comment) (block_comment)] @comment
+([
+ (line_comment)
+ (block_comment)
+ ] @injection.content
+ (#set! injection.language "comment"))
-(glsl_content) @glsl
+((glsl_content) @injection.content
+ (#set! injection.language "glsl"))
diff --git a/queries/elsa/injections.scm b/queries/elsa/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/elsa/injections.scm
+++ b/queries/elsa/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/elvish/injections.scm b/queries/elvish/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/elvish/injections.scm
+++ b/queries/elvish/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/embedded_template/injections.scm b/queries/embedded_template/injections.scm
index d55c87e09..2824f7a00 100644
--- a/queries/embedded_template/injections.scm
+++ b/queries/embedded_template/injections.scm
@@ -1,2 +1,7 @@
-(content) @html @combined
-(code) @ruby @combined
+((content) @injection.content
+ (#set! injection.language "html")
+ (#set! injection.combined))
+
+((code) @injection.content
+ (#set! injection.language "ruby")
+ (#set! injection.combined))
diff --git a/queries/fennel/injections.scm b/queries/fennel/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/fennel/injections.scm
+++ b/queries/fennel/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/firrtl/injections.scm b/queries/firrtl/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/firrtl/injections.scm
+++ b/queries/firrtl/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/fish/injections.scm b/queries/fish/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/fish/injections.scm
+++ b/queries/fish/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/foam/injections.scm b/queries/foam/injections.scm
index 4afdb63b0..2d744f6af 100644
--- a/queries/foam/injections.scm
+++ b/queries/foam/injections.scm
@@ -1,12 +1,20 @@
;; Pass code blocks to Cpp highlighter
-(code (code_body) @cpp)
+(code
+ (code_body) @injection.content
+ (#set! injection.language "cpp"))
;; Pass identifiers to Go highlighter (Cheating I know)
-;;((identifier) @lua)
+;; ((identifier) @injection.content
+;; (#set! injection.language "lua")
;; Highlight regex syntax inside literal strings
-((string_literal) @regex)
+((string_literal) @injection.content
+ (#set! injection.language "regex"))
;; Highlight PyFoam syntax as Python statements
-(pyfoam_variable code_body: (_) @python)
-(pyfoam_expression code_body: (_) @python)
+(pyfoam_variable
+ code_body: (_) @injection.content
+ (#set! injection.language "python"))
+(pyfoam_expression
+ code_body: (_) @injection.content
+ (#set! injection.language "python"))
diff --git a/queries/gdscript/injections.scm b/queries/gdscript/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/gdscript/injections.scm
+++ b/queries/gdscript/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/git_rebase/injections.scm b/queries/git_rebase/injections.scm
index 27388618e..8e6815a68 100644
--- a/queries/git_rebase/injections.scm
+++ b/queries/git_rebase/injections.scm
@@ -1,5 +1,6 @@
((operation
(command) @_command
- (message) @bash)
+ (message) @injection.content)
+(#set! injection.language "bash")
(#any-of? @_command "exec" "x"))
diff --git a/queries/gitattributes/injections.scm b/queries/gitattributes/injections.scm
index 4bb7d675d..6adae45a2 100644
--- a/queries/gitattributes/injections.scm
+++ b/queries/gitattributes/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/gitcommit/injections.scm b/queries/gitcommit/injections.scm
index eecdeee47..5e56dfa5f 100644
--- a/queries/gitcommit/injections.scm
+++ b/queries/gitcommit/injections.scm
@@ -1,2 +1,5 @@
-((diff) @diff (#exclude_children! @diff))
-(rebase_command) @git_rebase
+((diff) @injection.content
+ (#set! injection.language "diff"))
+
+((rebase_command) @injection.content
+ (#set! injection.language "git_rebase"))
diff --git a/queries/gleam/injections.scm b/queries/gleam/injections.scm
index ed4c2de91..378240e38 100644
--- a/queries/gleam/injections.scm
+++ b/queries/gleam/injections.scm
@@ -1,6 +1,7 @@
; Comments
-[
+([
(module_comment)
(statement_comment)
(comment)
-] @comment
+ ] @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/glsl/injections.scm b/queries/glsl/injections.scm
index 6d022021d..f9061052c 100644
--- a/queries/glsl/injections.scm
+++ b/queries/glsl/injections.scm
@@ -1,6 +1,15 @@
-((preproc_def (preproc_arg) @glsl)
- (#lua-match? @glsl "\n"))
-(preproc_function_def (preproc_arg) @glsl)
-(preproc_call (preproc_arg) @glsl)
+((preproc_def
+ (preproc_arg) @injection.content)
+ (#lua-match? @injection.content "\n")
+ (#set! injection.language "glsl"))
-(comment) @comment
+(preproc_function_def
+ (preproc_arg) @injection.content
+ (#set! injection.language "glsl"))
+
+(preproc_call
+ (preproc_arg) @injection.content
+ (#set! injection.language "glsl"))
+
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/go/injections.scm b/queries/go/injections.scm
index e0bdc99b9..68aa552cd 100644
--- a/queries/go/injections.scm
+++ b/queries/go/injections.scm
@@ -1,4 +1,5 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
(call_expression
(selector_expression) @_function (#any-of? @_function
@@ -10,4 +11,10 @@
"regexp.MustCompile"
"regexp.MustCompilePOSIX")
(argument_list
- . [(raw_string_literal) (interpreted_string_literal)] @regex (#offset! @regex 0 1 0 -1)))
+ .
+ [
+ (raw_string_literal)
+ (interpreted_string_literal)
+ ] @injection.content
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "regex")))
diff --git a/queries/gomod/injections.scm b/queries/gomod/injections.scm
index 4bb7d675d..321c90add 100644
--- a/queries/gomod/injections.scm
+++ b/queries/gomod/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/gowork/injections.scm b/queries/gowork/injections.scm
index 4bb7d675d..321c90add 100644
--- a/queries/gowork/injections.scm
+++ b/queries/gowork/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/graphql/injections.scm b/queries/graphql/injections.scm
index 4bb7d675d..321c90add 100644
--- a/queries/graphql/injections.scm
+++ b/queries/graphql/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/groovy/injections.scm b/queries/groovy/injections.scm
index 0a63c9bfe..0f3127b6b 100644
--- a/queries/groovy/injections.scm
+++ b/queries/groovy/injections.scm
@@ -1,4 +1,5 @@
-[
- (block_comment)
- (line_comment)
-] @comment
+((line_comment) @injection.content
+ (#set! injection.language "comment"))
+
+((block_comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/hare/injections.scm b/queries/hare/injections.scm
index 2992a948d..d3befb39b 100644
--- a/queries/hare/injections.scm
+++ b/queries/hare/injections.scm
@@ -1,8 +1,10 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
((call_expression
. (_) @_fnname
. "("
- . (_ [(string_content) (raw_string_content)] @regex)
+ . (_ [(string_content) (raw_string_content)] @injection.content)
. ")")
- (#any-of? @_fnname "compile" "regex::compile"))
+ (#any-of? @_fnname "compile" "regex::compile")
+ (#set! injection.language "regex"))
diff --git a/queries/haskell/injections.scm b/queries/haskell/injections.scm
index f210566c4..bc70e012f 100644
--- a/queries/haskell/injections.scm
+++ b/queries/haskell/injections.scm
@@ -2,11 +2,12 @@
;; General language injection
(quasiquote
- ((quoter) @language)
- ((quasiquote_body) @content)
+ ((quoter) @injection.language)
+ ((quasiquote_body) @injection.content)
)
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
;; -----------------------------------------------------------------------------
;; shakespeare library
@@ -17,35 +18,36 @@
; (quasiquote
; (quoter) @_name
; (#eq? @_name "coffee")
-; ((quasiquote_body) @coffeescript)
+; ((quasiquote_body) @injection.content
+; (#set! injection.language "coffeescript")))
; CSS: Text.Cassius, Text.Lucius
(quasiquote
(quoter) @_name
(#any-of? @_name "cassius" "lucius")
- ((quasiquote_body) @css)
-)
+ ((quasiquote_body) @injection.content)
+ (#set! injection.language "css"))
; HTML: Text.Hamlet
(quasiquote
(quoter) @_name
(#any-of? @_name "shamlet" "xshamlet" "hamlet" "xhamlet" "ihamlet")
- ((quasiquote_body) @html)
-)
+ ((quasiquote_body) @injection.content)
+ (#set! injection.language "html"))
; JS: Text.Julius
(quasiquote
(quoter) @_name
(#any-of? @_name "js" "julius")
- ((quasiquote_body) @javascript)
-)
+ ((quasiquote_body) @injection.content)
+ (#set! injection.language "javascript"))
; TS: Text.TypeScript
(quasiquote
(quoter) @_name
(#any-of? @_name "tsc" "tscJSX")
- ((quasiquote_body) @typescript)
-)
+ ((quasiquote_body) @injection.content)
+ (#set! injection.language "typescript"))
;; -----------------------------------------------------------------------------
@@ -54,8 +56,8 @@
(quasiquote
(quoter) @_name
(#eq? @_name "hsx")
- ((quasiquote_body) @html)
-)
+ ((quasiquote_body) @injection.content)
+ (#set! injection.language "html"))
;; -----------------------------------------------------------------------------
;; Inline JSON from aeson
@@ -63,8 +65,8 @@
(quasiquote
(quoter) @_name
(#eq? @_name "aesonQQ")
- ((quasiquote_body) @json)
-)
+ ((quasiquote_body) @injection.content)
+ (#set! injection.language "json"))
;; -----------------------------------------------------------------------------
@@ -72,14 +74,12 @@
; postgresql-simple
(quasiquote
- (quoter) @_name
- (#eq? @_name "sql")
- ((quasiquote_body) @sql)
-)
+ (quoter) @injection.language
+ (#eq? @injection.language "sql")
+ ((quasiquote_body) @injection.content))
-; persistent
(quasiquote
- (quoter) @_name
- (#any-of? @_name "persistUpperCase" "persistLowerCase" "persistWith")
- ((quasiquote_body) @haskell_persistent)
-)
+ (quoter) @_name
+ (#any-of? @_name "persistUpperCase" "persistLowerCase" "persistWith")
+ ((quasiquote_body) @injection.content)
+ (#set! injection.language "haskell_persistent"))
diff --git a/queries/hcl/injections.scm b/queries/hcl/injections.scm
index 94451beb4..fd881d503 100644
--- a/queries/hcl/injections.scm
+++ b/queries/hcl/injections.scm
@@ -1,7 +1,7 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
(heredoc_template
- (template_literal) @content
- (heredoc_identifier) @language
- (#set! "language" @language)
- (#downcase! "language"))
+ (template_literal) @injection.content
+ (heredoc_identifier) @injection.language
+ (#downcase! @injection.language))
diff --git a/queries/heex/injections.scm b/queries/heex/injections.scm
index fffd1dc53..1aa822197 100644
--- a/queries/heex/injections.scm
+++ b/queries/heex/injections.scm
@@ -2,10 +2,15 @@
(directive [
(expression_value)
(partial_expression_value)
-] @elixir @combined)
+] @injection.content
+ (#set! injection.language "elixir")
+ (#set! injection.combined))
; HEEx Elixir expressions are always within a tag or component
-(expression (expression_value) @elixir)
+(expression
+ (expression_value) @injection.content
+ (#set! injection.language "elixir"))
; HEEx comments
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/hjson/injections.scm b/queries/hjson/injections.scm
index 4bb7d675d..321c90add 100644
--- a/queries/hjson/injections.scm
+++ b/queries/hjson/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/hlsl/injections.scm b/queries/hlsl/injections.scm
index 52e88686c..9a9fcd6e8 100644
--- a/queries/hlsl/injections.scm
+++ b/queries/hlsl/injections.scm
@@ -1,6 +1,15 @@
-((preproc_def (preproc_arg) @hlsl)
- (#lua-match? @hlsl "\n"))
-(preproc_function_def (preproc_arg) @hlsl)
-(preproc_call (preproc_arg) @hlsl)
+((preproc_def
+ (preproc_arg) @injection.content)
+ (#lua-match? @injection.content "\n")
+ (#set! injection.language "hlsl"))
-(comment) @comment
+(preproc_function_def
+ (preproc_arg) @injection.content
+ (#set! injection.language "hlsl"))
+
+(preproc_call
+ (preproc_arg) @injection.content
+ (#set! injection.language "hlsl"))
+
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/hocon/injections.scm b/queries/hocon/injections.scm
index 4bb7d675d..321c90add 100644
--- a/queries/hocon/injections.scm
+++ b/queries/hocon/injections.scm
@@ -1 +1,2 @@
-(comment) @comment
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/html/injections.scm b/queries/html/injections.scm
index 23981018c..eba8395a4 100644
--- a/queries/html/injections.scm
+++ b/queries/html/injections.scm
@@ -3,8 +3,10 @@
(element
(start_tag
(tag_name) @_py_script)
- (text) @python
- (#any-of? @_py_script "py-script" "py-repl"))
+ (text) @injection.content
+ (#any-of? @_py_script "py-script" "py-repl")
+ (#set! injection.language "python")
+ (#set! injection.include-children))
(script_element
(start_tag
@@ -12,13 +14,17 @@
(attribute_name) @_attr
(quoted_attribute_value
(attribute_value) @_type)))
- (raw_text) @python
+ (raw_text) @injection.content
(#eq? @_attr "type")
; not adding type="py" here as it's handled by html_tags
- (#any-of? @_type "pyscript" "py-script"))
+ (#any-of? @_type "pyscript" "py-script")
+ (#set! injection.language "python")
+ (#set! injection.include-children))
(element
(start_tag
(tag_name) @_py_config)
- (text) @toml
- (#eq? @_py_config "py-config"))
+ (text) @injection.content
+ (#eq? @_py_config "py-config")
+ (#set! injection.language "toml")
+ (#set! injection.include-children))
diff --git a/queries/html_tags/injections.scm b/queries/html_tags/injections.scm
index 29608a5a4..5b9e5350f 100644
--- a/queries/html_tags/injections.scm
+++ b/queries/html_tags/injections.scm
@@ -2,73 +2,84 @@
;
; Add "lang" to predicate check so that vue/svelte can inherit this
; without having this element being captured twice
-(
- (style_element
+((style_element
(start_tag) @_no_type_lang
- (#not-lua-match? @_no_type_lang "%slang%s*=")
- (#not-lua-match? @_no_type_lang "%stype%s*=")
- (raw_text) @css))
+ (raw_text) @injection.content)
+ (#not-lua-match? @_no_type_lang "%slang%s*=")
+ (#not-lua-match? @_no_type_lang "%stype%s*=")
+ (#set! injection.language "css")
+ (#set! injection.include-children))
-(
- (style_element
- (start_tag
- (attribute
- (attribute_name) @_type
- (quoted_attribute_value (attribute_value) @_css)))
- (raw_text) @css)
- (#eq? @_type "type")
- (#eq? @_css "text/css")
-)
+((style_element
+ (start_tag
+ (attribute
+ (attribute_name) @_type
+ (quoted_attribute_value (attribute_value) @_css)))
+ (raw_text) @injection.content)
+ (#eq? @_type "type")
+ (#eq? @_css "text/css")
+ (#set! injection.language "css")
+ (#set! injection.include-children))
;
;
-(
- (script_element
- (start_tag) @_no_type_lang
- (#not-lua-match? @_no_type_lang "%slang%s*=")
- (#not-lua-match? @_no_type_lang "%stype%s*=")
- (raw_text) @javascript))
+((script_element
+ (start_tag) @_no_type_lang
+ (raw_text) @injection.content)
+ (#not-lua-match? @_no_type_lang "%slang%s*=")
+ (#not-lua-match? @_no_type_lang "%stype%s*=")
+ (#set! injection.language "javascript")
+ (#set! injection.include-children))
;