chore(injections)!: update injection syntax to 0.9

Since 0.9, @lang syntax is still available as fallback but will soon be deprecated.
Because of that, new syntax should be adopted once 0.9 becomes the
baseline requirements for nvim-treesitter

- update health check
- update doc
This commit is contained in:
Pham Huy Hoang 2023-05-03 19:07:59 +09:00 committed by Christian Clason
parent 2aa9e9b0e6
commit 78b54eb7f6
140 changed files with 1083 additions and 665 deletions

View file

@ -318,19 +318,32 @@ query.
### Injections ### Injections
Some captures are related to language injection (like markdown code blocks). They are used in `injections.scm`. 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 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 `@content` to describe the injection region. the node describing the language and `@injection.content` to describe the injection region.
```scheme ```scheme
@{lang} ; e.g. @html to describe a html region @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
@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
``` ```
For example, to inject javascript into HTML's `<script>` tag
```html
<script>someJsCode();</script>
```
```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 ### Indents
```scheme ```scheme

View file

@ -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 type_attr_value = vim.treesitter.get_node_text(node, bufnr)
local configured = html_script_type_languages[type_attr_value] local configured = html_script_type_languages[type_attr_value]
if configured then if configured then
metadata.language = configured metadata["injection.language"] = configured
else else
local parts = vim.split(type_attr_value, "/", {}) local parts = vim.split(type_attr_value, "/", {})
metadata.language = parts[#parts] metadata["injection.language"] = parts[#parts]
end end
end, true) end, true)
@ -172,7 +172,7 @@ query.add_directive("set-lang-from-info-string!", function(match, _, bufnr, pred
return return
end end
local injection_alias = vim.treesitter.get_node_text(node, bufnr) 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) end, true)
-- Just avoid some annoying warnings for this directive -- Just avoid some annoying warnings for this directive
@ -211,37 +211,6 @@ query.add_directive("downcase!", function(match, _, bufnr, pred, metadata)
end end
end, true) 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 -- Trim blank lines from end of the region
-- Arguments are the captures to trim. -- Arguments are the captures to trim.
---@param match (TSNode|nil)[] ---@param match (TSNode|nil)[]

View file

@ -1,6 +1,15 @@
((preproc_def (preproc_arg) @arduino) ((preproc_def
(#lua-match? @arduino "\n")) (preproc_arg) @injection.content)
(preproc_function_def (preproc_arg) @arduino) (#lua-match? @injection.content "\n")
(preproc_call (preproc_arg) @arduino) (#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"))

View file

@ -1,19 +1,23 @@
; inherits: html ; inherits: html_tags
((frontmatter (frontmatter
(raw_text) @typescript)) (raw_text) @injection.content
(#set! injection.language "typescript"))
((interpolation (interpolation
(raw_text) @tsx)) (raw_text) @injection.content
(#set! injection.language "tsx"))
((script_element (script_element
(raw_text) @typescript)) (raw_text) @injection.content
(#set! injection.language "typescript"))
((style_element (style_element
(start_tag (start_tag
(attribute (attribute
(attribute_name) @_lang_attr (attribute_name) @_lang_attr
(quoted_attribute_value (attribute_value) @_lang_value))) (quoted_attribute_value (attribute_value) @_lang_value)))
(raw_text) @scss) (raw_text) @injection.content
(#eq? @_lang_attr "lang") (#eq? @_lang_attr "lang")
(#eq? @_lang_value "scss")) (#eq? @_lang_value "scss")
(#set! injection.language "scss"))

View file

@ -1,2 +1,5 @@
(comment) @comment ((comment) @injection.content
(regex) @regex (#set! injection.language "comment"))
((regex) @injection.content
(#set! injection.language "regex"))

View file

@ -1,3 +1,5 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))
(regex) @regex ((regex) @injection.content
(#set! injection.language "regex"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,4 +1,5 @@
[ ([
(comment) (comment)
(diagnostic_comment) (diagnostic_comment)
] @comment ] @injection.content
(#set! injection.language "comment"))

View file

@ -1,10 +1,21 @@
((preproc_def (preproc_arg) @c) ((preproc_def
(#lua-match? @c "\n")) (preproc_arg) @injection.content)
(preproc_function_def (preproc_arg) @c) (#lua-match? @injection.content "\n")
(preproc_call (preproc_arg) @c) (#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 ; TODO: add when asm is added
; (gnu_asm_expression assembly_code: (string_literal) @asm) ; (gnu_asm_expression assembly_code: (string_literal) @injection.content
; (gnu_asm_expression assembly_code: (concatenated_string (string_literal) @asm)) ; (#set! injection.language "asm"))
; (gnu_asm_expression assembly_code: (concatenated_string (string_literal) @injection.content)
; (#set! injection.language "asm"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,10 +1,19 @@
((preproc_def (preproc_arg) @cpp) ((preproc_def
(#lua-match? @cpp "\n")) (preproc_arg) @injection.content)
(preproc_function_def (preproc_arg) @cpp) (#lua-match? @injection.content "\n")
(preproc_call (preproc_arg) @cpp) (#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 (raw_string_literal
delimiter: (raw_string_delimiter) @language delimiter: (raw_string_delimiter) @injection.language
(raw_string_content) @content) (raw_string_content) @injection.content)

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,6 +1,15 @@
((preproc_def (preproc_arg) @cuda) ((preproc_def
(#lua-match? @cuda "\n")) (preproc_arg) @injection.content)
(preproc_function_def (preproc_arg) @cuda) (#lua-match? @injection.content "\n")
(preproc_call (preproc_arg) @cuda) (#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"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,7 +1,9 @@
[ ([
(line_comment) (line_comment)
(block_comment) (block_comment)
(nesting_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"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,4 +1,5 @@
[ ([
(line_comment) (line_comment)
(block_comment) (block_comment)
] @comment ] @injection.content
(#set! injection.language "comment"))

View file

@ -1,3 +1,5 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))
(shell_command) @bash ((shell_command) @injection.content
(#set! injection.language "bash"))

View file

@ -1,2 +1,5 @@
(html_internal) @html ((html_internal) @injection.content
(comment) @comment (#set! injection.language "html"))
((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,59 +1,67 @@
(((comment) @_jsdoc_comment (((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 ; html(`...`), html`...`, sql(...) etc
(call_expression (call_expression
function: ((identifier) @language) function: ((identifier) @injection.language)
arguments: [ arguments: [
(arguments (arguments
(template_string) @content) (template_string) @injection.content)
(template_string) @content (template_string) @injection.content
] ]
(#offset! @content 0 1 0 -1) (#offset! @injection.content 0 1 0 -1)
(#not-eq? @content "svg")) (#not-eq? @injection.language "svg"))
; svg`...` or svg(`...`), which uses the html parser, so is not included in the previous query ; svg`...` or svg(`...`), which uses the html parser, so is not included in the previous query
(call_expression (call_expression
function: ((identifier) @_name (#eq? @_name "svg")) function: ((identifier) @_name (#eq? @_name "svg"))
arguments: [ arguments: [
(arguments (arguments
(template_string) @html) (template_string) @injection.content)
(template_string) @html (template_string) @injection.content
] ]
(#offset! @html 0 1 0 -1)) (#offset! @injection.content 0 1 0 -1)
(#set! injection.language "html"))
(call_expression (call_expression
function: ((identifier) @_name function: ((identifier) @_name
(#eq? @_name "gql")) (#eq? @_name "gql"))
arguments: ((template_string) @graphql arguments: ((template_string) @injection.content
(#offset! @graphql 0 1 0 -1))) (#offset! @injection.content 0 1 0 -1)
(#set! injection.language "graphql")))
(call_expression (call_expression
function: ((identifier) @_name function: ((identifier) @_name
(#eq? @_name "hbs")) (#eq? @_name "hbs"))
arguments: ((template_string) @glimmer arguments: ((template_string) @injection.content
(#offset! @glimmer 0 1 0 -1))) (#offset! @injection.content 0 1 0 -1)
(#set! injection.language "glimmer")))
((glimmer_template) @glimmer) ((glimmer_template) @injection.content
(#set! injection.language "glimmer"))
; styled.div`<css>` ; styled.div`<css>`
(call_expression (call_expression
function: (member_expression function: (member_expression
object: (identifier) @_name object: (identifier) @_name
(#eq? @_name "styled")) (#eq? @_name "styled"))
arguments: ((template_string) @css arguments: ((template_string) @injection.content
(#offset! @css 0 1 0 -1))) (#offset! @injection.content 0 1 0 -1)
(#set! injection.language "css")))
; styled(Component)`<css>` ; styled(Component)`<css>`
(call_expression (call_expression
function: (call_expression function: (call_expression
function: (identifier) @_name function: (identifier) @_name
(#eq? @_name "styled")) (#eq? @_name "styled"))
arguments: ((template_string) @css arguments: ((template_string) @injection.content
(#offset! @css 0 1 0 -1))) (#offset! @injection.content 0 1 0 -1)
(#set! injection.language "css")))
; styled.div.attrs({ prop: "foo" })`<css>` ; styled.div.attrs({ prop: "foo" })`<css>`
(call_expression (call_expression
@ -62,8 +70,9 @@
object: (member_expression object: (member_expression
object: (identifier) @_name object: (identifier) @_name
(#eq? @_name "styled")))) (#eq? @_name "styled"))))
arguments: ((template_string) @css arguments: ((template_string) @injection.content
(#offset! @css 0 1 0 -1))) (#offset! @injection.content 0 1 0 -1)
(#set! injection.language "css")))
; styled(Component).attrs({ prop: "foo" })`<css>` ; styled(Component).attrs({ prop: "foo" })`<css>`
@ -73,31 +82,34 @@
object: (call_expression object: (call_expression
function: (identifier) @_name function: (identifier) @_name
(#eq? @_name "styled")))) (#eq? @_name "styled"))))
arguments: ((template_string) @css arguments: ((template_string) @injection.content
(#offset! @css 0 1 0 -1))) (#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 ; ((comment) @_gql_comment
; (#eq? @_gql_comment "/* GraphQL */") ; (#eq? @_gql_comment "/* GraphQL */")
; (template_string) @graphql) ; (template_string) @injection.content
; (#set! injection.language "graphql"))
((template_string) @graphql ((template_string) @injection.content
(#lua-match? @graphql "^`#graphql") (#lua-match? @injection.content "^`#graphql")
(#offset! @graphql 0 1 0 -1)) (#offset! @injection.content 0 1 0 -1)
(#set! injection.language "graphql"))
; el.innerHTML = `<html>` ; el.innerHTML = `<html>`
(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 = '<html>' ; el.innerHTML = '<html>'
(assignment_expression (assignment_expression
left: (member_expression left:
property: (property_identifier) @_prop (member_expression
(#any-of? @_prop "innerHTML" "outerHTML")) property: (property_identifier) @_prop
right: (string) @html (#any-of? @_prop "outerHTML" "innerHTML"))
(#offset! @html 0 1 0 -1)) right:
[
(template_string)
(string)
] @injection.content
(#offset! @injection.content 0 1 0 -1)
(#set! injection.language "html"))

View file

@ -1,5 +1,8 @@
; EEx expressions are Elixir ; EEx expressions are Elixir
(expression) @elixir ((expression) @injection.content
(#set! injection.language "elixir"))
; EEx expressions can span multiple interpolated lines ; EEx expressions can span multiple interpolated lines
(partial_expression) @elixir @combined ((partial_expression) @injection.content
(#set! injection.language "elixir")
(#set! injection.combined))

View file

@ -1,5 +1,6 @@
; Comments ; Comments
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))
; Documentation ; Documentation
(unary_operator (unary_operator
@ -7,42 +8,49 @@
operand: (call operand: (call
target: ((identifier) @_identifier (#any-of? @_identifier "moduledoc" "typedoc" "shortdoc" "doc")) target: ((identifier) @_identifier (#any-of? @_identifier "moduledoc" "typedoc" "shortdoc" "doc"))
(arguments [ (arguments [
(string (quoted_content) @markdown) (string (quoted_content) @injection.content)
(sigil (quoted_content) @markdown) (sigil (quoted_content) @injection.content)
]))) ])
(#set! injection.language "markdown")))
; HEEx ; HEEx
(sigil (sigil
(sigil_name) @_sigil_name (sigil_name) @_sigil_name
(quoted_content) @heex (quoted_content) @injection.content
(#eq? @_sigil_name "H")) (#eq? @_sigil_name "H")
(#set! injection.language "heex"))
; Surface ; Surface
(sigil (sigil
(sigil_name) @_sigil_name (sigil_name) @_sigil_name
(quoted_content) @surface (quoted_content) @injection.content
(#eq? @_sigil_name "F")) (#eq? @_sigil_name "F")
(#set! injection.language "surface"))
; Zigler ; Zigler
(sigil (sigil
(sigil_name) @_sigil_name (sigil_name) @_sigil_name
(quoted_content) @eex (quoted_content) @injection.content
(#any-of? @_sigil_name "E" "L")) (#any-of? @_sigil_name "E" "L")
(#set! injection.language "eex"))
(sigil (sigil
(sigil_name) @_sigil_name (sigil_name) @_sigil_name
(quoted_content) @zig (quoted_content) @injection.content
(#any-of? @_sigil_name "z" "Z")) (#any-of? @_sigil_name "z" "Z")
(#set! injection.language "zig"))
; Regex ; Regex
(sigil (sigil
(sigil_name) @_sigil_name (sigil_name) @_sigil_name
(quoted_content) @regex (quoted_content) @injection.content
(#any-of? @_sigil_name "r" "R")) (#any-of? @_sigil_name "r" "R")
(#set! injection.language "regex"))
; Jason ; Json
(sigil (sigil
(sigil_name) @_sigil_name (sigil_name) @_sigil_name
(quoted_content) @json (quoted_content) @injection.content
(#any-of? @_sigil_name "j" "J")) (#any-of? @_sigil_name "j" "J")
(#set! injection.language "json"))

View file

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

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,2 +1,7 @@
(content) @html @combined ((content) @injection.content
(code) @ruby @combined (#set! injection.language "html")
(#set! injection.combined))
((code) @injection.content
(#set! injection.language "ruby")
(#set! injection.combined))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,12 +1,20 @@
;; Pass code blocks to Cpp highlighter ;; 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) ;; Pass identifiers to Go highlighter (Cheating I know)
;;((identifier) @lua) ;; ((identifier) @injection.content
;; (#set! injection.language "lua")
;; Highlight regex syntax inside literal strings ;; Highlight regex syntax inside literal strings
((string_literal) @regex) ((string_literal) @injection.content
(#set! injection.language "regex"))
;; Highlight PyFoam syntax as Python statements ;; Highlight PyFoam syntax as Python statements
(pyfoam_variable code_body: (_) @python) (pyfoam_variable
(pyfoam_expression code_body: (_) @python) code_body: (_) @injection.content
(#set! injection.language "python"))
(pyfoam_expression
code_body: (_) @injection.content
(#set! injection.language "python"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,5 +1,6 @@
((operation ((operation
(command) @_command (command) @_command
(message) @bash) (message) @injection.content)
(#set! injection.language "bash")
(#any-of? @_command "exec" "x")) (#any-of? @_command "exec" "x"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,2 +1,5 @@
((diff) @diff (#exclude_children! @diff)) ((diff) @injection.content
(rebase_command) @git_rebase (#set! injection.language "diff"))
((rebase_command) @injection.content
(#set! injection.language "git_rebase"))

View file

@ -1,6 +1,7 @@
; Comments ; Comments
[ ([
(module_comment) (module_comment)
(statement_comment) (statement_comment)
(comment) (comment)
] @comment ] @injection.content
(#set! injection.language "comment"))

View file

@ -1,6 +1,15 @@
((preproc_def (preproc_arg) @glsl) ((preproc_def
(#lua-match? @glsl "\n")) (preproc_arg) @injection.content)
(preproc_function_def (preproc_arg) @glsl) (#lua-match? @injection.content "\n")
(preproc_call (preproc_arg) @glsl) (#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"))

View file

@ -1,4 +1,5 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))
(call_expression (call_expression
(selector_expression) @_function (#any-of? @_function (selector_expression) @_function (#any-of? @_function
@ -10,4 +11,10 @@
"regexp.MustCompile" "regexp.MustCompile"
"regexp.MustCompilePOSIX") "regexp.MustCompilePOSIX")
(argument_list (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")))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,4 +1,5 @@
[ ((line_comment) @injection.content
(block_comment) (#set! injection.language "comment"))
(line_comment)
] @comment ((block_comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,8 +1,10 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))
((call_expression ((call_expression
. (_) @_fnname . (_) @_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"))

View file

@ -2,11 +2,12 @@
;; General language injection ;; General language injection
(quasiquote (quasiquote
((quoter) @language) ((quoter) @injection.language)
((quasiquote_body) @content) ((quasiquote_body) @injection.content)
) )
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))
;; ----------------------------------------------------------------------------- ;; -----------------------------------------------------------------------------
;; shakespeare library ;; shakespeare library
@ -17,35 +18,36 @@
; (quasiquote ; (quasiquote
; (quoter) @_name ; (quoter) @_name
; (#eq? @_name "coffee") ; (#eq? @_name "coffee")
; ((quasiquote_body) @coffeescript) ; ((quasiquote_body) @injection.content
; (#set! injection.language "coffeescript")))
; CSS: Text.Cassius, Text.Lucius ; CSS: Text.Cassius, Text.Lucius
(quasiquote (quasiquote
(quoter) @_name (quoter) @_name
(#any-of? @_name "cassius" "lucius") (#any-of? @_name "cassius" "lucius")
((quasiquote_body) @css) ((quasiquote_body) @injection.content)
) (#set! injection.language "css"))
; HTML: Text.Hamlet ; HTML: Text.Hamlet
(quasiquote (quasiquote
(quoter) @_name (quoter) @_name
(#any-of? @_name "shamlet" "xshamlet" "hamlet" "xhamlet" "ihamlet") (#any-of? @_name "shamlet" "xshamlet" "hamlet" "xhamlet" "ihamlet")
((quasiquote_body) @html) ((quasiquote_body) @injection.content)
) (#set! injection.language "html"))
; JS: Text.Julius ; JS: Text.Julius
(quasiquote (quasiquote
(quoter) @_name (quoter) @_name
(#any-of? @_name "js" "julius") (#any-of? @_name "js" "julius")
((quasiquote_body) @javascript) ((quasiquote_body) @injection.content)
) (#set! injection.language "javascript"))
; TS: Text.TypeScript ; TS: Text.TypeScript
(quasiquote (quasiquote
(quoter) @_name (quoter) @_name
(#any-of? @_name "tsc" "tscJSX") (#any-of? @_name "tsc" "tscJSX")
((quasiquote_body) @typescript) ((quasiquote_body) @injection.content)
) (#set! injection.language "typescript"))
;; ----------------------------------------------------------------------------- ;; -----------------------------------------------------------------------------
@ -54,8 +56,8 @@
(quasiquote (quasiquote
(quoter) @_name (quoter) @_name
(#eq? @_name "hsx") (#eq? @_name "hsx")
((quasiquote_body) @html) ((quasiquote_body) @injection.content)
) (#set! injection.language "html"))
;; ----------------------------------------------------------------------------- ;; -----------------------------------------------------------------------------
;; Inline JSON from aeson ;; Inline JSON from aeson
@ -63,8 +65,8 @@
(quasiquote (quasiquote
(quoter) @_name (quoter) @_name
(#eq? @_name "aesonQQ") (#eq? @_name "aesonQQ")
((quasiquote_body) @json) ((quasiquote_body) @injection.content)
) (#set! injection.language "json"))
;; ----------------------------------------------------------------------------- ;; -----------------------------------------------------------------------------
@ -72,14 +74,12 @@
; postgresql-simple ; postgresql-simple
(quasiquote (quasiquote
(quoter) @_name (quoter) @injection.language
(#eq? @_name "sql") (#eq? @injection.language "sql")
((quasiquote_body) @sql) ((quasiquote_body) @injection.content))
)
; persistent
(quasiquote (quasiquote
(quoter) @_name (quoter) @_name
(#any-of? @_name "persistUpperCase" "persistLowerCase" "persistWith") (#any-of? @_name "persistUpperCase" "persistLowerCase" "persistWith")
((quasiquote_body) @haskell_persistent) ((quasiquote_body) @injection.content)
) (#set! injection.language "haskell_persistent"))

View file

@ -1,7 +1,7 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))
(heredoc_template (heredoc_template
(template_literal) @content (template_literal) @injection.content
(heredoc_identifier) @language (heredoc_identifier) @injection.language
(#set! "language" @language) (#downcase! @injection.language))
(#downcase! "language"))

View file

@ -2,10 +2,15 @@
(directive [ (directive [
(expression_value) (expression_value)
(partial_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 ; 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 ; HEEx comments
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,6 +1,15 @@
((preproc_def (preproc_arg) @hlsl) ((preproc_def
(#lua-match? @hlsl "\n")) (preproc_arg) @injection.content)
(preproc_function_def (preproc_arg) @hlsl) (#lua-match? @injection.content "\n")
(preproc_call (preproc_arg) @hlsl) (#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"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -3,8 +3,10 @@
(element (element
(start_tag (start_tag
(tag_name) @_py_script) (tag_name) @_py_script)
(text) @python (text) @injection.content
(#any-of? @_py_script "py-script" "py-repl")) (#any-of? @_py_script "py-script" "py-repl")
(#set! injection.language "python")
(#set! injection.include-children))
(script_element (script_element
(start_tag (start_tag
@ -12,13 +14,17 @@
(attribute_name) @_attr (attribute_name) @_attr
(quoted_attribute_value (quoted_attribute_value
(attribute_value) @_type))) (attribute_value) @_type)))
(raw_text) @python (raw_text) @injection.content
(#eq? @_attr "type") (#eq? @_attr "type")
; not adding type="py" here as it's handled by html_tags ; 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 (element
(start_tag (start_tag
(tag_name) @_py_config) (tag_name) @_py_config)
(text) @toml (text) @injection.content
(#eq? @_py_config "py-config")) (#eq? @_py_config "py-config")
(#set! injection.language "toml")
(#set! injection.include-children))

View file

@ -2,73 +2,84 @@
; <style blocking> ...</style> ; <style blocking> ...</style>
; Add "lang" to predicate check so that vue/svelte can inherit this ; Add "lang" to predicate check so that vue/svelte can inherit this
; without having this element being captured twice ; without having this element being captured twice
( ((style_element
(style_element
(start_tag) @_no_type_lang (start_tag) @_no_type_lang
(#not-lua-match? @_no_type_lang "%slang%s*=") (raw_text) @injection.content)
(#not-lua-match? @_no_type_lang "%stype%s*=") (#not-lua-match? @_no_type_lang "%slang%s*=")
(raw_text) @css)) (#not-lua-match? @_no_type_lang "%stype%s*=")
(#set! injection.language "css")
(#set! injection.include-children))
( ((style_element
(style_element (start_tag
(start_tag (attribute
(attribute (attribute_name) @_type
(attribute_name) @_type (quoted_attribute_value (attribute_value) @_css)))
(quoted_attribute_value (attribute_value) @_css))) (raw_text) @injection.content)
(raw_text) @css) (#eq? @_type "type")
(#eq? @_type "type") (#eq? @_css "text/css")
(#eq? @_css "text/css") (#set! injection.language "css")
) (#set! injection.include-children))
; <script>...</script> ; <script>...</script>
; <script defer>...</script> ; <script defer>...</script>
( ((script_element
(script_element (start_tag) @_no_type_lang
(start_tag) @_no_type_lang (raw_text) @injection.content)
(#not-lua-match? @_no_type_lang "%slang%s*=") (#not-lua-match? @_no_type_lang "%slang%s*=")
(#not-lua-match? @_no_type_lang "%stype%s*=") (#not-lua-match? @_no_type_lang "%stype%s*=")
(raw_text) @javascript)) (#set! injection.language "javascript")
(#set! injection.include-children))
; <script type="mimetype-or-well-known-script-type"> ; <script type="mimetype-or-well-known-script-type">
(script_element (script_element
(start_tag (start_tag
((attribute ((attribute
(attribute_name) @_attr (#eq? @_attr "type") (attribute_name) @_attr (#eq? @_attr "type")
(quoted_attribute_value (attribute_value) @_type)))) (quoted_attribute_value (attribute_value) @_type))))
(raw_text) @content (#set-lang-from-mimetype! @_type)) (raw_text) @injection.content (#set-lang-from-mimetype! @_type)
(#set! injection.include-children))
; <a style="/* css */"> ; <a style="/* css */">
((attribute ((attribute
(attribute_name) @_attr (attribute_name) @_attr
(quoted_attribute_value (attribute_value) @css)) (quoted_attribute_value (attribute_value) @injection.content))
(#eq? @_attr "style")) (#eq? @_attr "style")
(#set! injection.language "css")
(#set! injection.include-children))
; lit-html style template interpolation ; lit-html style template interpolation
; <a @click=${e => console.log(e)}> ; <a @click=${e => console.log(e)}>
; <a @click="${e => console.log(e)}"> ; <a @click="${e => console.log(e)}">
((attribute ((attribute
(quoted_attribute_value (attribute_value) @javascript)) (quoted_attribute_value (attribute_value) @injection.content))
(#lua-match? @javascript "%${") (#lua-match? @injection.content "%${")
(#offset! @javascript 0 2 0 -1)) (#offset! @injection.content 0 2 0 -1)
((attribute (#set! injection.language "javascript")
(attribute_value) @javascript) (#set! injection.include-children))
(#lua-match? @javascript "%${")
(#offset! @javascript 0 2 0 -2))
(comment) @comment ((attribute
(attribute_value) @injection.content)
(#lua-match? @injection.content "%${")
(#offset! @injection.content 0 2 0 -2)
(#set! injection.language "javascript")
(#set! injection.include-children))
; <input pattern="[0-9]"> or <input pattern=[0-9]> ; <input pattern="[0-9]"> or <input pattern=[0-9]>
(element (_ (element (_
(tag_name) @_tagname (#eq? @_tagname "input") (tag_name) @_tagname (#eq? @_tagname "input")
((attribute ((attribute
(attribute_name) @_attr [ (attribute_name) @_attr [
(quoted_attribute_value (attribute_value) @regex) (quoted_attribute_value (attribute_value) @injection.content)
(attribute_value) @regex (attribute_value) @injection.content
] (#eq? @_attr "pattern"))) ] (#eq? @_attr "pattern")))
)) (#set! injection.language "regex")
(#set! injection.include-children)))
; <input type="checkbox" onchange="this.closest('form').elements.output.value = this.checked"> ; <input type="checkbox" onchange="this.closest('form').elements.output.value = this.checked">
(attribute (attribute
(attribute_name) @_name (attribute_name) @_name
(#lua-match? @_name "^on[a-z]+$") (#lua-match? @_name "^on[a-z]+$")
(quoted_attribute_value (attribute_value) @javascript)) (quoted_attribute_value (attribute_value) @injection.content)
(#set! injection.language "javascript")
(#set! injection.include-children))

View file

@ -1 +1,3 @@
(content) @html @combined ((content) @injection.content
(#set! injection.language "html")
(#set! injection.combined))

View file

@ -1,7 +1,11 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))
(json_body) @json ((json_body) @injection.content
(#set! injection.language "json"))
; (xml_body) @xml ; ((xml_body) @injection.content
; (#set! injection.language "xml"))
; (graphql_body) @graphql Not used as of now.. ; ((graphql_body) @injection.content
; (#set! injection.language "graphql")) ; Not used as of now..

View file

@ -1,7 +1,11 @@
; injections.scm ; injections.scm
(json_value) @json ((json_value) @injection.content
(xml) @html (#set! injection.language "json"))
((xml) @injection.content
(#set! injection.language "html"))
(multiline_string (multiline_string
(multiline_string_type) @language (multiline_string_type) @_lang
(multiline_string_content) @content) (multiline_string_content) @injection.content
(#inject-language! @_lang))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,4 +1,5 @@
[ ([
(block_comment) (block_comment)
(line_comment) (line_comment)
] @comment ] @injection.content
(#set! injection.language "comment"))

View file

@ -1,4 +1,4 @@
(comment) @comment ((comment) @injection.content (#set! injection.language "comment"))
; test(val) ; test(val)
(query (query
@ -12,7 +12,10 @@
"splits" "splits"
"sub" "sub"
"gsub")) "gsub"))
(args . (query (string) @regex))) (args .
(query
(string) @injection.content
(#set! injection.language "regex"))))
; test(regex; flags) ; test(regex; flags)
@ -28,4 +31,6 @@
"sub" "sub"
"gsub")) "gsub"))
(args . (args (args . (args
(query (string) @regex)))) (query
(string) @injection.content
(#set! injection.language "regex")))))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -3,6 +3,7 @@
(jsx_opening_element (jsx_opening_element
(identifier) @_name (#eq? @_name "style") (identifier) @_name (#eq? @_name "style")
(jsx_attribute) @_attr (#eq? @_attr "jsx")) (jsx_attribute) @_attr (#eq? @_attr "jsx"))
(jsx_expression (template_string) @css (jsx_expression
(#offset! @css 0 1 0 -1)) ((template_string) @injection.content
) (#set! injection.language "css"))
(#offset! @injection.content 0 1 0 -1)))

View file

@ -1,5 +1,5 @@
;; Inject markdown in docstrings ;; Inject markdown in docstrings
((string_literal) @markdown ((string_literal) @injection.content
. [ . [
(module_definition) (module_definition)
(abstract_definition) (abstract_definition)
@ -9,15 +9,18 @@
(assignment) (assignment)
(const_statement) (const_statement)
] ]
(#lua-match? @markdown "^\"\"\"") (#lua-match? @injection.content "^\"\"\"")
(#offset! @markdown 0 3 0 -3)) (#set! injection.language "markdown")
(#offset! @injection.content 0 3 0 -3))
[ ([
(line_comment) (line_comment)
(block_comment) (block_comment)
] @comment ] @injection.content
(#set! injection.language "comment"))
((prefixed_string_literal ((prefixed_string_literal
prefix: (identifier) @_prefix) @regex prefix: (identifier) @_prefix) @injection.content
(#eq? @_prefix "r") (#eq? @_prefix "r")
(#offset! @regex 0 2 0 -1)) (#set! injection.language "regex")
(#offset! @injection.content 0 2 0 -1))

View file

@ -1,4 +1,5 @@
[ ([
(single_line_comment) (single_line_comment)
(multi_line_comment) (multi_line_comment)
] @comment ] @injection.content
(#set! injection.language "comment"))

View file

@ -1,35 +1,36 @@
[ ([
(line_comment) (line_comment)
(multiline_comment) (multiline_comment)
] @comment ] @injection.content
(#set! injection.language "comment"))
; There are 3 ways to define a regex ; There are 3 ways to define a regex
; - "[abc]?".toRegex() ; - "[abc]?".toRegex()
(call_expression (call_expression
(navigation_expression (navigation_expression
((string_literal) @regex) ((string_literal) @injection.content (#set! injection.language "regex"))
(navigation_suffix (navigation_suffix
((simple_identifier) @_function ((simple_identifier) @_function
(#eq? @_function "toRegex"))))) (#eq? @_function "toRegex")))))
; - Regex("[abc]?") ; - Regex("[abc]?")
(call_expression (call_expression
((simple_identifier) @_function ((simple_identifier) @_function
(#eq? @_function "Regex")) (#eq? @_function "Regex"))
(call_suffix (call_suffix
(value_arguments (value_arguments
(value_argument (value_argument
(string_literal) @regex)))) (string_literal) @injection.content (#set! injection.language "regex")))))
; - Regex.fromLiteral("[abc]?") ; - Regex.fromLiteral("[abc]?")
(call_expression (call_expression
(navigation_expression (navigation_expression
((simple_identifier) @_class ((simple_identifier) @_class
(#eq? @_class "Regex")) (#eq? @_class "Regex"))
(navigation_suffix (navigation_suffix
((simple_identifier) @_function ((simple_identifier) @_function
(#eq? @_function "fromLiteral")))) (#eq? @_function "fromLiteral"))))
(call_suffix (call_suffix
(value_arguments (value_arguments
(value_argument (value_argument
(string_literal) @regex)))) (string_literal) @injection.content (#set! injection.language "regex")))))

View file

@ -1,9 +1,11 @@
[ ([
(normal_action) (normal_action)
(failible_action) (failible_action)
] @rust ] @injection.content
(#set! injection.language "rust"))
(use) @rust ((use) @injection.content (#set! injection.language "rust"))
((regex_literal) @regex ((regex_literal) @injection.content
(#offset! @regex 0 2 0 -1)) (#set! injection.language "regex")
(#offset! @injection.content 0 2 0 -1))

View file

@ -1,22 +1,25 @@
[ ([
(line_comment) (line_comment)
(block_comment) (block_comment)
(comment_environment) (comment_environment)
] @comment ] @injection.content
(#set! injection.language "comment"))
(pycode_environment (pycode_environment
code: (source_code) @python code:
) (source_code) @injection.content
(#set! injection.language "python"))
(minted_environment (minted_environment
(begin (begin
language: (curly_group_text language: (curly_group_text
(text) @language)) (text) @injection.language))
(source_code) @content) (source_code) @injection.content)
((generic_environment ((generic_environment
(begin (begin
name: (curly_group_text name: (curly_group_text
(text) @_env))) @c (text) @_env))) @injection.content
(#set! injection.language "c")
(#any-of? @_env "asy" "asydef")) (#any-of? @_env "asy" "asydef"))

View file

@ -1,2 +1,5 @@
(comment) @comment ((comment) @injection.content
(note) @comment (#set! injection.language "comment"))
((note) @injection.content
(#set! injection.language "comment"))

View file

@ -243,5 +243,7 @@
(string) @string (string) @string
(escape_sequence) @string.escape
;; Error ;; Error
(ERROR) @error (ERROR) @error

View file

@ -3,57 +3,65 @@
(identifier) @_cdef_identifier (identifier) @_cdef_identifier
(_ _ (identifier) @_cdef_identifier) (_ _ (identifier) @_cdef_identifier)
] ]
arguments: (arguments (string content: _ @c))) arguments:
(arguments
(string content: _ @injection.content)))
(#set! injection.language "c")
(#eq? @_cdef_identifier "cdef")) (#eq? @_cdef_identifier "cdef"))
((function_call ((function_call
name: (_) @_vimcmd_identifier name: (_) @_vimcmd_identifier
arguments: (arguments . (string content: _ @vim))) arguments: (arguments (string content: _ @injection.content)))
(#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_exec" "vim.api.nvim_exec2")) (#set! injection.language "vim")
(#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_command" "vim.api.nvim_exec2"))
((function_call ((function_call
name: (_) @_vimcmd_identifier name: (_) @_vimcmd_identifier
arguments: (arguments (string content: _ @query) .)) arguments: (arguments (string content: _ @injection.content) .))
(#any-of? @_vimcmd_identifier "vim.treesitter.query.set" "vim.treesitter.query.parse_query" "vim.treesitter.query.parse")) (#set! injection.language "query")
(#any-of? @_vimcmd_identifier "vim.treesitter.query.set" "vim.treesitter.query.parse"))
; vim.rcprequest(123, "nvim_exec_lua", "return vim.api.nvim_buf_get_lines(0, 0, -1, false)", false)
((function_call ((function_call
name: (_) @_vimcmd_identifier name: (_) @_vimcmd_identifier
arguments: (arguments . (_) . (string content: _ @_method) . (string content: _ @lua))) arguments: (arguments . (_) . (string content: _ @_method) . (string content: _ @injection.content)))
(#any-of? @_vimcmd_identifier "vim.rpcrequest" "vim.rpcnotify") (#any-of? @_vimcmd_identifier "vim.rpcrequest" "vim.rpcnotify")
(#eq? @_method "nvim_exec_lua")) (#eq? @_method "nvim_exec_lua")
(#set! injection.language "lua"))
; highlight string as query if starts with `;; query` ;; highlight string as query if starts with `;; query`
(string content: _ @query (#lua-match? @query "^%s*;+%s?query")) (string content: _ @injection.content
(#lua-match? @injection.content "^%s*;+%s?query")
(#set! injection.language "query"))
((comment) @luadoc ((comment) @injection.content
(#lua-match? @luadoc "[-][-][-][%s]*@") (#lua-match? @injection.content "[-][-][-][%s]*@")
(#offset! @luadoc 0 3 0 0)) (#set! injection.language "luadoc")
(#offset! @injection.content 0 3 0 0))
; string.match("123", "%d+") ; string.match("123", "%d+")
(function_call (function_call
(dot_index_expression (dot_index_expression
field: (identifier) @_method field: (identifier) @_method
(#any-of? @_method "find" "match")) (#any-of? @_method "find" "match"))
arguments: (arguments (_) . (string content: _ @luap))) arguments: (arguments (_) . (string content: _ @injection.content (#set! injection.language "luap"))))
(function_call (function_call
(dot_index_expression (dot_index_expression
field: (identifier) @_method field: (identifier) @_method
(#any-of? @_method "gmatch" "gsub")) (#any-of? @_method "gmatch" "gsub"))
arguments: (arguments (_) (string content: _ @luap))) arguments: (arguments (_) (string content: _ @injection.content (#set! injection.language "luap"))))
; ("123"):match("%d+") ; ("123"):match("%d+")
(function_call (function_call
(method_index_expression (method_index_expression
method: (identifier) @_method method: (identifier) @_method
(#any-of? @_method "find" "match")) (#any-of? @_method "find" "match"))
arguments: (arguments . (string content: _ @luap))) arguments: (arguments . (string content: _ @injection.content (#set! injection.language "luap"))))
(function_call (function_call
(method_index_expression (method_index_expression
method: (identifier) @_method method: (identifier) @_method
(#any-of? @_method "gmatch" "gsub")) (#any-of? @_method "gmatch" "gsub"))
arguments: (arguments (string content: _ @luap))) arguments: (arguments (string content: _ @injection.content (#set! injection.language "luap"))))
(comment) @comment ((comment) @injection.content (#set! injection.language "comment"))

View file

@ -3,37 +3,44 @@
(identifier) @_cdef_identifier (identifier) @_cdef_identifier
(_ _ (identifier) @_cdef_identifier) (_ _ (identifier) @_cdef_identifier)
] ]
arguments: (arguments (string content: _ @c))) arguments: (arguments (string content: _ @injection.content)))
(#eq? @_cdef_identifier "cdef")) (#eq? @_cdef_identifier "cdef")
(#set! injection.language "c"))
((comment) @luadoc ((comment) @injection.content
(#lua-match? @luadoc "[-][-][-][%s]*@") (#lua-match? @injection.content "[-][-][-][%s]*@")
(#offset! @luadoc 0 3 0 0)) (#offset! @injection.content 0 3 0 0)
(#set! injection.language "luadoc"))
; string.match("123", "%d+") ; string.match("123", "%d+")
(function_call (function_call
(dot_index_expression (dot_index_expression
field: (identifier) @_method field: (identifier) @_method
(#any-of? @_method "find" "format" "match")) (#any-of? @_method "find" "format" "match"))
arguments: (arguments (_) . (string content: _ @luap))) arguments: (arguments (_) . (string content: _ @injection.content))
(#set! injection.language "luap"))
(function_call (function_call
(dot_index_expression (dot_index_expression
field: (identifier) @_method field: (identifier) @_method
(#any-of? @_method "gmatch" "gsub")) (#any-of? @_method "gmatch" "gsub"))
arguments: (arguments (_) (string content: _ @luap))) arguments: (arguments (_) (string content: _ @injection.content))
(#set! injection.language "luap"))
; ("123"):match("%d+") ; ("123"):match("%d+")
(function_call (function_call
(method_index_expression (method_index_expression
method: (identifier) @_method method: (identifier) @_method
(#any-of? @_method "find" "format" "match")) (#any-of? @_method "find" "format" "match"))
arguments: (arguments . (string content: _ @luap))) arguments: (arguments . (string content: _ @injection.content))
(#set! injection.language "luap"))
(function_call (function_call
(method_index_expression (method_index_expression
method: (identifier) @_method method: (identifier) @_method
(#any-of? @_method "gmatch" "gsub")) (#any-of? @_method "gmatch" "gsub"))
arguments: (arguments (string content: _ @luap))) arguments: (arguments (string content: _ @injection.content))
(#set! injection.language "luap"))
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,4 +1,7 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))
(shell_text) @bash ((shell_text) @injection.content
(shell_command) @bash (#set! injection.language "bash"))
((shell_command) @injection.content
(#set! injection.language "bash"))

View file

@ -1,17 +1,26 @@
(fenced_code_block (fenced_code_block
(info_string (info_string
(language) @_lang) (language) @_lang)
(code_fence_content) (code_fence_content) @injection.content
@content (#set-lang-from-info-string! @_lang))
(#set-lang-from-info-string! @_lang)
(#exclude_children! @content))
((html_block) @html @combined) ((html_block) @injection.content
(#set! injection.language "html")
(#set! injection.combined)
(#set! injection.include-children))
((minus_metadata) @yaml (#offset! @yaml 1 0 -1 0)) ((minus_metadata) @injection.content
((plus_metadata) @toml (#offset! @toml 1 0 -1 0)) (#set! injection.language "yaml")
(#offset! @injection.content 1 0 -1 0)
(#set! injection.include-children))
((plus_metadata) @injection.content
(#set! injection.language "toml")
(#offset! @injection.content 1 0 -1 0)
(#set! injection.include-children))
([ ([
(inline) (inline)
(pipe_table_cell) (pipe_table_cell)
] @markdown_inline (#exclude_children! @markdown_inline)) ] @injection.content
(#set! injection.language "markdown_inline"))

View file

@ -1,2 +1,8 @@
((html_tag) @html @combined) ((html_tag) @injection.content
((latex_block) @latex) (#set! injection.language "html")
(#set! injection.combined)
(#set! injection.include-children))
((latex_block) @injection.content
(#set! injection.language "latex")
(#set! injection.include-children))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(ocaml) @ocaml ((ocaml) @injection.content
(#set! injection.language "ocaml"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,19 +1,24 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))
(apply_expression (apply_expression
function: (_) @_func function: (_) @_func
argument: [ argument: [
(string_expression (string_fragment) @regex) (string_expression
(indented_string_expression (string_fragment) @regex) ((string_fragment) @injection.content (#set! injection.language "regex")))
(indented_string_expression
((string_fragment) @injection.content (#set! injection.language "regex")))
] ]
(#match? @_func "(^|\\.)match$")) (#match? @_func "(^|\\.)match$")
@combined (#set! injection.combined))
(binding (binding
attrpath: (attrpath (identifier) @_path) attrpath: (attrpath (identifier) @_path)
expression: [ expression: [
(string_expression (string_fragment) @bash) (string_expression
(indented_string_expression (string_fragment) @bash) ((string_fragment) @injection.content (#set! injection.language "bash")))
(indented_string_expression
((string_fragment) @injection.content (#set! injection.language "bash")))
] ]
(#match? @_path "(^\\w+(Phase|Hook)|(pre|post)[A-Z]\\w+|script)$")) (#match? @_path "(^\\w+(Phase|Hook)|(pre|post)[A-Z]\\w+|script)$"))
@ -22,87 +27,105 @@
argument: (_ (_)* (_ (_)* (binding argument: (_ (_)* (_ (_)* (binding
attrpath: (attrpath (identifier) @_path) attrpath: (attrpath (identifier) @_path)
expression: [ expression: [
(string_expression (string_fragment) @bash) (string_expression
(indented_string_expression (string_fragment) @bash) ((string_fragment) @injection.content (#set! injection.language "bash")))
(indented_string_expression
((string_fragment) @injection.content (#set! injection.language "bash")))
]))) ])))
(#match? @_func "(^|\\.)writeShellApplication$") (#match? @_func "(^|\\.)writeShellApplication$")
(#match? @_path "^text$")) (#match? @_path "^text$")
@combined (#set! injection.combined))
(apply_expression (apply_expression
function: (apply_expression function: (apply_expression
function: (apply_expression function: (_) @_func)) function: (apply_expression function: (_) @_func))
argument: [ argument: [
(string_expression (string_fragment) @bash) (string_expression
(indented_string_expression (string_fragment) @bash) ((string_fragment) @injection.content (#set! injection.language "bash")))
(indented_string_expression
((string_fragment) @injection.content (#set! injection.language "bash")))
] ]
(#match? @_func "(^|\\.)runCommand((No)?CC)?(Local)?$")) (#match? @_func "(^|\\.)runCommand((No)?CC)?(Local)?$")
@combined (#set! injection.combined))
((apply_expression ((apply_expression
function: (apply_expression function: (_) @_func) function: (apply_expression function: (_) @_func)
argument: [ argument: [
(string_expression (string_fragment) @bash) (string_expression
(indented_string_expression (string_fragment) @bash) ((string_fragment) @injection.content (#set! injection.language "bash")))
(indented_string_expression
((string_fragment) @injection.content (#set! injection.language "bash")))
]) ])
(#match? @_func "(^|\\.)write(Bash|Dash|ShellScript)(Bin)?$")) (#match? @_func "(^|\\.)write(Bash|Dash|ShellScript)(Bin)?$")
@combined (#set! injection.combined))
((apply_expression ((apply_expression
function: (apply_expression function: (_) @_func) function: (apply_expression function: (_) @_func)
argument: [ argument: [
(string_expression (string_fragment) @fish) (string_expression
(indented_string_expression (string_fragment) @fish) ((string_fragment) @injection.content (#set! injection.language "fish")))
(indented_string_expression
((string_fragment) @injection.content (#set! injection.language "fish")))
]) ])
(#match? @_func "(^|\\.)writeFish(Bin)?$")) (#match? @_func "(^|\\.)writeFish(Bin)?$")
@combined (#set! injection.combined))
((apply_expression ((apply_expression
function: (apply_expression function: (apply_expression
function: (apply_expression function: (_) @_func)) function: (apply_expression function: (_) @_func))
argument: [ argument: [
(string_expression (string_fragment) @haskell) (string_expression
(indented_string_expression (string_fragment) @haskell) ((string_fragment) @injection.content (#set! injection.language "haskell")))
(indented_string_expression
((string_fragment) @injection.content (#set! injection.language "haskell")))
]) ])
(#match? @_func "(^|\\.)writeHaskell(Bin)?$")) (#match? @_func "(^|\\.)writeHaskell(Bin)?$")
@combined (#set! injection.combined))
((apply_expression ((apply_expression
function: (apply_expression function: (apply_expression
function: (apply_expression function: (_) @_func)) function: (apply_expression function: (_) @_func))
argument: [ argument: [
(string_expression (string_fragment) @javascript) (string_expression
(indented_string_expression (string_fragment) @javascript) ((string_fragment) @injection.content (#set! injection.language "javascript")))
(indented_string_expression
((string_fragment) @injection.content (#set! injection.language "javascript")))
]) ])
(#match? @_func "(^|\\.)writeJS(Bin)?$")) (#match? @_func "(^|\\.)writeJS(Bin)?$")
@combined (#set! injection.combined))
((apply_expression ((apply_expression
function: (apply_expression function: (apply_expression
function: (apply_expression function: (_) @_func)) function: (apply_expression function: (_) @_func))
argument: [ argument: [
(string_expression (string_fragment) @perl) (string_expression
(indented_string_expression (string_fragment) @perl) ((string_fragment) @injection.content (#set! injection.language "perl")))
(indented_string_expression
((string_fragment) @injection.content (#set! injection.language "perl")))
]) ])
(#match? @_func "(^|\\.)writePerl(Bin)?$")) (#match? @_func "(^|\\.)writePerl(Bin)?$")
@combined (#set! injection.combined))
((apply_expression ((apply_expression
function: (apply_expression function: (apply_expression
function: (apply_expression function: (_) @_func)) function: (apply_expression function: (_) @_func))
argument: [ argument: [
(string_expression (string_fragment) @python) (string_expression
(indented_string_expression (string_fragment) @python) ((string_fragment) @injection.content (#set! injection.language "python")))
(indented_string_expression
((string_fragment) @injection.content (#set! injection.language "python")))
]) ])
(#match? @_func "(^|\\.)write(PyPy|Python)[23](Bin)?$")) (#match? @_func "(^|\\.)write(PyPy|Python)[23](Bin)?$")
@combined (#set! injection.combined))
((apply_expression ((apply_expression
function: (apply_expression function: (apply_expression
function: (apply_expression function: (_) @_func)) function: (apply_expression function: (_) @_func))
argument: [ argument: [
(string_expression (string_fragment) @rust) (string_expression
(indented_string_expression (string_fragment) @rust) ((string_fragment) @injection.content (#set! injection.language "rust")))
(indented_string_expression
((string_fragment) @injection.content (#set! injection.language "rust")))
]) ])
(#match? @_func "(^|\\.)writeRust(Bin)?$")) (#match? @_func "(^|\\.)writeRust(Bin)?$")
@combined (#set! injection.combined))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,3 +1,5 @@
(ocaml) @ocaml ((ocaml) @injection.content
(#set! injection.language "ocaml"))
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,4 +1,7 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))
; There is no parser for assembly language yet. Add an injection here when we ; There is no parser for assembly language yet. Add an injection here when we
; have a parser. ; have a parser.
; (asmBody) @asm ; ((asmBody) @injection.content
; (#set! injection.language "asm"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comments) @comment ((comments) @injection.content
(#set! injection.language "comment"))

View file

@ -1,20 +1,34 @@
(text) @html @combined ((text) @injection.content
(#set! injection.language "html")
(#set! injection.combined))
(comment) @phpdoc ((comment) @injection.content
(#set! injection.language "phpdoc"))
;; regex ;; regex
((function_call_expression ((function_call_expression
function: (_) @_preg_func_identifier function: (_) @_preg_func_identifier
arguments: (arguments . (argument (_ (string_value) @regex)))) arguments:
(arguments .
(argument
(_ (string_value) @injection.content))))
(#set! injection.language "regex")
(#lua-match? @_preg_func_identifier "^preg_")) (#lua-match? @_preg_func_identifier "^preg_"))
;; bash ;; bash
((function_call_expression ((function_call_expression
function: (_) @_shell_func_identifier function: (_) @_shell_func_identifier
arguments: (arguments . (argument (_ (string_value) @bash)))) arguments:
(arguments .
(argument
(_ (string_value) @injection.content))))
(#set! injection.language "bash")
(#any-of? @_shell_func_identifier "shell_exec" "escapeshellarg" (#any-of? @_shell_func_identifier "shell_exec" "escapeshellarg"
"escapeshellcmd" "exec" "passthru" "proc_open" "shell_exec" "system")) "escapeshellcmd" "exec" "passthru" "proc_open" "shell_exec" "system"))
((expression_statement (shell_command_expression (string_value) @bash))) (expression_statement
(shell_command_expression
(string_value) @injection.content)
(#set! injection.language "bash"))

View file

@ -1,10 +1,15 @@
[ (line_comment) (block_comment) ] @comment ([
(line_comment)
(block_comment)
] @injection.content
(#set! injection.language "comment"))
((code_block ((code_block
(code_block_language) @_language (code_block_language) @_language
(code_block_body) @c) (code_block_body) @injection.content)
(#eq? @_language "c-sdk")) (#eq? @_language "c-sdk")
(#set! injection.language "c"))
(code_block (code_block
(code_block_language) @language (code_block_language) @injection.language
(code_block_body) @content) (code_block_body) @injection.content)

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,4 +1,5 @@
[ ([
(line_comment) (line_comment)
(block_comment) (block_comment)
] @comment ] @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,3 @@
((label_value) @regex (#offset! @regex 0 1 0 -1)) ((label_value) @injection.content
(#set! injection.language "regex")
(#offset! @injection.content 0 1 0 -1))

View file

@ -1,13 +1,13 @@
( ((s_string) @injection.content
(s_string) @sql (#set! injection.language "sql")
(#offset! @sql 0 2 0 -1) (#offset! @injection.content 0 2 0 -1))
)
(from_text (from_text
(keyword_from_text) (keyword_from_text)
(keyword_json) (keyword_json)
(literal) @json (literal) @injection.content
(#offset! @json 0 3 0 -3) (#set! injection.language "json")
) (#offset! @injection.content 0 3 0 -3))
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,7 +1,8 @@
(javascript) @javascript ((javascript) @injection.content
(#set! injection.language "javascript"))
( ((attribute_name) @_attribute_name
(attribute_name) @_attribute_name (quoted_attribute_value
(quoted_attribute_value (attribute_value ) @javascript) (attribute_value) @injection.content
(#match? @_attribute_name "^(:|v-bind|v-|\\@)") (#set! injection.language "javascript"))
) (#match? @_attribute_name "^(:|v-bind|v-|\\@)"))

View file

@ -1,4 +1,6 @@
((regex) @regex ((regex) @injection.content
(#offset! @regex 0 1 0 -1)) (#set! injection.language "regex")
(#offset! @injection.content 0 1 0 -1))
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,8 +1,10 @@
((call ((call
function: (attribute function: (attribute
object: (identifier) @_re) object: (identifier) @_re)
arguments: (argument_list (string) @regex)) arguments: (argument_list (string) @injection.content))
(#eq? @_re "re") (#eq? @_re "re")
(#lua-match? @regex "^r.*")) (#lua-match? @injection.content "^r.*")
(#set! injection.language "regex"))
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,5 +1,6 @@
[ ([
(line_comment) (line_comment)
(block_comment) (block_comment)
(qldoc) (qldoc)
] @comment ] @injection.content
(#set! injection.language "comment"))

View file

@ -1 +1,2 @@
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

View file

@ -1,13 +1,16 @@
((predicate ((predicate
name: (identifier) @_name name: (identifier) @_name
parameters: (parameters (string) @regex)) parameters: (parameters (string) @injection.content))
(#match? @_name "^#?(not-)?(match|vim-match)$") (#match? @_name "^#?(not-)?(match|vim-match)$")
(#offset! @regex 0 1 0 -1)) (#set! injection.language "regex")
(#offset! @injection.content 0 1 0 -1))
((predicate ((predicate
name: (identifier) @_name name: (identifier) @_name
parameters: (parameters (string) @luap)) parameters: (parameters (string) @injection.content))
(#match? @_name "^#?(not-)?lua-match$") (#match? @_name "^#?(not-)?lua-match$")
(#offset! @luap 0 1 0 -1)) (#set! injection.language "luap")
(#offset! @injection.content 0 1 0 -1))
(comment) @comment ((comment) @injection.content
(#set! injection.language "comment"))

Some files were not shown because too many files have changed in this diff Show more