@@ -3,7 +3,7 @@ import sqlLint from 'sql-lint';
33import * as configuration from './configuration' ;
44
55export const PHP_SQL = '<<<SQL' ;
6- export const SQL_START_REGEX = / (?< token > " " " | " | ' ' ' | ' | ` ) - - \s * s q l / ;
6+ export const SQL_START_REGEX = / (?< token > r (?< hashes > # * ) ? " | " " " | " | ' ' ' | ' | ` ) - - \s * s q l / ;
77
88async function checkRange (
99 log : vscode . OutputChannel ,
@@ -60,6 +60,7 @@ export async function refreshDiagnostics(
6060 let startRangePosition = - 1 ;
6161 let sqlStringBound = '' ;
6262 let sqlStartLineIndex = - 1 ;
63+ let hashes = '' ; // For Rust raw strings
6364
6465 if (
6566 configuration . get < boolean > ( 'lintSQLFiles' ) &&
@@ -88,15 +89,26 @@ export async function refreshDiagnostics(
8889 if ( sqlStartLineIndex === - 1 ) {
8990 if ( ( match = SQL_START_REGEX . exec ( lineOfText ) ) !== null ) {
9091 startRangePosition = match . index + match . groups ! . token . length ;
91- sqlStringBound = match . groups ! . token ;
9292 sqlStartLineIndex = lineIndex ;
93+ if ( match . groups ! . hashes !== undefined ) {
94+ hashes = match . groups ! . hashes ;
95+ sqlStringBound = `"${ hashes } ` ;
96+ } else {
97+ sqlStringBound = match . groups ! . token ;
98+ }
9399 } else if ( ( phpPatternStart = lineOfText . indexOf ( PHP_SQL ) ) !== - 1 ) {
94100 startRangePosition = phpPatternStart + PHP_SQL . length ;
95101 sqlStringBound = 'SQL;' ;
96102 sqlStartLineIndex = lineIndex ;
97103 }
98- } else if ( sqlStringBound !== '' ) {
99- let endSqlIndex = lineOfText . indexOf ( sqlStringBound ) ;
104+ }
105+ if ( sqlStringBound !== '' ) {
106+ let endSqlIndex = - 1 ;
107+ if ( lineIndex === sqlStartLineIndex ) {
108+ endSqlIndex = lineOfText . indexOf ( sqlStringBound , startRangePosition ) ;
109+ } else {
110+ endSqlIndex = lineOfText . indexOf ( sqlStringBound ) ;
111+ }
100112 if ( endSqlIndex !== - 1 ) {
101113 sqlStringCnt += 1 ;
102114 const range = new vscode . Range (
@@ -109,6 +121,7 @@ export async function refreshDiagnostics(
109121 diagnostics . push ( ...subDiagnostics ) ;
110122 sqlStartLineIndex = - 1 ;
111123 sqlStringBound = '' ;
124+ hashes = '' ;
112125 }
113126 }
114127 }
0 commit comments