diff --git a/package.json b/package.json index 4fea13e9..b209bd55 100644 --- a/package.json +++ b/package.json @@ -165,6 +165,10 @@ "type": "string", "description": "QHOME directory for q runtime" }, + "kdb.neverShowQInstallAgain": { + "type": "boolean", + "description": "Never show q install walkthrough again" + }, "kdb.hideSubscribeRegistrationNotification": { "type": "boolean", "description": "Hide subscribe for registration notification", diff --git a/src/commands/serverCommand.ts b/src/commands/serverCommand.ts index 0837fcca..76c740b5 100644 --- a/src/commands/serverCommand.ts +++ b/src/commands/serverCommand.ts @@ -545,7 +545,6 @@ export async function removeConnection(viewItem: KdbNode | InsightsNode) { export async function connect(connLabel: string): Promise { const connMngService = new ConnectionManagementService(); - commands.executeCommand("kdb-results.focus"); ExecutionConsole.start(); const viewItem = connMngService.retrieveConnection(connLabel); if (viewItem === undefined) { diff --git a/src/extension.ts b/src/extension.ts index 0a1688a2..21f973a2 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -177,11 +177,13 @@ export async function activate(context: ExtensionContext) { AuthSettings.init(context); ext.secretSettings = AuthSettings.instance; + commands.executeCommand("kdb-results.focus"); + kdbOutputLog("kdb extension is now active!", "INFO"); try { // check for installed q runtime - await checkLocalInstall(); + await checkLocalInstall(true); } catch (err) { window.showErrorMessage(`${err}`); } diff --git a/src/utils/core.ts b/src/utils/core.ts index a60a0b3b..90cef80d 100644 --- a/src/utils/core.ts +++ b/src/utils/core.ts @@ -405,8 +405,18 @@ export function delay(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)); } -export async function checkLocalInstall(): Promise { +export async function checkLocalInstall( + isExtensionStartCheck?: boolean, +): Promise { const QHOME = workspace.getConfiguration().get("kdb.qHomeDirectory"); + if (isExtensionStartCheck) { + const notShow = workspace + .getConfiguration() + .get("kdb.neverShowQInstallAgain"); + if (notShow) { + return; + } + } if (QHOME || env.QHOME) { env.QHOME = QHOME || env.QHOME; if (!pathExists(env.QHOME!)) { @@ -454,12 +464,21 @@ export async function checkLocalInstall(): Promise { .showInformationMessage( "Local q installation not found!", "Install new instance", - "Cancel", + "No", + "Never show again", ) .then(async (installResult) => { if (installResult === "Install new instance") { await installTools(); - } else if (installResult === "Cancel") { + } else if (installResult === "Never show again") { + await workspace + .getConfiguration() + .update( + "kdb.neverShowQInstallAgain", + true, + ConfigurationTarget.Global, + ); + } else { showRegistrationNotification(); } }); diff --git a/test/suite/utils.test.ts b/test/suite/utils.test.ts index 5e55684a..26c339eb 100644 --- a/test/suite/utils.test.ts +++ b/test/suite/utils.test.ts @@ -1834,4 +1834,74 @@ describe("Utils", () => { assert.strictEqual(result, false); }); }); + + describe("checkLocalInstall", () => { + let getConfigurationStub: sinon.SinonStub; + let updateConfigurationStub: sinon.SinonStub; + let showInformationMessageStub: sinon.SinonStub; + let executeCommandStub: sinon.SinonStub; + + beforeEach(() => { + getConfigurationStub = sinon + .stub(vscode.workspace, "getConfiguration") + .returns({ + get: sinon.stub().returns(false), + update: sinon.stub().resolves(), + } as any); + updateConfigurationStub = getConfigurationStub() + .update as sinon.SinonStub; + showInformationMessageStub = sinon + .stub(vscode.window, "showInformationMessage") + .resolves(); + executeCommandStub = sinon + .stub(vscode.commands, "executeCommand") + .resolves(); + }); + + afterEach(() => { + sinon.restore(); + }); + + it("should return if 'neverShowQInstallAgain' is true", async () => { + getConfigurationStub() + .get.withArgs("kdb.neverShowQInstallAgain") + .returns(true); + + await coreUtils.checkLocalInstall(true); + + assert.strictEqual(showInformationMessageStub.called, false); + assert.strictEqual(executeCommandStub.called, false); + }); + it("should continue if 'neverShowQInstallAgain' is false", async () => { + getConfigurationStub() + .get.withArgs("kdb.neverShowQInstallAgain") + .returns(false); + + await coreUtils.checkLocalInstall(true); + + assert.strictEqual(showInformationMessageStub.called, true); + assert.strictEqual(executeCommandStub.called, true); + }); + + it("should handle 'Never show again' response", async () => { + getConfigurationStub() + .get.withArgs("kdb.qHomeDirectory") + .returns(undefined); + getConfigurationStub() + .get.withArgs("kdb.neverShowQInstallAgain") + .returns(false); + showInformationMessageStub.resolves("Never show again"); + + await coreUtils.checkLocalInstall(); + + assert.strictEqual( + updateConfigurationStub.calledWith( + "kdb.neverShowQInstallAgain", + true, + vscode.ConfigurationTarget.Global, + ), + true, + ); + }); + }); });