Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
c4bbbe7e
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,发现更多精彩内容 >>
提交
c4bbbe7e
编写于
11月 23, 2018
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #62821
上级
c2a379f5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
9 addition
and
26 deletion
+9
-26
src/tsconfig.strictNullChecks.json
src/tsconfig.strictNullChecks.json
+2
-1
src/vs/base/node/config.ts
src/vs/base/node/config.ts
+6
-19
src/vs/base/test/node/config.test.ts
src/vs/base/test/node/config.test.ts
+1
-6
未找到文件。
src/tsconfig.strictNullChecks.json
浏览文件 @
c4bbbe7e
...
...
@@ -735,7 +735,8 @@
"./vs/workbench/services/themes/common/workbenchThemeService.ts"
,
"./vs/workbench/services/title/common/titleService.ts"
,
"./vs/workbench/services/workspace/common/workspaceEditing.ts"
,
"./vs/workbench/test/electron-browser/api/mock.ts"
"./vs/workbench/test/electron-browser/api/mock.ts"
,
"./vs/base/node/config.ts"
],
"exclude"
:
[
"./typings/require-monaco.d.ts"
...
...
src/vs/base/node/config.ts
浏览文件 @
c4bbbe7e
...
...
@@ -22,12 +22,11 @@ export interface IConfigWatcher<T> {
reload
(
callback
:
(
config
:
T
)
=>
void
):
void
;
getConfig
():
T
;
getValue
<
V
>
(
key
:
string
,
fallback
?:
V
):
V
;
}
export
interface
IConfigOptions
<
T
>
{
onError
:
(
error
:
Error
|
string
)
=>
void
;
defaultConfig
?
:
T
;
defaultConfig
:
T
;
changeBufferDelay
?:
number
;
parse
?:
(
content
:
string
,
errors
:
any
[])
=>
T
;
initCallback
?:
(
config
:
T
)
=>
void
;
...
...
@@ -51,7 +50,7 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
private
readonly
_onDidUpdateConfiguration
:
Emitter
<
IConfigurationChangeEvent
<
T
>>
;
private
configName
:
string
;
constructor
(
private
_path
:
string
,
private
options
:
IConfigOptions
<
T
>
=
{
changeBufferDelay
:
0
,
defaultConfig
:
Object
.
create
(
null
),
onError
:
error
=>
console
.
error
(
error
)
})
{
constructor
(
private
_path
:
string
,
private
options
:
IConfigOptions
<
T
>
=
{
defaultConfig
:
Object
.
create
(
null
),
onError
:
error
=>
console
.
error
(
error
)
})
{
this
.
disposables
=
[];
this
.
configName
=
basename
(
this
.
_path
);
...
...
@@ -113,11 +112,11 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
try
{
this
.
parseErrors
=
[];
res
=
this
.
options
.
parse
?
this
.
options
.
parse
(
raw
,
this
.
parseErrors
)
:
json
.
parse
(
raw
,
this
.
parseErrors
);
return
res
||
this
.
options
.
defaultConfig
;
}
catch
(
error
)
{
// Ignore parsing errors
return
this
.
options
.
defaultConfig
;
}
return
res
||
this
.
options
.
defaultConfig
;
}
private
registerWatcher
():
void
{
...
...
@@ -156,7 +155,7 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
));
}
private
onConfigFileChange
(
eventType
:
string
,
filename
:
string
,
isParentFolder
:
boolean
):
void
{
private
onConfigFileChange
(
eventType
:
string
,
filename
:
string
|
undefined
,
isParentFolder
:
boolean
):
void
{
if
(
isParentFolder
)
{
// Windows: in some cases the filename contains artifacts from the absolute path
...
...
@@ -177,7 +176,7 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
}
// we can get multiple change events for one change, so we buffer through a timeout
this
.
timeoutHandle
=
global
.
setTimeout
(()
=>
this
.
reload
(),
this
.
options
.
changeBufferDelay
);
this
.
timeoutHandle
=
global
.
setTimeout
(()
=>
this
.
reload
(),
this
.
options
.
changeBufferDelay
||
0
);
}
public
reload
(
callback
?:
(
config
:
T
)
=>
void
):
void
{
...
...
@@ -200,18 +199,6 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
return
this
.
cache
;
}
public
getValue
<
V
>
(
key
:
string
,
fallback
?:
V
):
V
{
this
.
ensureLoaded
();
if
(
!
key
)
{
return
fallback
;
}
const
value
=
this
.
cache
?
(
this
.
cache
as
any
)[
key
]
:
void
0
;
return
typeof
value
!==
'
undefined
'
?
value
:
fallback
;
}
private
ensureLoaded
():
void
{
if
(
!
this
.
loaded
)
{
this
.
updateCache
(
this
.
loadSync
());
...
...
src/vs/base/test/node/config.test.ts
浏览文件 @
c4bbbe7e
...
...
@@ -46,9 +46,6 @@ suite('Config', () => {
let
config
=
watcher
.
getConfig
();
assert
.
ok
(
config
);
assert
.
equal
(
config
.
foo
,
'
bar
'
);
assert
.
equal
(
watcher
.
getValue
(
'
foo
'
),
'
bar
'
);
assert
.
equal
(
watcher
.
getValue
(
'
bar
'
),
void
0
);
assert
.
equal
(
watcher
.
getValue
(
'
bar
'
,
'
fallback
'
),
'
fallback
'
);
assert
.
ok
(
!
watcher
.
hasParseErrors
);
watcher
.
dispose
();
...
...
@@ -144,20 +141,18 @@ suite('Config', () => {
testFile
(
'
config
'
,
'
config.json
'
).
then
(
res
=>
{
fs
.
writeFileSync
(
res
.
testFile
,
'
// my comment
\n
{ "foo": "bar" }
'
);
let
watcher
=
new
ConfigWatcher
<
{
foo
:
string
;
}
>
(
res
.
testFile
,
{
changeBufferDelay
:
100
,
onError
:
console
.
error
});
let
watcher
=
new
ConfigWatcher
<
{
foo
:
string
;
}
>
(
res
.
testFile
,
{
changeBufferDelay
:
100
,
onError
:
console
.
error
,
defaultConfig
:
void
0
});
watcher
.
getConfig
();
// ensure we are in sync
fs
.
writeFileSync
(
res
.
testFile
,
'
// my comment
\n
{ "foo": "changed" }
'
);
// still old values because change is not bubbling yet
assert
.
equal
(
watcher
.
getConfig
().
foo
,
'
bar
'
);
assert
.
equal
(
watcher
.
getValue
(
'
foo
'
),
'
bar
'
);
// force a load from disk
watcher
.
reload
(
config
=>
{
assert
.
equal
(
config
.
foo
,
'
changed
'
);
assert
.
equal
(
watcher
.
getConfig
().
foo
,
'
changed
'
);
assert
.
equal
(
watcher
.
getValue
(
'
foo
'
),
'
changed
'
);
watcher
.
dispose
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录