Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
e1f1744c
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e1f1744c
编写于
1月 22, 2020
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#86916 introduce global extension enablement service
上级
e9167751
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
231 addition
and
147 deletion
+231
-147
src/vs/platform/extensionManagement/common/extensionEnablementService.ts
.../extensionManagement/common/extensionEnablementService.ts
+153
-0
src/vs/platform/extensionManagement/common/extensionManagement.ts
...latform/extensionManagement/common/extensionManagement.ts
+12
-0
src/vs/workbench/services/extensionManagement/common/extensionEnablementService.ts
.../extensionManagement/common/extensionEnablementService.ts
+54
-140
src/vs/workbench/services/extensionManagement/test/electron-browser/extensionEnablementService.test.ts
.../test/electron-browser/extensionEnablementService.test.ts
+9
-6
src/vs/workbench/workbench.common.main.ts
src/vs/workbench/workbench.common.main.ts
+3
-1
未找到文件。
src/vs/platform/extensionManagement/common/extensionEnablementService.ts
0 → 100644
浏览文件 @
e1f1744c
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IExtensionIdentifier
,
IGlobalExtensionEnablementService
,
DISABLED_EXTENSIONS_STORAGE_PATH
}
from
'
vs/platform/extensionManagement/common/extensionManagement
'
;
import
{
areSameExtensions
}
from
'
vs/platform/extensionManagement/common/extensionManagementUtil
'
;
import
{
IStorageService
,
StorageScope
,
IWorkspaceStorageChangeEvent
}
from
'
vs/platform/storage/common/storage
'
;
import
{
isUndefinedOrNull
}
from
'
vs/base/common/types
'
;
export
class
GlobalExtensionEnablementService
extends
Disposable
implements
IGlobalExtensionEnablementService
{
_serviceBrand
:
undefined
;
private
_onDidChangeEnablement
=
new
Emitter
<
readonly
IExtensionIdentifier
[]
>
();
readonly
onDidChangeEnablement
:
Event
<
readonly
IExtensionIdentifier
[]
>
=
this
.
_onDidChangeEnablement
.
event
;
private
readonly
storageManger
:
StorageManager
;
constructor
(
@
IStorageService
storageService
:
IStorageService
,
)
{
super
();
this
.
storageManger
=
this
.
_register
(
new
StorageManager
(
storageService
));
this
.
_register
(
this
.
storageManger
.
onDidChange
(
extensions
=>
this
.
_onDidChangeEnablement
.
fire
(
extensions
)));
}
async
enableExtension
(
extension
:
IExtensionIdentifier
):
Promise
<
boolean
>
{
if
(
this
.
_removeFromDisabledExtensions
(
extension
))
{
return
true
;
}
return
false
;
}
async
disableExtension
(
extension
:
IExtensionIdentifier
):
Promise
<
boolean
>
{
if
(
this
.
_addToDisabledExtensions
(
extension
))
{
return
true
;
}
return
false
;
}
getDisabledExtensions
():
IExtensionIdentifier
[]
{
return
this
.
_getExtensions
(
DISABLED_EXTENSIONS_STORAGE_PATH
);
}
private
_addToDisabledExtensions
(
identifier
:
IExtensionIdentifier
):
boolean
{
let
disabledExtensions
=
this
.
getDisabledExtensions
();
if
(
disabledExtensions
.
every
(
e
=>
!
areSameExtensions
(
e
,
identifier
)))
{
disabledExtensions
.
push
(
identifier
);
this
.
_setDisabledExtensions
(
disabledExtensions
);
return
true
;
}
return
false
;
}
private
_removeFromDisabledExtensions
(
identifier
:
IExtensionIdentifier
):
boolean
{
let
disabledExtensions
=
this
.
getDisabledExtensions
();
for
(
let
index
=
0
;
index
<
disabledExtensions
.
length
;
index
++
)
{
const
disabledExtension
=
disabledExtensions
[
index
];
if
(
areSameExtensions
(
disabledExtension
,
identifier
))
{
disabledExtensions
.
splice
(
index
,
1
);
this
.
_setDisabledExtensions
(
disabledExtensions
);
return
true
;
}
}
return
false
;
}
private
_setDisabledExtensions
(
disabledExtensions
:
IExtensionIdentifier
[]):
void
{
this
.
_setExtensions
(
DISABLED_EXTENSIONS_STORAGE_PATH
,
disabledExtensions
);
}
private
_getExtensions
(
storageId
:
string
):
IExtensionIdentifier
[]
{
return
this
.
storageManger
.
get
(
storageId
,
StorageScope
.
GLOBAL
);
}
private
_setExtensions
(
storageId
:
string
,
extensions
:
IExtensionIdentifier
[]):
void
{
this
.
storageManger
.
set
(
storageId
,
extensions
,
StorageScope
.
GLOBAL
);
}
}
export
class
StorageManager
extends
Disposable
{
private
storage
:
{
[
key
:
string
]:
string
}
=
Object
.
create
(
null
);
private
_onDidChange
:
Emitter
<
IExtensionIdentifier
[]
>
=
this
.
_register
(
new
Emitter
<
IExtensionIdentifier
[]
>
());
readonly
onDidChange
:
Event
<
IExtensionIdentifier
[]
>
=
this
.
_onDidChange
.
event
;
constructor
(
private
storageService
:
IStorageService
)
{
super
();
this
.
_register
(
storageService
.
onDidChangeStorage
(
e
=>
this
.
onDidStorageChange
(
e
)));
}
get
(
key
:
string
,
scope
:
StorageScope
):
IExtensionIdentifier
[]
{
let
value
:
string
;
if
(
scope
===
StorageScope
.
GLOBAL
)
{
if
(
isUndefinedOrNull
(
this
.
storage
[
key
]))
{
this
.
storage
[
key
]
=
this
.
_get
(
key
,
scope
);
}
value
=
this
.
storage
[
key
];
}
else
{
value
=
this
.
_get
(
key
,
scope
);
}
return
JSON
.
parse
(
value
);
}
set
(
key
:
string
,
value
:
IExtensionIdentifier
[],
scope
:
StorageScope
):
void
{
let
newValue
:
string
=
JSON
.
stringify
(
value
.
map
(({
id
,
uuid
})
=>
(
<
IExtensionIdentifier
>
{
id
,
uuid
})));
const
oldValue
=
this
.
_get
(
key
,
scope
);
if
(
oldValue
!==
newValue
)
{
if
(
scope
===
StorageScope
.
GLOBAL
)
{
if
(
value
.
length
)
{
this
.
storage
[
key
]
=
newValue
;
}
else
{
delete
this
.
storage
[
key
];
}
}
this
.
_set
(
key
,
value
.
length
?
newValue
:
undefined
,
scope
);
}
}
private
onDidStorageChange
(
workspaceStorageChangeEvent
:
IWorkspaceStorageChangeEvent
):
void
{
if
(
workspaceStorageChangeEvent
.
scope
===
StorageScope
.
GLOBAL
)
{
if
(
!
isUndefinedOrNull
(
this
.
storage
[
workspaceStorageChangeEvent
.
key
]))
{
const
newValue
=
this
.
_get
(
workspaceStorageChangeEvent
.
key
,
workspaceStorageChangeEvent
.
scope
);
if
(
newValue
!==
this
.
storage
[
workspaceStorageChangeEvent
.
key
])
{
const
oldValues
=
this
.
get
(
workspaceStorageChangeEvent
.
key
,
workspaceStorageChangeEvent
.
scope
);
delete
this
.
storage
[
workspaceStorageChangeEvent
.
key
];
const
newValues
=
this
.
get
(
workspaceStorageChangeEvent
.
key
,
workspaceStorageChangeEvent
.
scope
);
const
added
=
oldValues
.
filter
(
oldValue
=>
!
newValues
.
some
(
newValue
=>
areSameExtensions
(
oldValue
,
newValue
)));
const
removed
=
newValues
.
filter
(
newValue
=>
!
oldValues
.
some
(
oldValue
=>
areSameExtensions
(
oldValue
,
newValue
)));
if
(
added
.
length
||
removed
.
length
)
{
this
.
_onDidChange
.
fire
([...
added
,
...
removed
]);
}
}
}
}
}
private
_get
(
key
:
string
,
scope
:
StorageScope
):
string
{
return
this
.
storageService
.
get
(
key
,
scope
,
'
[]
'
);
}
private
_set
(
key
:
string
,
value
:
string
|
undefined
,
scope
:
StorageScope
):
void
{
if
(
value
)
{
this
.
storageService
.
store
(
key
,
value
,
scope
);
}
else
{
this
.
storageService
.
remove
(
key
,
scope
);
}
}
}
src/vs/platform/extensionManagement/common/extensionManagement.ts
浏览文件 @
e1f1744c
...
...
@@ -207,6 +207,18 @@ export interface IExtensionManagementService {
updateMetadata
(
local
:
ILocalExtension
,
metadata
:
IGalleryMetadata
):
Promise
<
ILocalExtension
>
;
}
export
const
DISABLED_EXTENSIONS_STORAGE_PATH
=
'
extensionsIdentifiers/disabled
'
;
export
const
ENABLED_EXTENSIONS_STORAGE_PATH
=
'
extensionsIdentifiers/enabled
'
;
export
const
IGlobalExtensionEnablementService
=
createDecorator
<
IGlobalExtensionEnablementService
>
(
'
IGlobalExtensionEnablementService
'
);
export
interface
IGlobalExtensionEnablementService
{
_serviceBrand
:
undefined
;
readonly
onDidChangeEnablement
:
Event
<
readonly
IExtensionIdentifier
[]
>
;
getDisabledExtensions
():
IExtensionIdentifier
[];
enableExtension
(
extension
:
IExtensionIdentifier
):
Promise
<
boolean
>
;
disableExtension
(
extension
:
IExtensionIdentifier
):
Promise
<
boolean
>
;
}
export
const
ExtensionsLabel
=
localize
(
'
extensions
'
,
"
Extensions
"
);
export
const
ExtensionsChannelId
=
'
extensions
'
;
export
const
PreferencesLabel
=
localize
(
'
preferences
'
,
"
Preferences
"
);
src/vs/workbench/services/extensionManagement/common/extensionEnablementService.ts
浏览文件 @
e1f1744c
...
...
@@ -6,21 +6,18 @@
import
{
localize
}
from
'
vs/nls
'
;
import
{
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IExtensionManagementService
,
DidUninstallExtensionEvent
,
IExtensionIdentifier
}
from
'
vs/platform/extensionManagement/common/extensionManagement
'
;
import
{
IExtensionManagementService
,
DidUninstallExtensionEvent
,
IExtensionIdentifier
,
IGlobalExtensionEnablementService
,
ENABLED_EXTENSIONS_STORAGE_PATH
,
DISABLED_EXTENSIONS_STORAGE_PATH
}
from
'
vs/platform/extensionManagement/common/extensionManagement
'
;
import
{
IWorkbenchExtensionEnablementService
,
EnablementState
,
IExtensionManagementServerService
}
from
'
vs/workbench/services/extensionManagement/common/extensionManagement
'
;
import
{
areSameExtensions
}
from
'
vs/platform/extensionManagement/common/extensionManagementUtil
'
;
import
{
IWorkspaceContextService
,
WorkbenchState
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IStorageService
,
StorageScope
,
IWorkspaceStorageChangeEvent
}
from
'
vs/platform/storage/common/storage
'
;
import
{
IStorageService
,
StorageScope
}
from
'
vs/platform/storage/common/storage
'
;
import
{
IWorkbenchEnvironmentService
}
from
'
vs/workbench/services/environment/common/environmentService
'
;
import
{
isUndefinedOrNull
}
from
'
vs/base/common/types
'
;
import
{
ExtensionType
,
IExtension
}
from
'
vs/platform/extensions/common/extensions
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
getExtensionKind
}
from
'
vs/workbench/services/extensions/common/extensionsUtil
'
;
import
{
registerSingleton
}
from
'
vs/platform/instantiation/common/extensions
'
;
import
{
IProductService
}
from
'
vs/platform/product/common/productService
'
;
const
DISABLED_EXTENSIONS_STORAGE_PATH
=
'
extensionsIdentifiers/disabled
'
;
const
ENABLED_EXTENSIONS_STORAGE_PATH
=
'
extensionsIdentifiers/enabled
'
;
import
{
StorageManager
}
from
'
vs/platform/extensionManagement/common/extensionEnablementService
'
;
export
class
ExtensionEnablementService
extends
Disposable
implements
IWorkbenchExtensionEnablementService
{
...
...
@@ -33,6 +30,7 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
constructor
(
@
IStorageService
storageService
:
IStorageService
,
@
IGlobalExtensionEnablementService
protected
readonly
globalExtensionEnablementService
:
IGlobalExtensionEnablementService
,
@
IWorkspaceContextService
private
readonly
contextService
:
IWorkspaceContextService
,
@
IWorkbenchEnvironmentService
private
readonly
environmentService
:
IWorkbenchEnvironmentService
,
@
IExtensionManagementService
private
readonly
extensionManagementService
:
IExtensionManagementService
,
...
...
@@ -42,7 +40,7 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
)
{
super
();
this
.
storageManger
=
this
.
_register
(
new
StorageManager
(
storageService
));
this
.
_register
(
this
.
storageManger
.
onDidChange
(
extensions
=>
this
.
onDidChangeStorage
(
extensions
)));
this
.
_register
(
this
.
globalExtensionEnablementService
.
onDidChangeEnablement
(
extensions
=>
this
.
onDidChangeExtensions
(
extensions
)));
this
.
_register
(
extensionManagementService
.
onDidUninstallExtension
(
this
.
_onDidUninstallExtension
,
this
));
}
...
...
@@ -61,20 +59,7 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
if
(
this
.
_isDisabledByExtensionKind
(
extension
))
{
return
EnablementState
.
DisabledByExtensionKind
;
}
const
identifier
=
extension
.
identifier
;
if
(
this
.
hasWorkspace
)
{
if
(
this
.
_getEnabledExtensions
(
StorageScope
.
WORKSPACE
).
filter
(
e
=>
areSameExtensions
(
e
,
identifier
))[
0
])
{
return
EnablementState
.
EnabledWorkspace
;
}
if
(
this
.
_getDisabledExtensions
(
StorageScope
.
WORKSPACE
).
filter
(
e
=>
areSameExtensions
(
e
,
identifier
))[
0
])
{
return
EnablementState
.
DisabledWorkspace
;
}
}
if
(
this
.
_getDisabledExtensions
(
StorageScope
.
GLOBAL
).
filter
(
e
=>
areSameExtensions
(
e
,
identifier
))[
0
])
{
return
EnablementState
.
DisabledGlobally
;
}
return
EnablementState
.
EnabledGlobally
;
return
this
.
_getEnablementState
(
extension
.
identifier
);
}
canChangeEnablement
(
extension
:
IExtension
):
boolean
{
...
...
@@ -167,128 +152,128 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
private
_getEnablementState
(
identifier
:
IExtensionIdentifier
):
EnablementState
{
if
(
this
.
hasWorkspace
)
{
if
(
this
.
_get
EnabledExtensions
(
StorageScope
.
WORKSPACE
).
filter
(
e
=>
areSameExtensions
(
e
,
identifier
))[
0
])
{
if
(
this
.
_get
WorkspaceEnabledExtensions
(
).
filter
(
e
=>
areSameExtensions
(
e
,
identifier
))[
0
])
{
return
EnablementState
.
EnabledWorkspace
;
}
if
(
this
.
_get
DisabledExtensions
(
StorageScope
.
WORKSPACE
).
filter
(
e
=>
areSameExtensions
(
e
,
identifier
))[
0
])
{
if
(
this
.
_get
WorkspaceDisabledExtensions
(
).
filter
(
e
=>
areSameExtensions
(
e
,
identifier
))[
0
])
{
return
EnablementState
.
DisabledWorkspace
;
}
}
if
(
this
.
_getDisabledExtensions
(
StorageScope
.
GLOBAL
).
filter
(
e
=>
areSameExtensions
(
e
,
identifier
))[
0
])
{
if
(
this
.
globalExtensionEnablementService
.
getDisabledExtensions
(
).
filter
(
e
=>
areSameExtensions
(
e
,
identifier
))[
0
])
{
return
EnablementState
.
DisabledGlobally
;
}
return
EnablementState
.
EnabledGlobally
;
}
private
_enableExtension
(
identifier
:
IExtensionIdentifier
):
void
{
this
.
_removeFrom
DisabledExtensions
(
identifier
,
StorageScope
.
WORKSPACE
);
this
.
_removeFrom
EnabledExtensions
(
identifier
,
StorageScope
.
WORKSPACE
);
this
.
_removeFromDisabledExtensions
(
identifier
,
StorageScope
.
GLOBAL
);
private
_enableExtension
(
identifier
:
IExtensionIdentifier
):
Promise
<
boolean
>
{
this
.
_removeFrom
WorkspaceDisabledExtensions
(
identifier
);
this
.
_removeFrom
WorkspaceEnabledExtensions
(
identifier
);
return
this
.
globalExtensionEnablementService
.
enableExtension
(
identifier
);
}
private
_disableExtension
(
identifier
:
IExtensionIdentifier
):
void
{
this
.
_removeFrom
DisabledExtensions
(
identifier
,
StorageScope
.
WORKSPACE
);
this
.
_removeFrom
EnabledExtensions
(
identifier
,
StorageScope
.
WORKSPACE
);
this
.
_addToDisabledExtensions
(
identifier
,
StorageScope
.
GLOBAL
);
private
_disableExtension
(
identifier
:
IExtensionIdentifier
):
Promise
<
boolean
>
{
this
.
_removeFrom
WorkspaceDisabledExtensions
(
identifier
);
this
.
_removeFrom
WorkspaceEnabledExtensions
(
identifier
);
return
this
.
globalExtensionEnablementService
.
disableExtension
(
identifier
);
}
private
_enableExtensionInWorkspace
(
identifier
:
IExtensionIdentifier
):
void
{
this
.
_removeFrom
DisabledExtensions
(
identifier
,
StorageScope
.
WORKSPACE
);
this
.
_addTo
EnabledExtensions
(
identifier
,
StorageScope
.
WORKSPACE
);
this
.
_removeFrom
WorkspaceDisabledExtensions
(
identifier
);
this
.
_addTo
WorkspaceEnabledExtensions
(
identifier
);
}
private
_disableExtensionInWorkspace
(
identifier
:
IExtensionIdentifier
):
void
{
this
.
_addTo
DisabledExtensions
(
identifier
,
StorageScope
.
WORKSPACE
);
this
.
_removeFrom
EnabledExtensions
(
identifier
,
StorageScope
.
WORKSPACE
);
this
.
_addTo
WorkspaceDisabledExtensions
(
identifier
);
this
.
_removeFrom
WorkspaceEnabledExtensions
(
identifier
);
}
private
_addTo
DisabledExtensions
(
identifier
:
IExtensionIdentifier
,
scope
:
StorageScope
):
Promise
<
boolean
>
{
if
(
scope
===
StorageScope
.
WORKSPACE
&&
!
this
.
hasWorkspace
)
{
private
_addTo
WorkspaceDisabledExtensions
(
identifier
:
IExtensionIdentifier
):
Promise
<
boolean
>
{
if
(
!
this
.
hasWorkspace
)
{
return
Promise
.
resolve
(
false
);
}
let
disabledExtensions
=
this
.
_get
DisabledExtensions
(
scope
);
let
disabledExtensions
=
this
.
_get
WorkspaceDisabledExtensions
(
);
if
(
disabledExtensions
.
every
(
e
=>
!
areSameExtensions
(
e
,
identifier
)))
{
disabledExtensions
.
push
(
identifier
);
this
.
_setDisabledExtensions
(
disabledExtensions
,
scope
);
this
.
_setDisabledExtensions
(
disabledExtensions
);
return
Promise
.
resolve
(
true
);
}
return
Promise
.
resolve
(
false
);
}
private
_removeFromDisabledExtensions
(
identifier
:
IExtensionIdentifier
,
scope
:
StorageScope
):
boolean
{
if
(
scope
===
StorageScope
.
WORKSPACE
&&
!
this
.
hasWorkspace
)
{
private
async
_removeFromWorkspaceDisabledExtensions
(
identifier
:
IExtensionIdentifier
):
Promise
<
boolean
>
{
if
(
!
this
.
hasWorkspace
)
{
return
false
;
}
let
disabledExtensions
=
this
.
_get
DisabledExtensions
(
scope
);
let
disabledExtensions
=
this
.
_get
WorkspaceDisabledExtensions
(
);
for
(
let
index
=
0
;
index
<
disabledExtensions
.
length
;
index
++
)
{
const
disabledExtension
=
disabledExtensions
[
index
];
if
(
areSameExtensions
(
disabledExtension
,
identifier
))
{
disabledExtensions
.
splice
(
index
,
1
);
this
.
_setDisabledExtensions
(
disabledExtensions
,
scope
);
this
.
_setDisabledExtensions
(
disabledExtensions
);
return
true
;
}
}
return
false
;
}
private
_addTo
EnabledExtensions
(
identifier
:
IExtensionIdentifier
,
scope
:
StorageScope
):
boolean
{
if
(
scope
===
StorageScope
.
WORKSPACE
&&
!
this
.
hasWorkspace
)
{
private
_addTo
WorkspaceEnabledExtensions
(
identifier
:
IExtensionIdentifier
):
boolean
{
if
(
!
this
.
hasWorkspace
)
{
return
false
;
}
let
enabledExtensions
=
this
.
_get
EnabledExtensions
(
scope
);
let
enabledExtensions
=
this
.
_get
WorkspaceEnabledExtensions
(
);
if
(
enabledExtensions
.
every
(
e
=>
!
areSameExtensions
(
e
,
identifier
)))
{
enabledExtensions
.
push
(
identifier
);
this
.
_setEnabledExtensions
(
enabledExtensions
,
scope
);
this
.
_setEnabledExtensions
(
enabledExtensions
);
return
true
;
}
return
false
;
}
private
_removeFrom
EnabledExtensions
(
identifier
:
IExtensionIdentifier
,
scope
:
StorageScope
):
boolean
{
if
(
scope
===
StorageScope
.
WORKSPACE
&&
!
this
.
hasWorkspace
)
{
private
_removeFrom
WorkspaceEnabledExtensions
(
identifier
:
IExtensionIdentifier
):
boolean
{
if
(
!
this
.
hasWorkspace
)
{
return
false
;
}
let
enabledExtensions
=
this
.
_get
EnabledExtensions
(
scope
);
let
enabledExtensions
=
this
.
_get
WorkspaceEnabledExtensions
(
);
for
(
let
index
=
0
;
index
<
enabledExtensions
.
length
;
index
++
)
{
const
disabledExtension
=
enabledExtensions
[
index
];
if
(
areSameExtensions
(
disabledExtension
,
identifier
))
{
enabledExtensions
.
splice
(
index
,
1
);
this
.
_setEnabledExtensions
(
enabledExtensions
,
scope
);
this
.
_setEnabledExtensions
(
enabledExtensions
);
return
true
;
}
}
return
false
;
}
protected
_get
EnabledExtensions
(
scope
:
StorageScope
):
IExtensionIdentifier
[]
{
return
this
.
_getExtensions
(
ENABLED_EXTENSIONS_STORAGE_PATH
,
scope
);
protected
_get
WorkspaceEnabledExtensions
(
):
IExtensionIdentifier
[]
{
return
this
.
_getExtensions
(
ENABLED_EXTENSIONS_STORAGE_PATH
);
}
private
_setEnabledExtensions
(
enabledExtensions
:
IExtensionIdentifier
[]
,
scope
:
StorageScope
):
void
{
this
.
_setExtensions
(
ENABLED_EXTENSIONS_STORAGE_PATH
,
enabledExtensions
,
scope
);
private
_setEnabledExtensions
(
enabledExtensions
:
IExtensionIdentifier
[]):
void
{
this
.
_setExtensions
(
ENABLED_EXTENSIONS_STORAGE_PATH
,
enabledExtensions
);
}
protected
_get
DisabledExtensions
(
scope
:
StorageScope
):
IExtensionIdentifier
[]
{
return
this
.
_getExtensions
(
DISABLED_EXTENSIONS_STORAGE_PATH
,
scope
);
protected
_get
WorkspaceDisabledExtensions
(
):
IExtensionIdentifier
[]
{
return
this
.
_getExtensions
(
DISABLED_EXTENSIONS_STORAGE_PATH
);
}
private
_setDisabledExtensions
(
disabledExtensions
:
IExtensionIdentifier
[]
,
scope
:
StorageScope
):
void
{
this
.
_setExtensions
(
DISABLED_EXTENSIONS_STORAGE_PATH
,
disabledExtensions
,
scope
);
private
_setDisabledExtensions
(
disabledExtensions
:
IExtensionIdentifier
[]):
void
{
this
.
_setExtensions
(
DISABLED_EXTENSIONS_STORAGE_PATH
,
disabledExtensions
);
}
private
_getExtensions
(
storageId
:
string
,
scope
:
StorageScope
):
IExtensionIdentifier
[]
{
if
(
scope
===
StorageScope
.
WORKSPACE
&&
!
this
.
hasWorkspace
)
{
private
_getExtensions
(
storageId
:
string
):
IExtensionIdentifier
[]
{
if
(
!
this
.
hasWorkspace
)
{
return
[];
}
return
this
.
storageManger
.
get
(
storageId
,
scope
);
return
this
.
storageManger
.
get
(
storageId
,
StorageScope
.
WORKSPACE
);
}
private
_setExtensions
(
storageId
:
string
,
extensions
:
IExtensionIdentifier
[]
,
scope
:
StorageScope
):
void
{
this
.
storageManger
.
set
(
storageId
,
extensions
,
scope
);
private
_setExtensions
(
storageId
:
string
,
extensions
:
IExtensionIdentifier
[]):
void
{
this
.
storageManger
.
set
(
storageId
,
extensions
,
StorageScope
.
WORKSPACE
);
}
private
async
onDidChange
Storage
(
extensionIdentifiers
:
IExtensionIdentifier
[]
):
Promise
<
void
>
{
private
async
onDidChange
Extensions
(
extensionIdentifiers
:
ReadonlyArray
<
IExtensionIdentifier
>
):
Promise
<
void
>
{
const
installedExtensions
=
await
this
.
extensionManagementService
.
getInstalled
();
const
extensions
=
installedExtensions
.
filter
(
installedExtension
=>
extensionIdentifiers
.
some
(
identifier
=>
areSameExtensions
(
identifier
,
installedExtension
.
identifier
)));
this
.
_onEnablementChanged
.
fire
(
extensions
);
...
...
@@ -301,80 +286,9 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
}
private
_reset
(
extension
:
IExtensionIdentifier
)
{
this
.
_removeFromDisabledExtensions
(
extension
,
StorageScope
.
WORKSPACE
);
this
.
_removeFromEnabledExtensions
(
extension
,
StorageScope
.
WORKSPACE
);
this
.
_removeFromDisabledExtensions
(
extension
,
StorageScope
.
GLOBAL
);
}
}
class
StorageManager
extends
Disposable
{
private
storage
:
{
[
key
:
string
]:
string
}
=
Object
.
create
(
null
);
private
_onDidChange
:
Emitter
<
IExtensionIdentifier
[]
>
=
this
.
_register
(
new
Emitter
<
IExtensionIdentifier
[]
>
());
readonly
onDidChange
:
Event
<
IExtensionIdentifier
[]
>
=
this
.
_onDidChange
.
event
;
constructor
(
private
storageService
:
IStorageService
)
{
super
();
this
.
_register
(
storageService
.
onDidChangeStorage
(
e
=>
this
.
onDidStorageChange
(
e
)));
}
get
(
key
:
string
,
scope
:
StorageScope
):
IExtensionIdentifier
[]
{
let
value
:
string
;
if
(
scope
===
StorageScope
.
GLOBAL
)
{
if
(
isUndefinedOrNull
(
this
.
storage
[
key
]))
{
this
.
storage
[
key
]
=
this
.
_get
(
key
,
scope
);
}
value
=
this
.
storage
[
key
];
}
else
{
value
=
this
.
_get
(
key
,
scope
);
}
return
JSON
.
parse
(
value
);
}
set
(
key
:
string
,
value
:
IExtensionIdentifier
[],
scope
:
StorageScope
):
void
{
let
newValue
:
string
=
JSON
.
stringify
(
value
.
map
(({
id
,
uuid
})
=>
(
<
IExtensionIdentifier
>
{
id
,
uuid
})));
const
oldValue
=
this
.
_get
(
key
,
scope
);
if
(
oldValue
!==
newValue
)
{
if
(
scope
===
StorageScope
.
GLOBAL
)
{
if
(
value
.
length
)
{
this
.
storage
[
key
]
=
newValue
;
}
else
{
delete
this
.
storage
[
key
];
}
}
this
.
_set
(
key
,
value
.
length
?
newValue
:
undefined
,
scope
);
}
}
private
onDidStorageChange
(
workspaceStorageChangeEvent
:
IWorkspaceStorageChangeEvent
):
void
{
if
(
workspaceStorageChangeEvent
.
scope
===
StorageScope
.
GLOBAL
)
{
if
(
!
isUndefinedOrNull
(
this
.
storage
[
workspaceStorageChangeEvent
.
key
]))
{
const
newValue
=
this
.
_get
(
workspaceStorageChangeEvent
.
key
,
workspaceStorageChangeEvent
.
scope
);
if
(
newValue
!==
this
.
storage
[
workspaceStorageChangeEvent
.
key
])
{
const
oldValues
=
this
.
get
(
workspaceStorageChangeEvent
.
key
,
workspaceStorageChangeEvent
.
scope
);
delete
this
.
storage
[
workspaceStorageChangeEvent
.
key
];
const
newValues
=
this
.
get
(
workspaceStorageChangeEvent
.
key
,
workspaceStorageChangeEvent
.
scope
);
const
added
=
oldValues
.
filter
(
oldValue
=>
!
newValues
.
some
(
newValue
=>
areSameExtensions
(
oldValue
,
newValue
)));
const
removed
=
newValues
.
filter
(
newValue
=>
!
oldValues
.
some
(
oldValue
=>
areSameExtensions
(
oldValue
,
newValue
)));
if
(
added
.
length
||
removed
.
length
)
{
this
.
_onDidChange
.
fire
([...
added
,
...
removed
]);
}
}
}
}
}
private
_get
(
key
:
string
,
scope
:
StorageScope
):
string
{
return
this
.
storageService
.
get
(
key
,
scope
,
'
[]
'
);
}
private
_set
(
key
:
string
,
value
:
string
|
undefined
,
scope
:
StorageScope
):
void
{
if
(
value
)
{
this
.
storageService
.
store
(
key
,
value
,
scope
);
}
else
{
this
.
storageService
.
remove
(
key
,
scope
);
}
this
.
_removeFromWorkspaceDisabledExtensions
(
extension
);
this
.
_removeFromWorkspaceEnabledExtensions
(
extension
);
this
.
globalExtensionEnablementService
.
enableExtension
(
extension
);
}
}
...
...
src/vs/workbench/services/extensionManagement/test/electron-browser/extensionEnablementService.test.ts
浏览文件 @
e1f1744c
...
...
@@ -11,7 +11,7 @@ import { TestInstantiationService } from 'vs/platform/instantiation/test/common/
import
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
IWorkspaceContextService
,
WorkbenchState
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IWorkbenchEnvironmentService
}
from
'
vs/workbench/services/environment/common/environmentService
'
;
import
{
IStorageService
,
InMemoryStorageService
,
StorageScope
}
from
'
vs/platform/storage/common/storage
'
;
import
{
IStorageService
,
InMemoryStorageService
}
from
'
vs/platform/storage/common/storage
'
;
import
{
IExtensionContributions
,
ExtensionType
,
IExtension
}
from
'
vs/platform/extensions/common/extensions
'
;
import
{
isUndefinedOrNull
}
from
'
vs/base/common/types
'
;
import
{
areSameExtensions
}
from
'
vs/platform/extensionManagement/common/extensionManagementUtil
'
;
...
...
@@ -22,8 +22,9 @@ import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
import
{
assign
}
from
'
vs/base/common/objects
'
;
import
{
TestConfigurationService
}
from
'
vs/platform/configuration/test/common/testConfigurationService
'
;
import
{
productService
}
from
'
vs/workbench/test/workbenchTestServices
'
;
import
{
GlobalExtensionEnablementService
}
from
'
vs/platform/extensionManagement/common/extensionEnablementService
'
;
function
s
torageService
(
instantiationService
:
TestInstantiationService
):
IStorageService
{
function
createS
torageService
(
instantiationService
:
TestInstantiationService
):
IStorageService
{
let
service
=
instantiationService
.
get
(
IStorageService
);
if
(
!
service
)
{
let
workspaceContextService
=
instantiationService
.
get
(
IWorkspaceContextService
);
...
...
@@ -39,10 +40,12 @@ function storageService(instantiationService: TestInstantiationService): IStorag
export
class
TestExtensionEnablementService
extends
ExtensionEnablementService
{
constructor
(
instantiationService
:
TestInstantiationService
)
{
const
storageService
=
createStorageService
(
instantiationService
);
const
extensionManagementService
=
instantiationService
.
get
(
IExtensionManagementService
)
||
instantiationService
.
stub
(
IExtensionManagementService
,
{
onDidInstallExtension
:
new
Emitter
<
DidInstallExtensionEvent
>
().
event
,
onDidUninstallExtension
:
new
Emitter
<
DidUninstallExtensionEvent
>
().
event
}
as
IExtensionManagementService
);
const
extensionManagementServerService
=
instantiationService
.
get
(
IExtensionManagementServerService
)
||
instantiationService
.
stub
(
IExtensionManagementServerService
,
<
IExtensionManagementServerService
>
{
localExtensionManagementServer
:
{
extensionManagementService
}
});
super
(
storageService
(
instantiationService
),
storageService
,
new
GlobalExtensionEnablementService
(
storageService
),
instantiationService
.
get
(
IWorkspaceContextService
),
instantiationService
.
get
(
IWorkbenchEnvironmentService
)
||
instantiationService
.
stub
(
IWorkbenchEnvironmentService
,
{
configuration
:
Object
.
create
(
null
)
}
as
IWorkbenchEnvironmentService
),
extensionManagementService
,
...
...
@@ -53,13 +56,13 @@ export class TestExtensionEnablementService extends ExtensionEnablementService {
}
public
reset
():
void
{
let
extensions
=
this
.
_getDisabledExtensions
(
StorageScope
.
GLOBAL
);
for
(
const
e
of
this
.
_get
DisabledExtensions
(
StorageScope
.
WORKSPACE
))
{
let
extensions
=
this
.
globalExtensionEnablementService
.
getDisabledExtensions
(
);
for
(
const
e
of
this
.
_get
WorkspaceDisabledExtensions
(
))
{
if
(
!
extensions
.
some
(
r
=>
areSameExtensions
(
r
,
e
)))
{
extensions
.
push
(
e
);
}
}
const
workspaceEnabledExtensions
=
this
.
_get
EnabledExtensions
(
StorageScope
.
WORKSPACE
);
const
workspaceEnabledExtensions
=
this
.
_get
WorkspaceEnabledExtensions
(
);
if
(
workspaceEnabledExtensions
.
length
)
{
extensions
=
extensions
.
filter
(
r
=>
!
workspaceEnabledExtensions
.
some
(
e
=>
areSameExtensions
(
e
,
r
)));
}
...
...
src/vs/workbench/workbench.common.main.ts
浏览文件 @
e1f1744c
...
...
@@ -87,7 +87,8 @@ import 'vs/workbench/services/filesConfiguration/common/filesConfigurationServic
import
{
registerSingleton
}
from
'
vs/platform/instantiation/common/extensions
'
;
import
{
ExtensionGalleryService
}
from
'
vs/platform/extensionManagement/common/extensionGalleryService
'
;
import
{
IExtensionGalleryService
}
from
'
vs/platform/extensionManagement/common/extensionManagement
'
;
import
{
GlobalExtensionEnablementService
}
from
'
vs/platform/extensionManagement/common/extensionEnablementService
'
;
import
{
IExtensionGalleryService
,
IGlobalExtensionEnablementService
}
from
'
vs/platform/extensionManagement/common/extensionManagement
'
;
import
{
ContextViewService
}
from
'
vs/platform/contextview/browser/contextViewService
'
;
import
{
IContextViewService
}
from
'
vs/platform/contextview/browser/contextView
'
;
import
{
IListService
,
ListService
}
from
'
vs/platform/list/browser/listService
'
;
...
...
@@ -110,6 +111,7 @@ import { DownloadService } from 'vs/platform/download/common/downloadService';
import
{
OpenerService
}
from
'
vs/editor/browser/services/openerService
'
;
import
{
IOpenerService
}
from
'
vs/platform/opener/common/opener
'
;
registerSingleton
(
IGlobalExtensionEnablementService
,
GlobalExtensionEnablementService
);
registerSingleton
(
IExtensionGalleryService
,
ExtensionGalleryService
,
true
);
registerSingleton
(
IContextViewService
,
ContextViewService
,
true
);
registerSingleton
(
IListService
,
ListService
,
true
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录