File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -166,16 +166,22 @@ async function runMultipleHandler(mode: `all`|`selected`|`from`) {
166
166
const startPos = editor . document . offsetAt ( selection . start ) ;
167
167
const endPos = editor . document . offsetAt ( selection . end ) ;
168
168
169
- const sqlDocument = new Document ( editor . document . getText ( ) ) ;
169
+ const sqlDocument = new Document ( editor . document . getText ( ) , false ) ;
170
170
const statementGroups = sqlDocument . getStatementGroups ( ) ;
171
171
172
172
let statementsToRun : StatementGroup [ ] ;
173
173
174
+ const isInRange = ( group : StatementGroup ) => {
175
+ const groupStart = group . statements [ 0 ] . tokens [ 0 ] . range . start ;
176
+ const groupEnd = group . statements [ group . statements . length - 1 ] . tokens [ group . statements [ group . statements . length - 1 ] . tokens . length - 1 ] . range . end ;
177
+
178
+ return ( startPos >= groupStart && startPos <= groupEnd ) || ( endPos >= groupStart && endPos <= groupEnd ) ||
179
+ ( groupStart >= startPos && groupStart <= endPos ) || ( groupEnd >= startPos && groupEnd <= endPos ) ;
180
+ }
181
+
174
182
switch ( mode ) {
175
183
case `selected` :
176
- const firstStatement = statementGroups . findIndex ( group => ( startPos >= group . range . start && startPos <= group . range . end ) ) ;
177
- const lastStatement = statementGroups . findIndex ( group => ( endPos >= group . range . start && endPos <= group . range . end ) ) ;
178
- statementsToRun = statementGroups . slice ( firstStatement , lastStatement + 1 ) ;
184
+ statementsToRun = statementGroups . filter ( group => isInRange ( group ) || isInRange ( group ) )
179
185
break ;
180
186
case `from` : statementsToRun = statementGroups . filter ( group => ( startPos <= group . range . end ) ) ; break ;
181
187
default : statementsToRun = statementGroups ;
You can’t perform that action at this time.
0 commit comments