@@ -3,7 +3,8 @@ 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 =
7+ / (?< token > r (?< hashes > # * ) ? " | " " " | " | ' ' ' | ' | ` ) - - \s * s q l / ;
78
89async function checkRange (
910 log : vscode . OutputChannel ,
@@ -60,6 +61,7 @@ export async function refreshDiagnostics(
6061 let startRangePosition = - 1 ;
6162 let sqlStringBound = '' ;
6263 let sqlStartLineIndex = - 1 ;
64+ let hashes = '' ; // For Rust raw strings
6365
6466 if (
6567 configuration . get < boolean > ( 'lintSQLFiles' ) &&
@@ -88,15 +90,29 @@ export async function refreshDiagnostics(
8890 if ( sqlStartLineIndex === - 1 ) {
8991 if ( ( match = SQL_START_REGEX . exec ( lineOfText ) ) !== null ) {
9092 startRangePosition = match . index + match . groups ! . token . length ;
91- sqlStringBound = match . groups ! . token ;
9293 sqlStartLineIndex = lineIndex ;
94+ if ( match . groups ! . hashes !== undefined ) {
95+ hashes = match . groups ! . hashes ;
96+ sqlStringBound = `"${ hashes } ` ;
97+ } else {
98+ sqlStringBound = match . groups ! . token ;
99+ }
93100 } else if ( ( phpPatternStart = lineOfText . indexOf ( PHP_SQL ) ) !== - 1 ) {
94101 startRangePosition = phpPatternStart + PHP_SQL . length ;
95102 sqlStringBound = 'SQL;' ;
96103 sqlStartLineIndex = lineIndex ;
97104 }
98- } else if ( sqlStringBound !== '' ) {
99- let endSqlIndex = lineOfText . indexOf ( sqlStringBound ) ;
105+ }
106+ if ( sqlStringBound !== '' ) {
107+ let endSqlIndex = - 1 ;
108+ if ( lineIndex === sqlStartLineIndex ) {
109+ endSqlIndex = lineOfText . indexOf (
110+ sqlStringBound ,
111+ startRangePosition ,
112+ ) ;
113+ } else {
114+ endSqlIndex = lineOfText . indexOf ( sqlStringBound ) ;
115+ }
100116 if ( endSqlIndex !== - 1 ) {
101117 sqlStringCnt += 1 ;
102118 const range = new vscode . Range (
@@ -109,6 +125,7 @@ export async function refreshDiagnostics(
109125 diagnostics . push ( ...subDiagnostics ) ;
110126 sqlStartLineIndex = - 1 ;
111127 sqlStringBound = '' ;
128+ hashes = '' ;
112129 }
113130 }
114131 }
0 commit comments