Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
a8b0050c
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
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,发现更多精彩内容 >>
提交
a8b0050c
编写于
9月 21, 2016
作者:
I
isidor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
configuration resolver service: also resolve configuration variables
上级
eae1b662
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
39 addition
and
21 deletion
+39
-21
src/vs/workbench/electron-browser/workbench.ts
src/vs/workbench/electron-browser/workbench.ts
+2
-1
src/vs/workbench/services/configurationResolver/node/configurationResolverService.ts
...onfigurationResolver/node/configurationResolverService.ts
+37
-20
未找到文件。
src/vs/workbench/electron-browser/workbench.ts
浏览文件 @
a8b0050c
...
...
@@ -391,7 +391,8 @@ export class Workbench implements IPartService {
serviceCollection
.
set
(
IConfigurationEditingService
,
this
.
instantiationService
.
createInstance
(
ConfigurationEditingService
));
// Configuration Resolver
const
configurationResolverService
=
this
.
instantiationService
.
createInstance
(
ConfigurationResolverService
);
const
workspace
=
this
.
contextService
.
getWorkspace
();
const
configurationResolverService
=
this
.
instantiationService
.
createInstance
(
ConfigurationResolverService
,
workspace
?
workspace
.
resource
:
null
,
process
.
env
);
serviceCollection
.
set
(
IConfigurationResolverService
,
configurationResolverService
);
// Quick open service (quick open controller)
...
...
src/vs/workbench/services/configurationResolver/node/configurationResolverService.ts
浏览文件 @
a8b0050c
...
...
@@ -5,10 +5,11 @@
import
*
as
paths
from
'
vs/base/common/paths
'
;
import
*
as
types
from
'
vs/base/common/types
'
;
import
uri
from
'
vs/base/common/uri
'
;
import
{
IStringDictionary
}
from
'
vs/base/common/collections
'
;
import
{
IConfigurationResolverService
}
from
'
vs/workbench/services/configurationResolver/common/configurationResolver
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
asFileEditorInput
}
from
'
vs/workbench/common/editor
'
;
...
...
@@ -18,16 +19,16 @@ export class ConfigurationResolverService implements IConfigurationResolverServi
private
_execPath
:
string
;
constructor
(
workspaceRoot
:
uri
,
envVariables
:
{
[
key
:
string
]:
string
},
@
IWorkbenchEditorService
private
editorService
:
IWorkbenchEditorService
,
@
I
WorkspaceContextService
private
contextService
:
IWorkspaceContex
tService
,
@
I
EnvironmentService
private
environmentService
:
IEnvironment
Service
@
I
EnvironmentService
private
environmentService
:
IEnvironmen
tService
,
@
I
ConfigurationService
private
configurationService
:
IConfiguration
Service
)
{
const
workspace
=
contextService
.
getWorkspace
();
const
fsPath
=
workspace
?
workspace
.
resource
.
fsPath
:
''
;
this
.
_workspaceRoot
=
paths
.
normalize
(
fsPath
,
true
);
this
.
_workspaceRoot
=
paths
.
normalize
(
workspaceRoot
?
workspaceRoot
.
fsPath
:
''
,
true
);
this
.
_execPath
=
environmentService
.
execPath
;
Object
.
keys
(
process
.
env
).
forEach
(
key
=>
{
this
[
`env.
${
key
}
`
]
=
process
.
env
[
key
];
Object
.
keys
(
envVariables
).
forEach
(
key
=>
{
this
[
`env.
${
key
}
`
]
=
envVariables
[
key
];
});
}
...
...
@@ -85,9 +86,9 @@ export class ConfigurationResolverService implements IConfigurationResolverServi
if
(
types
.
isString
(
value
))
{
return
this
.
resolveString
(
value
);
}
else
if
(
types
.
isArray
(
value
))
{
return
this
.
__
resolveArray
(
value
);
return
this
.
resolveArray
(
value
);
}
else
if
(
types
.
isObject
(
value
))
{
return
this
.
__
resolveLiteral
(
value
);
return
this
.
resolveLiteral
(
value
);
}
return
value
;
...
...
@@ -98,17 +99,17 @@ export class ConfigurationResolverService implements IConfigurationResolverServi
if
(
types
.
isString
(
value
))
{
return
this
.
resolveString
(
value
);
}
else
if
(
types
.
isArray
(
value
))
{
return
this
.
__
resolveAnyArray
(
value
);
return
this
.
resolveAnyArray
(
value
);
}
else
if
(
types
.
isObject
(
value
))
{
return
this
.
__
resolveAnyLiteral
(
value
);
return
this
.
resolveAnyLiteral
(
value
);
}
return
value
;
}
pr
otected
resolveString
(
value
:
string
):
string
{
pr
ivate
resolveString
(
value
:
string
):
string
{
let
regexp
=
/
\$\{(
.*
?)\}
/g
;
return
value
.
replace
(
regexp
,
(
match
:
string
,
name
:
string
)
=>
{
const
resolvedString
=
value
.
replace
(
regexp
,
(
match
:
string
,
name
:
string
)
=>
{
let
newValue
=
(
<
any
>
this
)[
name
];
if
(
types
.
isString
(
newValue
))
{
return
newValue
;
...
...
@@ -116,9 +117,25 @@ export class ConfigurationResolverService implements IConfigurationResolverServi
return
match
&&
match
.
indexOf
(
'
env.
'
)
>
0
?
''
:
match
;
}
});
return
this
.
resolveConfigVariable
(
resolvedString
);
}
private
resolveConfigVariable
(
value
:
string
):
string
{
let
regexp
=
/
\$\{
config
\.(
.*
?)\}
/g
;
return
value
.
replace
(
regexp
,
(
match
:
string
,
name
:
string
)
=>
{
let
config
=
this
.
configurationService
.
getConfiguration
();
let
newValue
=
new
Function
(
'
_
'
,
'
try {return _.
'
+
name
+
'
;} catch (ex) { return "";}
'
)(
config
);
if
(
types
.
isString
(
newValue
))
{
// Prevent infinite recursion and also support nested references (or tokens)
return
newValue
===
value
?
''
:
this
.
resolveString
(
newValue
);
}
else
{
return
this
.
resolve
(
newValue
)
+
''
;
}
});
}
private
__
resolveLiteral
(
values
:
IStringDictionary
<
string
|
IStringDictionary
<
string
>
|
string
[]
>
):
IStringDictionary
<
string
|
IStringDictionary
<
string
>
|
string
[]
>
{
private
resolveLiteral
(
values
:
IStringDictionary
<
string
|
IStringDictionary
<
string
>
|
string
[]
>
):
IStringDictionary
<
string
|
IStringDictionary
<
string
>
|
string
[]
>
{
let
result
:
IStringDictionary
<
string
|
IStringDictionary
<
string
>
|
string
[]
>
=
Object
.
create
(
null
);
Object
.
keys
(
values
).
forEach
(
key
=>
{
let
value
=
values
[
key
];
...
...
@@ -127,8 +144,8 @@ export class ConfigurationResolverService implements IConfigurationResolverServi
return
result
;
}
private
__
resolveAnyLiteral
<
T
>
(
values
:
T
):
T
;
private
__
resolveAnyLiteral
<
T
>
(
values
:
any
):
any
{
private
resolveAnyLiteral
<
T
>
(
values
:
T
):
T
;
private
resolveAnyLiteral
<
T
>
(
values
:
any
):
any
{
let
result
:
IStringDictionary
<
string
|
IStringDictionary
<
string
>
|
string
[]
>
=
Object
.
create
(
null
);
Object
.
keys
(
values
).
forEach
(
key
=>
{
let
value
=
values
[
key
];
...
...
@@ -137,12 +154,12 @@ export class ConfigurationResolverService implements IConfigurationResolverServi
return
result
;
}
private
__
resolveArray
(
value
:
string
[]):
string
[]
{
private
resolveArray
(
value
:
string
[]):
string
[]
{
return
value
.
map
(
s
=>
this
.
resolveString
(
s
));
}
private
__
resolveAnyArray
<
T
>
(
value
:
T
[]):
T
[];
private
__
resolveAnyArray
(
value
:
any
[]):
any
[]
{
private
resolveAnyArray
<
T
>
(
value
:
T
[]):
T
[];
private
resolveAnyArray
(
value
:
any
[]):
any
[]
{
return
value
.
map
(
s
=>
this
.
resolveAny
(
s
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录