From 63586ff2e452832e3e1250d1e9cf3938d377d832 Mon Sep 17 00:00:00 2001 From: Kaan Kuscu Date: Mon, 15 Sep 2025 18:51:03 +0300 Subject: [PATCH] Add new injections for Go (#37605) support for injecting sql, json, yaml, xml, html, css, js, lua and csv value if you use `/* lang */` before string literals, highlights them **Example:** ```go const sqlQuery = /* sql */ "SELECT * FROM users;" // highlights as SQL code ``` Screenshot 2025-09-05 at 06 17 49 Closes #ISSUE Release Notes: - Go: Added support for injecting sql, json, yaml, xml, html, css, js, lua and csv language highlights into string literals, when they are prefixed with `/* lang */` **Example:** ```go const sqlQuery = /* sql */ "SELECT * FROM users;" // Will be highlighted as SQL code ``` --- crates/languages/src/go/injections.scm | 363 ++++++++++++++++++++++++- 1 file changed, 362 insertions(+), 1 deletion(-) diff --git a/crates/languages/src/go/injections.scm b/crates/languages/src/go/injections.scm index 2be0844d97b7f9f16e8832b5b8aebbb0d0043e5d..7bb68d760e1a556ef93a9477dc578c88d9350dcb 100644 --- a/crates/languages/src/go/injections.scm +++ b/crates/languages/src/go/injections.scm @@ -10,4 +10,365 @@ (raw_string_literal) (interpreted_string_literal) ] @injection.content - (#set! injection.language "regex"))) + (#set! injection.language "regex") + )) + +; INJECT SQL +( + [ + ; var, const or short declaration of raw or interpreted string literal + ((comment) @comment + . + (expression_list + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a literal element (to struct field eg.) + ((comment) @comment + . + (literal_element + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a function parameter + ((comment) @comment + . + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content) + ] + + (#match? @comment "^\\/\\*\\s*sql\\s*\\*\\/") ; /* sql */ or /*sql*/ + (#set! injection.language "sql") +) + +; INJECT JSON +( + [ + ; var, const or short declaration of raw or interpreted string literal + ((comment) @comment + . + (expression_list + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a literal element (to struct field eg.) + ((comment) @comment + . + (literal_element + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a function parameter + ((comment) @comment + . + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content) + ] + + (#match? @comment "^\\/\\*\\s*json\\s*\\*\\/") ; /* json */ or /*json*/ + (#set! injection.language "json") +) + +; INJECT YAML +( + [ + ; var, const or short declaration of raw or interpreted string literal + ((comment) @comment + . + (expression_list + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a literal element (to struct field eg.) + ((comment) @comment + . + (literal_element + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a function parameter + ((comment) @comment + . + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content) + ] + + (#match? @comment "^\\/\\*\\s*yaml\\s*\\*\\/") ; /* yaml */ or /*yaml*/ + (#set! injection.language "yaml") +) + +; INJECT XML +( + [ + ; var, const or short declaration of raw or interpreted string literal + ((comment) @comment + . + (expression_list + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a literal element (to struct field eg.) + ((comment) @comment + . + (literal_element + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a function parameter + ((comment) @comment + . + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content) + ] + + (#match? @comment "^\\/\\*\\s*xml\\s*\\*\\/") ; /* xml */ or /*xml*/ + (#set! injection.language "xml") +) + +; INJECT HTML +( + [ + ; var, const or short declaration of raw or interpreted string literal + ((comment) @comment + . + (expression_list + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a literal element (to struct field eg.) + ((comment) @comment + . + (literal_element + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a function parameter + ((comment) @comment + . + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content) + ] + + (#match? @comment "^\\/\\*\\s*html\\s*\\*\\/") ; /* html */ or /*html*/ + (#set! injection.language "html") +) + +; INJECT JS +( + [ + ; var, const or short declaration of raw or interpreted string literal + ((comment) @comment + . + (expression_list + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a literal element (to struct field eg.) + ((comment) @comment + . + (literal_element + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a function parameter + ((comment) @comment + . + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content) + ] + + (#match? @comment "^\\/\\*\\s*js\\s*\\*\\/") ; /* js */ or /*js*/ + (#set! injection.language "javascript") +) + +; INJECT CSS +( + [ + ; var, const or short declaration of raw or interpreted string literal + ((comment) @comment + . + (expression_list + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a literal element (to struct field eg.) + ((comment) @comment + . + (literal_element + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a function parameter + ((comment) @comment + . + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content) + ] + + (#match? @comment "^\\/\\*\\s*css\\s*\\*\\/") ; /* css */ or /*css*/ + (#set! injection.language "css") +) + +; INJECT LUA +( + [ + ; var, const or short declaration of raw or interpreted string literal + ((comment) @comment + . + (expression_list + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a literal element (to struct field eg.) + ((comment) @comment + . + (literal_element + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a function parameter + ((comment) @comment + . + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content) + ] + + (#match? @comment "^\\/\\*\\s*lua\\s*\\*\\/") ; /* lua */ or /*lua*/ + (#set! injection.language "lua") +) + +; INJECT BASH +( + [ + ; var, const or short declaration of raw or interpreted string literal + ((comment) @comment + . + (expression_list + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a literal element (to struct field eg.) + ((comment) @comment + . + (literal_element + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a function parameter + ((comment) @comment + . + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content) + ] + + (#match? @comment "^\\/\\*\\s*bash\\s*\\*\\/") ; /* bash */ or /*bash*/ + (#set! injection.language "bash") +) + +; INJECT CSV +( + [ + ; var, const or short declaration of raw or interpreted string literal + ((comment) @comment + . + (expression_list + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a literal element (to struct field eg.) + ((comment) @comment + . + (literal_element + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + )) + + ; when passing as a function parameter + ((comment) @comment + . + [ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content) + ] + + (#match? @comment "^\\/\\*\\s*csv\\s*\\*\\/") ; /* csv */ or /*csv*/ + (#set! injection.language "csv") +)