From a10a9368188dd01c887132246a29ce332c08a295 Mon Sep 17 00:00:00 2001 From: Adam Shedivy Date: Thu, 31 Oct 2024 15:17:36 -0500 Subject: [PATCH] enable continue features only when extension is active --- package.json | 7 +------ .../continue/continueContextProvider.ts | 15 +++++++++++++-- src/views/jobManager/jobManagerView.ts | 2 -- .../jobManager/selfCodes/selfCodesResultsView.ts | 3 ++- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 6f97d9b7..3f09a0ec 100644 --- a/package.json +++ b/package.json @@ -875,11 +875,6 @@ "group": "navigation@1", "when": "view == jobManager" }, - { - "command": "vscode-db2i.jobManager.continue", - "group": "navigation@1", - "when": "view == jobManager" - }, { "command": "vscode-db2i.jobManager.defaultSelfSettings", "group": "navigation", @@ -1093,7 +1088,7 @@ }, { "command": "vscode-db2i.self.explainSelf", - "when": "view == vscode-db2i.self.nodes && viewItem == selfCodeNode", + "when": "view == vscode-db2i.self.nodes && viewItem == selfCodeNode && continueExtensionActive", "group": "navigation" } ], diff --git a/src/aiProviders/continue/continueContextProvider.ts b/src/aiProviders/continue/continueContextProvider.ts index 46b64136..94591c99 100644 --- a/src/aiProviders/continue/continueContextProvider.ts +++ b/src/aiProviders/continue/continueContextProvider.ts @@ -13,6 +13,8 @@ import { } from "../../.."; import { DB2_SELF_PROMPT, DB2_SYSTEM_PROMPT } from "./prompts"; +export let isContinueActive = false; + const db2ContextProviderDesc: ContextProviderDescription = { title: "db2i", displayTitle: "Db2i", @@ -176,6 +178,15 @@ export async function registerContinueProvider() { const provider = new db2ContextProvider(); const continueID = `Continue.continue`; const continueEx = vscode.extensions.getExtension(continueID); - const continueAPI = continueEx?.exports; - continueAPI?.registerCustomContextProvider(provider); + if (continueEx) { + if (!continueEx.isActive) { + await continueEx.activate(); + } + + isContinueActive = true; + const continueAPI = continueEx?.exports; + continueAPI?.registerCustomContextProvider(provider); + vscode.commands.executeCommand('setContext', 'continueExtensionActive', true); + vscode.window.showInformationMessage(`@Db2i context provider enabled in Continue!`); + } } diff --git a/src/views/jobManager/jobManagerView.ts b/src/views/jobManager/jobManagerView.ts index 176fd39d..8ebbec52 100644 --- a/src/views/jobManager/jobManagerView.ts +++ b/src/views/jobManager/jobManagerView.ts @@ -9,9 +9,7 @@ import { displayJobLog } from "./jobLog"; import { SelfValue, selfCodesMap } from "./selfCodes/nodes"; import { SelfCodesQuickPickItem } from "./selfCodes/selfCodesBrowser"; import { updateStatusBar } from "./statusBar"; -import { selfCodesResultsView } from "./selfCodes/selfCodesResultsView"; import { setCancelButtonVisibility } from "../results"; -import { registerContinueProvider } from "../../aiProviders/continue/continueContextProvider"; import { JDBCOptions } from "@ibm/mapepire-js/dist/src/types"; const selectJobCommand = `vscode-db2i.jobManager.selectJob`; diff --git a/src/views/jobManager/selfCodes/selfCodesResultsView.ts b/src/views/jobManager/selfCodes/selfCodesResultsView.ts index 68f5b5eb..bea8e30a 100644 --- a/src/views/jobManager/selfCodes/selfCodesResultsView.ts +++ b/src/views/jobManager/selfCodes/selfCodesResultsView.ts @@ -16,6 +16,7 @@ import { SQLExample } from "../../examples"; import { JobInfo } from "../../../connection/manager"; import { OldSQLJob } from "../../../connection/sqlJob"; import { JobLogEntry } from "../../../connection/types"; +import { isContinueActive } from "../../../aiProviders/continue/continueContextProvider"; type ChangeTreeDataEventType = SelfCodeTreeItem | undefined | null | void; @@ -70,7 +71,7 @@ export class selfCodesResultsView implements TreeDataProvider { } }), vscode.commands.registerCommand(`vscode-db2i.self.explainSelf`, async (item: SelfCodeTreeItem) => { - if (item && item.error) { + if (item && item.error && isContinueActive) { const jsonData = JSON.stringify(item.error, null, 2); const document = await vscode.workspace.openTextDocument({ content: jsonData,