From b6cfef75b557ff952a2c24523ba210e14fdfb815 Mon Sep 17 00:00:00 2001 From: Erik O'Leary Date: Wed, 21 Aug 2024 15:49:51 -0500 Subject: [PATCH] Execute the select connection command if user executes script without a connection #253 --- src/commands/runQuery.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/commands/runQuery.ts b/src/commands/runQuery.ts index 81bdc23..b37599a 100644 --- a/src/commands/runQuery.ts +++ b/src/commands/runQuery.ts @@ -15,8 +15,18 @@ export class runQueryCommand extends BaseCommand { let connection = EditorState.connection; if (!connection) { - vscode.window.showWarningMessage('No PostgreSQL Server or Database selected'); - return; + // If we don't have a connection, then we need to get one, execute the 'vscode-postgres.selectConnection' command + // to get the user to select a connection + await vscode.commands.executeCommand('vscode-postgres.selectConnection'); + + // Try to get the connection again + connection = EditorState.connection; + + // If the result is false, then the user cancelled the selection + if (!connection) { + vscode.window.showWarningMessage('No PostgreSQL Server or Database selected'); + return; + } } let editor = vscode.window.activeTextEditor;