diff --git a/vscode-extension/package.json b/vscode-extension/package.json index fd9f7ab4d..24a4984d5 100644 --- a/vscode-extension/package.json +++ b/vscode-extension/package.json @@ -15,6 +15,10 @@ "Other" ], "main": "./out/extension.js", + "activationEvents": [ + "workspaceContains:**.aiconfig.**", + "onView:extension" + ], "contributes": { "commands": [ { @@ -102,6 +106,11 @@ "type": "string", "default": "", "description": "Path to the python interpreter for this VS Code workspace" + }, + "vscode-aiconfig.version": { + "type": "string", + "default": "", + "description": "Version of the AIConfig Editor extension last time it was activated. We use this value to check if the extension has been updated to prompt users to reload VS Code" } } }, diff --git a/vscode-extension/src/constants.ts b/vscode-extension/src/constants.ts index c3e02f2c7..a2033eb9b 100644 --- a/vscode-extension/src/constants.ts +++ b/vscode-extension/src/constants.ts @@ -1 +1,5 @@ export const PYTHON_INTERPRETER_CACHE_KEY_NAME = "pythonInterpreter"; + +// Used for prompting user to reload VS Code window on update, and ensuring +// that walkthrough gets shown on first install +export const VERSION_KEY_NAME = "version"; diff --git a/vscode-extension/src/extension.ts b/vscode-extension/src/extension.ts index d1f1a2632..30c4d5c74 100644 --- a/vscode-extension/src/extension.ts +++ b/vscode-extension/src/extension.ts @@ -25,6 +25,7 @@ import { initialize, savePythonInterpreterToCache, } from "./utilities/pythonSetupUtils"; +import { performVersionInstallAndUpdateActionsIfNeeded } from "./utilities/versionUpdateUtils"; import { AIConfigEditorProvider } from "./aiConfigEditor"; import { AIConfigEditorManager, @@ -49,6 +50,8 @@ export async function activate(context: vscode.ExtensionContext) { log: true, }); + await performVersionInstallAndUpdateActionsIfNeeded(context); + const setupCommand = vscode.commands.registerCommand(COMMANDS.INIT, () => { initialize(context, extensionOutputChannel); }); @@ -175,6 +178,10 @@ export async function activate(context: vscode.ExtensionContext) { aiconfigEditorManager.getRegisteredEditors() ); if (editors.length > 0) { + // TODO: Check if user has set python interpreter, only do it if: + // after env is created + // python interpreter has actually changed + vscode.window .showInformationMessage( "Python Interpreter Updated: Would you like to refresh active AIConfig files?", diff --git a/vscode-extension/src/utilities/versionUpdateUtils.ts b/vscode-extension/src/utilities/versionUpdateUtils.ts new file mode 100644 index 000000000..a7d48e05f --- /dev/null +++ b/vscode-extension/src/utilities/versionUpdateUtils.ts @@ -0,0 +1,44 @@ +/** + * Utils file for handling actions to perform whenever user + * installs or updates the extension. + * VS Code automatically checks for version updates + * (https://code.visualstudio.com/docs/editor/extension-marketplace#_extension-autoupdate) + * but I haven't been able to find a way to use this to trigger any + * actions. Also even though the Walkthrough documentation says + * that this gets triggered on first install, I haven't been able + * to trigger this either, so I am calling this manually + * https://code.visualstudio.com/api/references/contribution-points#contributes.walkthroughs + */ + +import * as vscode from "vscode"; + +import { EXTENSION_NAME } from "../util"; +import { VERSION_KEY_NAME } from "../constants"; + +export async function performVersionInstallAndUpdateActionsIfNeeded( + context: vscode.ExtensionContext +) { + const extension = vscode.extensions.getExtension(context.extension.id); + const currExtensionVersion = extension?.packageJSON.version; + const config = vscode.workspace.getConfiguration(EXTENSION_NAME); + const lastActivatedVersion = config.get(VERSION_KEY_NAME); + if (currExtensionVersion !== lastActivatedVersion) { + await config.update( + VERSION_KEY_NAME, + currExtensionVersion, + vscode.ConfigurationTarget.Global + ); + } + + if (lastActivatedVersion === undefined || lastActivatedVersion === "") { + // First time activating extension, show walkthrough + // Will implement next PR + // vscode.commands.executeCommand("workbench.action.openWalkthrough"); + } else if ( + currExtensionVersion > lastActivatedVersion + // TODO: Add check for if version string follows format of %d.%d.%d + ) { + // Extension has been updated, prompt user to refresh VS Code window + // Will implement next PR + } +}