Fix getCurrentQuery to look at active tabs instead of active text editors

This commit is contained in:
shati-patel
2023-08-09 17:07:33 +01:00
parent bd6a7b263f
commit c5febb4b48

View File

@@ -8,6 +8,7 @@ import {
CancellationTokenSource,
QuickPickItem,
Range,
TabInputText,
Uri,
window,
} from "vscode";
@@ -300,20 +301,18 @@ export class LocalQueries extends DisposableObject {
}
/**
* Gets the current active query.
*
* For now, the "active query" is just whatever query is in the active text editor. Once we have a
* proper "queries" panel, we can provide a way to select the current query there.
* Gets the current active query. This is the query that is open in the active tab.
*/
public async getCurrentQuery(allowLibraryFiles: boolean): Promise<string> {
const editor = window.activeTextEditor;
if (editor === undefined) {
const input = window.tabGroups.activeTabGroup.activeTab?.input;
if (input === undefined || !isTabInputText(input)) {
throw new Error(
"No query was selected. Please select a query and try again.",
);
}
return validateQueryUri(editor.document.uri, allowLibraryFiles);
return validateQueryUri(input.uri, allowLibraryFiles);
}
private async createSkeletonQuery(): Promise<void> {
@@ -581,3 +580,7 @@ export class LocalQueries extends DisposableObject {
: [];
}
}
function isTabInputText(input: any): input is TabInputText {
return input?.uri !== undefined;
}