Skip to content

Commit

Permalink
[Go] add support for TSQL in language injections
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-hall committed Oct 25, 2023
1 parent cc2a871 commit 1f5edee
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Go/Embeddings/Go (Embedded TSQL).sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%YAML 1.2
---
name: Go (Embedded T-SQL)
scope: source.go.embedded-backtick-string.tsql
version: 2
hidden: true

extends: Packages/Go/Embeddings/Go (Embedded Backtick String).sublime-syntax

contexts:
match-raw-string:
# replaces Go.sublime-syntax#match-raw-string
- match: '`'
scope: meta.string.go string.quoted.backtick.go punctuation.definition.string.begin.go
embed: scope:source.tsql.go-embedded-backtick-string
embed_scope: meta.string.go meta.embedded.go source.sql.embedded.go
escape: '`'
escape_captures:
0: meta.string.go string.quoted.backtick.go punctuation.definition.string.end.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
%YAML 1.2
---
name: T-SQL inside Go backtick string
scope: source.tsql.go-embedded-backtick-string
version: 2
hidden: true

extends: Packages/SQL/TSQL.sublime-syntax

contexts:
prototype:
- meta_prepend: true
- include: scope:source.go#match-raw-text-content

string-escape:
- meta_prepend: true
- include: scope:source.go#match-raw-string-content

string-interpolation:
- meta_prepend: true
- include: scope:source.go#match-raw-string-content
3 changes: 3 additions & 0 deletions Go/Go.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ contexts:
- match: (?i)sql\b
scope: meta.annotation.parameters.go constant.other.language-name.go
set: scope:source.go.embedded-backtick-string.sql#match-comment-magic-language-injection-inner
- match: (?i)t-?sql\b
scope: meta.annotation.parameters.go constant.other.language-name.go
set: scope:source.go.embedded-backtick-string.tsql#match-comment-magic-language-injection-inner
- match: (?i)xml\b
scope: meta.annotation.parameters.go constant.other.language-name.go
set: scope:source.go.embedded-backtick-string.xml#match-comment-magic-language-injection-inner
Expand Down
11 changes: 11 additions & 0 deletions Go/tests/syntax_test_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -5783,6 +5783,17 @@ func lang_embedding() {
not_sql_string = `select not sql`
// ^^^^^^^^^^^^^^^^ meta.string.go string.quoted.backtick.go - source.sql
//language=t-sql
// <- comment.line.double-slash.go punctuation.definition.comment.go
//^^^^^^^^^^^^^^^ comment.line.double-slash.go
//^^^^^^^^ meta.annotation.identifier.go
// ^ meta.annotation keyword.operator.assignment.go
// ^^^^^ meta.annotation.parameters.go constant.other.language-name.go
sqlQuery = `
SELECT id
FROM ##global_temp_table;`
// ^^ punctuation.definition.variable
response := &http.Response{
StatusCode: http.StatusUnauthorized,
//language=json
Expand Down

0 comments on commit 1f5edee

Please sign in to comment.