Skip to content

Commit 67644d2

Browse files
committed
Improve range checking for statement groups in runMultipleHandler
Signed-off-by: worksofliam <[email protected]>
1 parent 218b33b commit 67644d2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/views/results/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,22 @@ async function runMultipleHandler(mode: `all`|`selected`|`from`) {
166166
const startPos = editor.document.offsetAt(selection.start);
167167
const endPos = editor.document.offsetAt(selection.end);
168168

169-
const sqlDocument = new Document(editor.document.getText());
169+
const sqlDocument = new Document(editor.document.getText(), false);
170170
const statementGroups = sqlDocument.getStatementGroups();
171171

172172
let statementsToRun: StatementGroup[];
173173

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+
174182
switch (mode) {
175183
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))
179185
break;
180186
case `from`: statementsToRun = statementGroups.filter(group => (startPos <= group.range.end)); break;
181187
default: statementsToRun = statementGroups;

0 commit comments

Comments
 (0)