@@ -12,13 +12,14 @@ import { areSameExtensions } from 'vs/platform/extensionManagement/common/extens
12
12
import { IWorkspaceContextService , WorkbenchState } from 'vs/platform/workspace/common/workspace' ;
13
13
import { IStorageService , StorageScope } from 'vs/platform/storage/common/storage' ;
14
14
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService' ;
15
- import { ExtensionType , IExtension } from 'vs/platform/extensions/common/extensions' ;
15
+ import { ExtensionType , IExtension , isAuthenticaionProviderExtension , isLanguagePackExtension } from 'vs/platform/extensions/common/extensions' ;
16
16
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
17
17
import { getExtensionKind } from 'vs/workbench/services/extensions/common/extensionsUtil' ;
18
18
import { registerSingleton } from 'vs/platform/instantiation/common/extensions' ;
19
19
import { IProductService } from 'vs/platform/product/common/productService' ;
20
20
import { StorageManager } from 'vs/platform/extensionManagement/common/extensionEnablementService' ;
21
21
import { webWorkerExtHostConfig } from 'vs/workbench/services/extensions/common/extensions' ;
22
+ import { IUserDataSyncAccountService } from 'vs/platform/userDataSync/common/userDataSyncAccount' ;
22
23
23
24
const SOURCE = 'IWorkbenchExtensionEnablementService' ;
24
25
@@ -40,6 +41,7 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
40
41
@IConfigurationService private readonly configurationService : IConfigurationService ,
41
42
@IExtensionManagementServerService private readonly extensionManagementServerService : IExtensionManagementServerService ,
42
43
@IProductService private readonly productService : IProductService ,
44
+ @IUserDataSyncAccountService private readonly userDataSyncAccountService : IUserDataSyncAccountService ,
43
45
) {
44
46
super ( ) ;
45
47
this . storageManger = this . _register ( new StorageManager ( storageService ) ) ;
@@ -66,7 +68,9 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
66
68
}
67
69
68
70
canChangeEnablement ( extension : IExtension ) : boolean {
69
- if ( extension . manifest && extension . manifest . contributes && extension . manifest . contributes . localizations && extension . manifest . contributes . localizations . length ) {
71
+ try {
72
+ this . throwErrorIfCannotChangeEnablement ( extension ) ;
73
+ } catch ( error ) {
70
74
return false ;
71
75
}
72
76
const enablementState = this . getEnablementState ( extension ) ;
@@ -76,11 +80,47 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
76
80
return true ;
77
81
}
78
82
83
+ private throwErrorIfCannotChangeEnablement ( extension : IExtension ) : void {
84
+ if ( isLanguagePackExtension ( extension . manifest ) ) {
85
+ throw new Error ( localize ( 'cannot disable language pack extension' , "Cannot disable {0} extension because it contributes language packs." , extension . manifest . displayName || extension . identifier . id ) ) ;
86
+ }
87
+
88
+ if ( this . userDataSyncAccountService . account &&
89
+ isAuthenticaionProviderExtension ( extension . manifest ) && extension . manifest . contributes ! . authentication ! . some ( a => a . id === this . userDataSyncAccountService . account ! . authenticationProviderId ) ) {
90
+ throw new Error ( localize ( 'cannot disable auth extension' , "Cannot disable {0} extension because Settings Sync depends on it." , extension . manifest . displayName || extension . identifier . id ) ) ;
91
+ }
92
+ }
93
+
94
+ canChangeWorkspaceEnablement ( extension : IExtension ) : boolean {
95
+ if ( ! this . canChangeEnablement ( extension ) ) {
96
+ return false ;
97
+ }
98
+ try {
99
+ this . throwErrorIfCannotChangeWorkspaceEnablement ( extension ) ;
100
+ } catch ( error ) {
101
+ return false ;
102
+ }
103
+ return true ;
104
+ }
105
+
106
+ private throwErrorIfCannotChangeWorkspaceEnablement ( extension : IExtension ) : void {
107
+ if ( ! this . hasWorkspace ) {
108
+ throw new Error ( localize ( 'noWorkspace' , "No workspace." ) ) ;
109
+ }
110
+ if ( isAuthenticaionProviderExtension ( extension . manifest ) ) {
111
+ throw new Error ( localize ( 'cannot disable auth extension in workspace' , "Cannot disable {0} extension in workspace because it contributes authentication providers" , extension . manifest . displayName || extension . identifier . id ) ) ;
112
+ }
113
+ }
114
+
79
115
async setEnablement ( extensions : IExtension [ ] , newState : EnablementState ) : Promise < boolean [ ] > {
80
116
81
117
const workspace = newState === EnablementState . DisabledWorkspace || newState === EnablementState . EnabledWorkspace ;
82
- if ( workspace && ! this . hasWorkspace ) {
83
- return Promise . reject ( new Error ( localize ( 'noWorkspace' , "No workspace." ) ) ) ;
118
+ for ( const extension of extensions ) {
119
+ if ( workspace ) {
120
+ this . throwErrorIfCannotChangeWorkspaceEnablement ( extension ) ;
121
+ } else {
122
+ this . throwErrorIfCannotChangeEnablement ( extension ) ;
123
+ }
84
124
}
85
125
86
126
const result = await Promise . all ( extensions . map ( e => this . _setEnablement ( e , newState ) ) ) ;
@@ -316,4 +356,4 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
316
356
}
317
357
}
318
358
319
- registerSingleton ( IWorkbenchExtensionEnablementService , ExtensionEnablementService , true ) ;
359
+ registerSingleton ( IWorkbenchExtensionEnablementService , ExtensionEnablementService ) ;
0 commit comments