Skip to content

Commit 251cd73

Browse files
committed
Extensions Storage: do not dispose immediately
1 parent 9c1a7e7 commit 251cd73

2 files changed

Lines changed: 39 additions & 5 deletions

File tree

src/vs/platform/extensions/node/extensions.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export class ExtensionsRuntimeService implements IExtensionsRuntimeService {
1414

1515
_serviceBrand: any;
1616

17+
private workspaceStorage: ExtensionsStorage;
18+
private globalStorage: ExtensionsStorage;
19+
1720
constructor(
1821
@IStorageService private storageService: IStorageService
1922
) {
@@ -34,20 +37,50 @@ export class ExtensionsRuntimeService implements IExtensionsRuntimeService {
3437
}
3538

3639
private getData(scope: StorageScope): IExtensionsStorageData {
40+
const extensionsStorage = this.getStorage(scope);
41+
return extensionsStorage ? extensionsStorage.data : {};
42+
}
43+
44+
private getStorage(scope: StorageScope): ExtensionsStorage {
3745
const path = this.getPath(scope);
3846
if (path) {
39-
const extensionsStorage = new ExtensionsStorage(path);
40-
const data = extensionsStorage.data;
41-
extensionsStorage.dispose();
42-
return data;
47+
if (StorageScope.WORKSPACE === scope) {
48+
return this.getWorkspaceStorage(path);
49+
}
50+
return this.getGlobalStorage(path);
4351
}
44-
return {};
52+
return null;
53+
}
54+
55+
private getGlobalStorage(path: string): ExtensionsStorage {
56+
if (!this.globalStorage) {
57+
this.globalStorage = new ExtensionsStorage(path);
58+
}
59+
return this.globalStorage;
60+
}
61+
62+
private getWorkspaceStorage(path: string): ExtensionsStorage {
63+
if (!this.workspaceStorage) {
64+
this.workspaceStorage = new ExtensionsStorage(path);
65+
}
66+
return this.workspaceStorage;
4567
}
4668

4769
private getPath(scope: StorageScope): string {
4870
const path = this.storageService.getStoragePath(scope);
4971
return path ? paths.join(path, 'extensions.json') : void 0;
5072
}
73+
74+
public dispose() {
75+
if (this.workspaceStorage) {
76+
this.workspaceStorage.dispose();
77+
this.workspaceStorage = null;
78+
}
79+
if (this.globalStorage) {
80+
this.globalStorage.dispose();
81+
this.globalStorage = null;
82+
}
83+
}
5184
}
5285

5386
export class ExtensionsStorage extends Disposable {

src/vs/workbench/electron-browser/shell.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ export class WorkbenchShell {
294294

295295
const extensionsRuntimeService = instantiationService.createInstance(ExtensionsRuntimeService);
296296
serviceCollection.set(IExtensionsRuntimeService, extensionsRuntimeService);
297+
disposables.add(extensionsRuntimeService);
297298

298299
const extensionHostProcessWorker = this.startExtensionHost(instantiationService);
299300
this.threadService = instantiationService.createInstance(MainThreadService, extensionHostProcessWorker.messagingProtocol);

0 commit comments

Comments
 (0)