Skip to content

Commit e308c2b

Browse files
author
Dave Bartolomeo
authored
Merge pull request #2685 from github/shati-patel/get-current-query
Fix `getCurrentQuery` to look at active tabs instead of active text editors
2 parents a965ea4 + 616bdb9 commit e308c2b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

extensions/ql-vscode/src/local-queries/local-queries.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
CancellationTokenSource,
99
QuickPickItem,
1010
Range,
11+
TabInputText,
1112
Uri,
1213
window,
1314
} from "vscode";
@@ -300,20 +301,18 @@ export class LocalQueries extends DisposableObject {
300301
}
301302

302303
/**
303-
* Gets the current active query.
304-
*
305-
* For now, the "active query" is just whatever query is in the active text editor. Once we have a
306-
* proper "queries" panel, we can provide a way to select the current query there.
304+
* Gets the current active query. This is the query that is open in the active tab.
307305
*/
308306
public async getCurrentQuery(allowLibraryFiles: boolean): Promise<string> {
309-
const editor = window.activeTextEditor;
310-
if (editor === undefined) {
307+
const input = window.tabGroups.activeTabGroup.activeTab?.input;
308+
309+
if (input === undefined || !isTabInputText(input)) {
311310
throw new Error(
312311
"No query was selected. Please select a query and try again.",
313312
);
314313
}
315314

316-
return validateQueryUri(editor.document.uri, allowLibraryFiles);
315+
return validateQueryUri(input.uri, allowLibraryFiles);
317316
}
318317

319318
private async createSkeletonQuery(): Promise<void> {
@@ -581,3 +580,7 @@ export class LocalQueries extends DisposableObject {
581580
: [];
582581
}
583582
}
583+
584+
function isTabInputText(input: any): input is TabInputText {
585+
return input?.uri !== undefined;
586+
}

0 commit comments

Comments
 (0)