Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
46b97c73
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,发现更多精彩内容 >>
提交
46b97c73
编写于
4月 02, 2019
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#47763 Use fileservice to read user config
上级
ef74aa96
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
83 addition
and
7 deletion
+83
-7
src/vs/platform/configuration/node/configuration.ts
src/vs/platform/configuration/node/configuration.ts
+73
-6
src/vs/workbench/services/configuration/node/configuration.ts
...vs/workbench/services/configuration/node/configuration.ts
+10
-1
未找到文件。
src/vs/platform/configuration/node/configuration.ts
浏览文件 @
46b97c73
...
...
@@ -10,8 +10,9 @@ import { ConfigWatcher } from 'vs/base/node/config';
import
{
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
import
{
RunOnceScheduler
}
from
'
vs/base/common/async
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
IFileService
,
FileChangesEvent
}
from
'
vs/platform/files/common/files
'
;
import
{
IFileService
,
FileChangesEvent
,
FileChangeType
}
from
'
vs/platform/files/common/files
'
;
import
*
as
resources
from
'
vs/base/common/resources
'
;
import
{
IDisposable
}
from
'
vscode-xterm
'
;
export
class
NodeBasedUserConfiguration
extends
Disposable
{
...
...
@@ -62,6 +63,10 @@ export class FileServiceBasedUserConfiguration extends Disposable {
protected
readonly
_onDidChangeConfiguration
:
Emitter
<
ConfigurationModel
>
=
this
.
_register
(
new
Emitter
<
ConfigurationModel
>
());
readonly
onDidChangeConfiguration
:
Event
<
ConfigurationModel
>
=
this
.
_onDidChangeConfiguration
.
event
;
private
fileWatcherDisposable
:
IDisposable
=
Disposable
.
None
;
private
directoryWatcherDisposable
:
IDisposable
=
Disposable
.
None
;
private
exists
:
boolean
=
false
;
constructor
(
private
readonly
configurationResource
:
URI
,
private
readonly
fileService
:
IFileService
...
...
@@ -70,8 +75,44 @@ export class FileServiceBasedUserConfiguration extends Disposable {
this
.
_register
(
fileService
.
onFileChanges
(
e
=>
this
.
handleFileEvents
(
e
)));
this
.
reloadConfigurationScheduler
=
this
.
_register
(
new
RunOnceScheduler
(()
=>
this
.
reload
().
then
(
configurationModel
=>
this
.
_onDidChangeConfiguration
.
fire
(
configurationModel
)),
50
));
this
.
watchResource
();
this
.
_register
(
toDisposable
(()
=>
this
.
stopWatchingResource
()));
this
.
watchDirectory
();
this
.
_register
(
toDisposable
(()
=>
this
.
stopWatchingDirectory
()));
fileService
.
exists
(
this
.
configurationResource
)
.
then
(
exists
=>
{
this
.
exists
=
exists
;
if
(
this
.
exists
)
{
// If exists stop watching directory
this
.
stopWatchingDirectory
();
}
else
{
// Otherwise stop watching resource
this
.
stopWatchingResource
();
}
});
}
private
watchResource
():
void
{
this
.
fileService
.
watch
(
this
.
configurationResource
);
this
.
_register
(
toDisposable
(()
=>
this
.
fileService
.
unwatch
(
this
.
configurationResource
)));
this
.
fileWatcherDisposable
=
toDisposable
(()
=>
this
.
fileService
.
unwatch
(
this
.
configurationResource
));
}
private
stopWatchingResource
():
void
{
this
.
fileWatcherDisposable
.
dispose
();
this
.
fileWatcherDisposable
=
Disposable
.
None
;
}
private
watchDirectory
():
void
{
const
directory
=
resources
.
dirname
(
this
.
configurationResource
);
this
.
fileService
.
watch
(
directory
);
this
.
directoryWatcherDisposable
=
toDisposable
(()
=>
this
.
fileService
.
unwatch
(
directory
));
}
private
stopWatchingDirectory
():
void
{
this
.
directoryWatcherDisposable
.
dispose
();
this
.
directoryWatcherDisposable
=
Disposable
.
None
;
}
initialize
():
Promise
<
ConfigurationModel
>
{
...
...
@@ -90,13 +131,39 @@ export class FileServiceBasedUserConfiguration extends Disposable {
});
}
private
handleFileEvents
(
event
:
FileChangesEvent
):
void
{
private
async
handleFileEvents
(
event
:
FileChangesEvent
):
Promise
<
void
>
{
const
events
=
event
.
changes
;
let
affectedByChanges
=
false
;
// Find changes that affect workspace file
for
(
let
i
=
0
,
len
=
events
.
length
;
i
<
len
&&
!
affectedByChanges
;
i
++
)
{
affectedByChanges
=
resources
.
isEqual
(
this
.
configurationResource
,
events
[
i
].
resource
);
// Find changes that affect the resource
for
(
const
event
of
events
)
{
affectedByChanges
=
resources
.
isEqual
(
this
.
configurationResource
,
event
.
resource
);
if
(
affectedByChanges
)
{
if
(
event
.
type
!==
FileChangeType
.
DELETED
)
{
this
.
exists
=
false
;
// Resource deleted. Stop watching resource and start watching directory
this
.
stopWatchingResource
();
this
.
watchDirectory
();
}
break
;
}
}
if
(
!
affectedByChanges
&&
!
this
.
exists
)
{
// Find changes if resource is added
const
directory
=
resources
.
dirname
(
this
.
configurationResource
);
for
(
const
{
resource
}
of
events
)
{
if
(
resources
.
isEqual
(
directory
,
resource
))
{
this
.
exists
=
affectedByChanges
=
await
this
.
fileService
.
exists
(
this
.
configurationResource
);
if
(
affectedByChanges
)
{
// Resource is created. Stop watching directory and start watching resource
this
.
stopWatchingDirectory
();
this
.
watchResource
();
}
break
;
}
}
}
if
(
affectedByChanges
)
{
...
...
src/vs/workbench/services/configuration/node/configuration.ts
浏览文件 @
46b97c73
...
...
@@ -29,7 +29,9 @@ import { FileServiceBasedUserConfiguration, NodeBasedUserConfiguration } from 'v
export
class
LocalUserConfiguration
extends
Disposable
{
private
readonly
userConfigurationResource
:
URI
;
private
userConfiguration
:
NodeBasedUserConfiguration
|
FileServiceBasedUserConfiguration
;
private
changeDisposable
:
IDisposable
=
Disposable
.
None
;
private
readonly
_onDidChangeConfiguration
:
Emitter
<
ConfigurationModel
>
=
this
.
_register
(
new
Emitter
<
ConfigurationModel
>
());
public
readonly
onDidChangeConfiguration
:
Event
<
ConfigurationModel
>
=
this
.
_onDidChangeConfiguration
.
event
;
...
...
@@ -38,8 +40,9 @@ export class LocalUserConfiguration extends Disposable {
environmentService
:
IEnvironmentService
)
{
super
();
this
.
userConfigurationResource
=
URI
.
file
(
environmentService
.
appSettingsPath
);
this
.
userConfiguration
=
this
.
_register
(
new
NodeBasedUserConfiguration
(
environmentService
.
appSettingsPath
));
this
.
_register
(
this
.
userConfiguration
.
onDidChangeConfiguration
(
configurationModel
=>
this
.
_onDidChangeConfiguration
.
fire
(
configurationModel
)));
this
.
changeDisposable
=
this
.
_register
(
this
.
userConfiguration
.
onDidChangeConfiguration
(
configurationModel
=>
this
.
_onDidChangeConfiguration
.
fire
(
configurationModel
)));
}
initialize
():
Promise
<
ConfigurationModel
>
{
...
...
@@ -51,6 +54,12 @@ export class LocalUserConfiguration extends Disposable {
}
async
adopt
(
fileService
:
IFileService
):
Promise
<
ConfigurationModel
|
null
>
{
if
(
this
.
userConfiguration
instanceof
NodeBasedUserConfiguration
)
{
this
.
userConfiguration
.
dispose
();
dispose
(
this
.
changeDisposable
);
this
.
userConfiguration
=
this
.
_register
(
new
FileServiceBasedUserConfiguration
(
this
.
userConfigurationResource
,
fileService
));
this
.
changeDisposable
=
this
.
_register
(
this
.
userConfiguration
.
onDidChangeConfiguration
(
configurationModel
=>
this
.
_onDidChangeConfiguration
.
fire
(
configurationModel
)));
}
return
null
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录