From 3d8dd32c10419ba62035b75803238fa2a7751583 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 17 Apr 2023 13:56:38 -0700 Subject: [PATCH 1/3] Highlight sqlx's `query_scalar{,_unchecked}` macros as SQL --- runtime/queries/rust/injections.scm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/runtime/queries/rust/injections.scm b/runtime/queries/rust/injections.scm index d191a53adb4b..4c22ed1c999b 100644 --- a/runtime/queries/rust/injections.scm +++ b/runtime/queries/rust/injections.scm @@ -52,6 +52,18 @@ ) (#set! injection.language "sql")) +; Highlight SQL in `sqlx::query_scalar!()` +(macro_invocation + macro: (scoped_identifier + path: (identifier) @_sqlx (#eq? @_sqlx "sqlx") + name: (identifier) @_query (#eq? @_query "query_scalar")) + (token_tree + ; Only the first argument is SQL + . + [(string_literal) (raw_string_literal)] @injection.content + ) + (#set! injection.language "sql")) + ; Highlight SQL in `sqlx::query_unchecked!()` (macro_invocation macro: (scoped_identifier @@ -78,3 +90,15 @@ [(string_literal) (raw_string_literal)] @injection.content ) (#set! injection.language "sql")) + +; Highlight SQL in `sqlx::query_scalar_unchecked!()` +(macro_invocation + macro: (scoped_identifier + path: (identifier) @_sqlx (#eq? @_sqlx "sqlx") + name: (identifier) @_query (#eq? @_query "query_scalar_unchecked")) + (token_tree + ; Only the first argument is SQL + . + [(string_literal) (raw_string_literal)] @injection.content + ) + (#set! injection.language "sql")) From 041b116cab4030ce014773c51e457000185f544e Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 18 Apr 2023 19:05:02 -0700 Subject: [PATCH 2/3] Update injections.scm --- runtime/queries/rust/injections.scm | 59 ++--------------------------- 1 file changed, 4 insertions(+), 55 deletions(-) diff --git a/runtime/queries/rust/injections.scm b/runtime/queries/rust/injections.scm index 4c22ed1c999b..af190faab61b 100644 --- a/runtime/queries/rust/injections.scm +++ b/runtime/queries/rust/injections.scm @@ -25,11 +25,11 @@ arguments: (arguments (raw_string_literal) @injection.content) (#set! injection.language "regex")) -; Highlight SQL in `sqlx::query!()` +; Highlight SQL in `sqlx::query!()`, `sqlx::query_scalar!()`, and `sqlx::query_scalar_unchecked!()` (macro_invocation macro: (scoped_identifier path: (identifier) @_sqlx (#eq? @_sqlx "sqlx") - name: (identifier) @_query (#eq? @_query "query")) + name: (identifier) @_query (#match? @_query "^query(_scalar|_scalar_unchecked)?$")) (token_tree ; Only the first argument is SQL . @@ -37,11 +37,11 @@ ) (#set! injection.language "sql")) -; Highlight SQL in `sqlx::query_as!()` +; Highlight SQL in `sqlx::query_as!()` and `sqlx::query_as_unchecked!()` (macro_invocation macro: (scoped_identifier path: (identifier) @_sqlx (#eq? @_sqlx "sqlx") - name: (identifier) @_query_as (#eq? @_query_as "query_as")) + name: (identifier) @_query_as (#match? @_query "^query_as(_unchecked)?$")) (token_tree ; Only the second argument is SQL . @@ -51,54 +51,3 @@ [(string_literal) (raw_string_literal)] @injection.content ) (#set! injection.language "sql")) - -; Highlight SQL in `sqlx::query_scalar!()` -(macro_invocation - macro: (scoped_identifier - path: (identifier) @_sqlx (#eq? @_sqlx "sqlx") - name: (identifier) @_query (#eq? @_query "query_scalar")) - (token_tree - ; Only the first argument is SQL - . - [(string_literal) (raw_string_literal)] @injection.content - ) - (#set! injection.language "sql")) - -; Highlight SQL in `sqlx::query_unchecked!()` -(macro_invocation - macro: (scoped_identifier - path: (identifier) @_sqlx (#eq? @_sqlx "sqlx") - name: (identifier) @_query_as (#eq? @_query_as "query_unchecked")) - (token_tree - ; Only the first argument is SQL - . - [(string_literal) (raw_string_literal)] @injection.content - ) - (#set! injection.language "sql")) - -; Highlight SQL in `sqlx::query_as_unchecked!()` -(macro_invocation - macro: (scoped_identifier - path: (identifier) @_sqlx (#eq? @_sqlx "sqlx") - name: (identifier) @_query_as (#eq? @_query_as "query_as_unchecked")) - (token_tree - ; Only the second argument is SQL - . - ; Allow anything as the first argument in case the user has lower case type - ; names for some reason - (_) - [(string_literal) (raw_string_literal)] @injection.content - ) - (#set! injection.language "sql")) - -; Highlight SQL in `sqlx::query_scalar_unchecked!()` -(macro_invocation - macro: (scoped_identifier - path: (identifier) @_sqlx (#eq? @_sqlx "sqlx") - name: (identifier) @_query (#eq? @_query "query_scalar_unchecked")) - (token_tree - ; Only the first argument is SQL - . - [(string_literal) (raw_string_literal)] @injection.content - ) - (#set! injection.language "sql")) From 5ff676bff646e9241e8023f6a37226b125bd1b7a Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 18 Apr 2023 19:07:09 -0700 Subject: [PATCH 3/3] fixup copy-pasta --- runtime/queries/rust/injections.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/queries/rust/injections.scm b/runtime/queries/rust/injections.scm index af190faab61b..b29a5ad70b2b 100644 --- a/runtime/queries/rust/injections.scm +++ b/runtime/queries/rust/injections.scm @@ -41,7 +41,7 @@ (macro_invocation macro: (scoped_identifier path: (identifier) @_sqlx (#eq? @_sqlx "sqlx") - name: (identifier) @_query_as (#match? @_query "^query_as(_unchecked)?$")) + name: (identifier) @_query_as (#match? @_query_as "^query_as(_unchecked)?$")) (token_tree ; Only the second argument is SQL .