forked from DonJayamanne/vscode-python-manager
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcache.ts
More file actions
28 lines (25 loc) · 1.42 KB
/
Copy pathcache.ts
File metadata and controls
28 lines (25 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { commands, ExtensionContext, ExtensionMode } from 'vscode';
import { PythonEnvironment } from '../client/pythonEnvironments/info';
const LastExtensionVersionKey = 'LAST_EXTENSION_VERSION';
export const EnvironmentsCacheMementoKey = 'PYTHON:PACKAGE_MANAGER:ENVS_CACHE';
let cacheClearedOnce = false;
export async function clearCacheIfNewVersionInstalled(context: ExtensionContext, clearEnvCache = false) {
const shouldRefresh = context.extensionMode === ExtensionMode.Development;
if (!shouldRefresh && (cacheClearedOnce || context.globalState.get(LastExtensionVersionKey, '') === context.extension?.packageJSON?.version)) {
return;
}
cacheClearedOnce = true;
let venvEnvs: PythonEnvironment[] = []
if (!clearEnvCache) {
venvEnvs = context.globalState.get<PythonEnvironment[]>(EnvironmentsCacheMementoKey, []);
}
await Promise.all([
commands.executeCommand('python.envManager.clearPersistentStorage'),
context.globalState.keys().filter(key => key !== LastExtensionVersionKey).map(key => context.globalState.update(key, undefined)),
context.workspaceState.keys().map(key => context.workspaceState.update(key, undefined))
]);
await context.globalState.update(LastExtensionVersionKey, context.extension.packageJSON.version);
if (!clearEnvCache && Array.isArray(venvEnvs)) {
await context.globalState.update(EnvironmentsCacheMementoKey, venvEnvs);
}
}