|
2 | 2 | // Licensed under the MIT License.
|
3 | 3 |
|
4 | 4 | import * as vscode from 'vscode';
|
5 |
| -import { getGlobalStorage } from '../common/persistentState'; |
| 5 | +import { Uri } from 'vscode'; |
| 6 | +import { getGlobalStorage, IPersistentStorage } from '../common/persistentState'; |
6 | 7 | import { getOSType, OSType } from '../common/utils/platform';
|
7 | 8 | import { ActivationResult, ExtensionState } from '../components';
|
8 | 9 | import { PythonEnvInfo } from './base/info';
|
@@ -184,11 +185,38 @@ function createWorkspaceLocator(ext: ExtensionState): WorkspaceLocators {
|
184 | 185 | return locators;
|
185 | 186 | }
|
186 | 187 |
|
| 188 | +function getFromStorage(storage: IPersistentStorage<PythonEnvInfo[]>): PythonEnvInfo[] { |
| 189 | + return storage.get().map((e) => { |
| 190 | + if (e.searchLocation) { |
| 191 | + if (typeof e.searchLocation === 'string') { |
| 192 | + e.searchLocation = Uri.parse(e.searchLocation); |
| 193 | + } else if ('scheme' in e.searchLocation && 'path' in e.searchLocation) { |
| 194 | + e.searchLocation = Uri.parse(`${e.searchLocation.scheme}://${e.searchLocation.path}`); |
| 195 | + } |
| 196 | + } |
| 197 | + return e; |
| 198 | + }); |
| 199 | +} |
| 200 | + |
| 201 | +function putIntoStorage(storage: IPersistentStorage<PythonEnvInfo[]>, envs: PythonEnvInfo[]): Promise<void> { |
| 202 | + storage.set( |
| 203 | + envs.map((e) => { |
| 204 | + if (e.searchLocation) { |
| 205 | + // Make TS believe it is string. This is temporary. We need to serialize this in |
| 206 | + // a custom way. |
| 207 | + e.searchLocation = (e.searchLocation.toString() as unknown) as Uri; |
| 208 | + } |
| 209 | + return e; |
| 210 | + }), |
| 211 | + ); |
| 212 | + return Promise.resolve(); |
| 213 | +} |
| 214 | + |
187 | 215 | async function createCollectionCache(ext: ExtensionState): Promise<IEnvsCollectionCache> {
|
188 | 216 | const storage = getGlobalStorage<PythonEnvInfo[]>(ext.context, 'PYTHON_ENV_INFO_CACHE', []);
|
189 | 217 | const cache = await createCache({
|
190 |
| - get: () => storage.get(), |
191 |
| - store: async (e) => storage.set(e), |
| 218 | + get: () => getFromStorage(storage), |
| 219 | + store: async (e) => putIntoStorage(storage, e), |
192 | 220 | });
|
193 | 221 | return cache;
|
194 | 222 | }
|
0 commit comments