From c5febb4b4821f1fcf492990ecc9ae9d42e2c3669 Mon Sep 17 00:00:00 2001 From: shati-patel <42641846+shati-patel@users.noreply.github.com> Date: Wed, 9 Aug 2023 17:07:33 +0100 Subject: [PATCH] Fix `getCurrentQuery` to look at active tabs instead of active text editors --- .../src/local-queries/local-queries.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/extensions/ql-vscode/src/local-queries/local-queries.ts b/extensions/ql-vscode/src/local-queries/local-queries.ts index 96ea67bec..70bb4efef 100644 --- a/extensions/ql-vscode/src/local-queries/local-queries.ts +++ b/extensions/ql-vscode/src/local-queries/local-queries.ts @@ -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 { - 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 { @@ -581,3 +580,7 @@ export class LocalQueries extends DisposableObject { : []; } } + +function isTabInputText(input: any): input is TabInputText { + return input?.uri !== undefined; +}