@@ -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
5386export class ExtensionsStorage extends Disposable {
0 commit comments