I need to run the extension command right after the installation. There is an event like onStartupFinished
, but the problem is, it will run every time the vscode starts.
How to do it? does vsocde have any way to do it?
CodePudding user response:
You can use a version field in the global context state. You get the context in your activation method.
export const activate = (context: ExtensionContext): void => {
const myExtension = extensions.getExtension("<my-extension-id>");
const currentVersion = myExtension!.packageJSON.version ?? "1.0.0";
const lastVersion = context.globalState.get("MyExtensionVersion");
if (currentVersion !== lastVersion) {
void context.globalState.update("MyExtensionVersion", currentVersion);
// Do one time setup here.
}
}
Don't forget to set onStartupFinished
in activationEvents
.