Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
6229e7a5
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
6229e7a5
编写于
4月 09, 2021
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change to async
上级
8df88488
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
60 addition
and
65 deletion
+60
-65
src/vs/workbench/services/configuration/browser/configurationService.ts
...ch/services/configuration/browser/configurationService.ts
+60
-65
未找到文件。
src/vs/workbench/services/configuration/browser/configurationService.ts
浏览文件 @
6229e7a5
...
...
@@ -141,8 +141,9 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat
// Workspace Context Service Impl
public
getCompleteWorkspace
():
Promise
<
Workspace
>
{
return
this
.
completeWorkspaceBarrier
.
wait
().
then
(()
=>
this
.
getWorkspace
());
public
async
getCompleteWorkspace
():
Promise
<
Workspace
>
{
await
this
.
completeWorkspaceBarrier
.
wait
();
return
this
.
getWorkspace
();
}
public
getWorkspace
():
Workspace
{
...
...
@@ -176,10 +177,9 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat
return
this
.
updateFolders
([],
foldersToRemove
);
}
public
updateFolders
(
foldersToAdd
:
IWorkspaceFolderCreationData
[],
foldersToRemove
:
URI
[],
index
?:
number
):
Promise
<
void
>
{
return
this
.
cyclicDependency
.
then
(()
=>
{
return
this
.
workspaceEditingQueue
.
queue
(()
=>
this
.
doUpdateFolders
(
foldersToAdd
,
foldersToRemove
,
index
));
});
public
async
updateFolders
(
foldersToAdd
:
IWorkspaceFolderCreationData
[],
foldersToRemove
:
URI
[],
index
?:
number
):
Promise
<
void
>
{
await
this
.
cyclicDependency
;
return
this
.
workspaceEditingQueue
.
queue
(()
=>
this
.
doUpdateFolders
(
foldersToAdd
,
foldersToRemove
,
index
));
}
public
isInsideWorkspace
(
resource
:
URI
):
boolean
{
...
...
@@ -274,11 +274,10 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat
return
Promise
.
resolve
(
undefined
);
}
private
setFolders
(
folders
:
IStoredWorkspaceFolder
[]):
Promise
<
void
>
{
return
this
.
cyclicDependency
.
then
(()
=>
{
return
this
.
workspaceConfiguration
.
setFolders
(
folders
,
this
.
jsonEditingService
)
.
then
(()
=>
this
.
onWorkspaceConfigurationChanged
());
});
private
async
setFolders
(
folders
:
IStoredWorkspaceFolder
[]):
Promise
<
void
>
{
await
this
.
cyclicDependency
;
await
this
.
workspaceConfiguration
.
setFolders
(
folders
,
this
.
jsonEditingService
);
return
this
.
onWorkspaceConfigurationChanged
();
}
private
contains
(
resources
:
URI
[],
toCheck
:
URI
):
boolean
{
...
...
@@ -479,11 +478,11 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat
}
}
private
updateWorkspaceAndInitializeConfiguration
(
workspace
:
Workspace
):
Promise
<
void
>
{
private
async
updateWorkspaceAndInitializeConfiguration
(
workspace
:
Workspace
):
Promise
<
void
>
{
const
hasWorkspaceBefore
=
!!
this
.
workspace
;
let
previousState
:
WorkbenchState
;
let
previousState
:
WorkbenchState
|
undefined
;
let
previousWorkspacePath
:
string
|
undefined
;
let
previousFolders
:
WorkspaceFolder
[];
let
previousFolders
:
WorkspaceFolder
[]
=
[]
;
if
(
hasWorkspaceBefore
)
{
previousState
=
this
.
getWorkbenchState
();
...
...
@@ -494,32 +493,31 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat
this
.
workspace
=
workspace
;
}
return
this
.
initializeConfiguration
().
then
(()
=>
{
// Trigger changes after configuration initialization so that configuration is up to date.
if
(
hasWorkspaceBefore
)
{
const
newState
=
this
.
getWorkbenchState
();
if
(
previousState
&&
newState
!==
previousState
)
{
this
.
_onDidChangeWorkbenchState
.
fire
(
newState
);
}
const
newWorkspacePath
=
this
.
workspace
.
configuration
?
this
.
workspace
.
configuration
.
fsPath
:
undefined
;
if
(
previousWorkspacePath
&&
newWorkspacePath
!==
previousWorkspacePath
||
newState
!==
previousState
)
{
this
.
_onDidChangeWorkspaceName
.
fire
();
}
await
this
.
initializeConfiguration
();
const
folderChanges
=
this
.
compareFolders
(
previousFolders
,
this
.
workspace
.
folders
);
if
(
folderChanges
&&
(
folderChanges
.
added
.
length
||
folderChanges
.
removed
.
length
||
folderChanges
.
changed
.
length
))
{
this
.
_onDidChangeWorkspaceFolders
.
fire
(
folderChanges
);
}
// Trigger changes after configuration initialization so that configuration is up to date.
if
(
hasWorkspaceBefore
)
{
const
newState
=
this
.
getWorkbenchState
();
if
(
previousState
&&
newState
!==
previousState
)
{
this
.
_onDidChangeWorkbenchState
.
fire
(
newState
);
}
const
newWorkspacePath
=
this
.
workspace
.
configuration
?
this
.
workspace
.
configuration
.
fsPath
:
undefined
;
if
(
previousWorkspacePath
&&
newWorkspacePath
!==
previousWorkspacePath
||
newState
!==
previousState
)
{
this
.
_onDidChangeWorkspaceName
.
fire
();
}
if
(
!
this
.
localUserConfiguration
.
hasTasksLoaded
)
{
// Reload local user configuration again to load user tasks
this
.
_
register
(
runWhenIdle
(()
=>
this
.
reloadLocalUserConfiguration
(),
5000
)
);
const
folderChanges
=
this
.
compareFolders
(
previousFolders
,
this
.
workspace
.
folders
);
if
(
folderChanges
&&
(
folderChanges
.
added
.
length
||
folderChanges
.
removed
.
length
||
folderChanges
.
changed
.
length
))
{
this
.
_
onDidChangeWorkspaceFolders
.
fire
(
folderChanges
);
}
});
}
if
(
!
this
.
localUserConfiguration
.
hasTasksLoaded
)
{
// Reload local user configuration again to load user tasks
this
.
_register
(
runWhenIdle
(()
=>
this
.
reloadLocalUserConfiguration
(),
5000
));
}
}
private
compareFolders
(
currentFolders
:
IWorkspaceFolder
[],
newFolders
:
IWorkspaceFolder
[]):
IWorkspaceFoldersChangeEvent
{
...
...
@@ -545,13 +543,14 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat
await
this
.
loadConfiguration
(
local
,
remote
);
}
private
initializeUserConfiguration
():
Promise
<
{
local
:
ConfigurationModel
,
remote
:
ConfigurationModel
}
>
{
return
Promise
.
all
([
this
.
localUserConfiguration
.
initialize
(),
this
.
remoteUserConfiguration
?
this
.
remoteUserConfiguration
.
initialize
()
:
Promise
.
resolve
(
new
ConfigurationModel
())])
.
then
(([
local
,
remote
])
=>
({
local
,
remote
}))
;
private
async
initializeUserConfiguration
():
Promise
<
{
local
:
ConfigurationModel
,
remote
:
ConfigurationModel
}
>
{
const
[
local
,
remote
]
=
await
Promise
.
all
([
this
.
localUserConfiguration
.
initialize
(),
this
.
remoteUserConfiguration
?
this
.
remoteUserConfiguration
.
initialize
()
:
Promise
.
resolve
(
new
ConfigurationModel
())]);
return
{
local
,
remote
}
;
}
private
reloadUserConfiguration
():
Promise
<
{
local
:
ConfigurationModel
,
remote
:
ConfigurationModel
}
>
{
return
Promise
.
all
([
this
.
reloadLocalUserConfiguration
(
true
),
this
.
reloadRemoteUserConfiguration
(
true
)]).
then
(([
local
,
remote
])
=>
({
local
,
remote
}));
private
async
reloadUserConfiguration
():
Promise
<
{
local
:
ConfigurationModel
,
remote
:
ConfigurationModel
}
>
{
const
[
local
,
remote
]
=
await
Promise
.
all
([
this
.
reloadLocalUserConfiguration
(
true
),
this
.
reloadRemoteUserConfiguration
(
true
)]);
return
{
local
,
remote
};
}
async
reloadLocalUserConfiguration
(
donotTrigger
?:
boolean
):
Promise
<
ConfigurationModel
>
{
...
...
@@ -573,7 +572,7 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat
return
new
ConfigurationModel
();
}
private
reloadWorkspaceConfiguration
():
Promise
<
void
>
{
private
async
reloadWorkspaceConfiguration
():
Promise
<
void
>
{
const
workbenchState
=
this
.
getWorkbenchState
();
if
(
workbenchState
===
WorkbenchState
.
FOLDER
)
{
return
this
.
onWorkspaceFolderConfigurationChanged
(
this
.
workspace
.
folders
[
0
]);
...
...
@@ -581,7 +580,6 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat
if
(
workbenchState
===
WorkbenchState
.
WORKSPACE
)
{
return
this
.
workspaceConfiguration
.
reload
().
then
(()
=>
this
.
onWorkspaceConfigurationChanged
());
}
return
Promise
.
resolve
(
undefined
);
}
private
reloadWorkspaceFolderConfiguration
(
folder
:
IWorkspaceFolder
):
Promise
<
void
>
{
...
...
@@ -823,44 +821,41 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat
return
validWorkspaceFolders
;
}
private
writeConfigurationValue
(
key
:
string
,
value
:
any
,
target
:
ConfigurationTarget
,
overrides
:
IConfigurationOverrides
|
undefined
,
donotNotifyError
:
boolean
):
Promise
<
void
>
{
private
async
writeConfigurationValue
(
key
:
string
,
value
:
any
,
target
:
ConfigurationTarget
,
overrides
:
IConfigurationOverrides
|
undefined
,
donotNotifyError
:
boolean
):
Promise
<
void
>
{
if
(
target
===
ConfigurationTarget
.
DEFAULT
)
{
return
Promise
.
reject
(
new
Error
(
'
Invalid configuration target
'
)
);
throw
new
Error
(
'
Invalid configuration target
'
);
}
if
(
target
===
ConfigurationTarget
.
MEMORY
)
{
const
previous
=
{
data
:
this
.
_configuration
.
toData
(),
workspace
:
this
.
workspace
};
this
.
_configuration
.
updateValue
(
key
,
value
,
overrides
);
this
.
triggerConfigurationChange
({
keys
:
overrides
?.
overrideIdentifier
?
[
keyFromOverrideIdentifier
(
overrides
.
overrideIdentifier
),
key
]
:
[
key
],
overrides
:
overrides
?.
overrideIdentifier
?
[[
overrides
?.
overrideIdentifier
,
[
key
]]]
:
[]
},
previous
,
target
);
return
Promise
.
resolve
(
undefined
)
;
return
;
}
const
editableConfigurationTarget
=
this
.
toEditableConfigurationTarget
(
target
,
key
);
if
(
!
editableConfigurationTarget
)
{
return
Promise
.
reject
(
new
Error
(
'
Invalid configuration target
'
)
);
throw
new
Error
(
'
Invalid configuration target
'
);
}
if
(
editableConfigurationTarget
===
EditableConfigurationTarget
.
USER_REMOTE
&&
!
this
.
remoteUserConfiguration
)
{
return
Promise
.
reject
(
new
Error
(
'
Invalid configuration target
'
));
}
return
this
.
configurationEditingService
.
writeConfiguration
(
editableConfigurationTarget
,
{
key
,
value
},
{
scopes
:
overrides
,
donotNotifyError
})
.
then
(()
=>
{
switch
(
editableConfigurationTarget
)
{
case
EditableConfigurationTarget
.
USER_LOCAL
:
return
this
.
reloadLocalUserConfiguration
().
then
(()
=>
undefined
);
case
EditableConfigurationTarget
.
USER_REMOTE
:
return
this
.
reloadRemoteUserConfiguration
().
then
(()
=>
undefined
);
case
EditableConfigurationTarget
.
WORKSPACE
:
return
this
.
reloadWorkspaceConfiguration
();
case
EditableConfigurationTarget
.
WORKSPACE_FOLDER
:
const
workspaceFolder
=
overrides
&&
overrides
.
resource
?
this
.
workspace
.
getFolder
(
overrides
.
resource
)
:
null
;
if
(
workspaceFolder
)
{
return
this
.
reloadWorkspaceFolderConfiguration
(
workspaceFolder
);
}
throw
new
Error
(
'
Invalid configuration target
'
);
}
await
this
.
configurationEditingService
.
writeConfiguration
(
editableConfigurationTarget
,
{
key
,
value
},
{
scopes
:
overrides
,
donotNotifyError
});
switch
(
editableConfigurationTarget
)
{
case
EditableConfigurationTarget
.
USER_LOCAL
:
return
this
.
reloadLocalUserConfiguration
().
then
(()
=>
undefined
);
case
EditableConfigurationTarget
.
USER_REMOTE
:
return
this
.
reloadRemoteUserConfiguration
().
then
(()
=>
undefined
);
case
EditableConfigurationTarget
.
WORKSPACE
:
return
this
.
reloadWorkspaceConfiguration
();
case
EditableConfigurationTarget
.
WORKSPACE_FOLDER
:
const
workspaceFolder
=
overrides
&&
overrides
.
resource
?
this
.
workspace
.
getFolder
(
overrides
.
resource
)
:
null
;
if
(
workspaceFolder
)
{
return
this
.
reloadWorkspaceFolderConfiguration
(
workspaceFolder
);
}
return
Promise
.
resolve
();
});
}
}
private
deriveConfigurationTargets
(
key
:
string
,
value
:
any
,
inspect
:
IConfigurationValue
<
any
>
):
ConfigurationTarget
[]
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录