Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
85cc6ab7
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,发现更多精彩内容 >>
提交
85cc6ab7
编写于
11月 07, 2016
作者:
J
Johannes Rieken
提交者:
GitHub
11月 07, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15007 from Microsoft/joh/configInspect
WorkspaceConfiguration#inspect
上级
23e41cc6
b95c77c3
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
165 addition
and
34 deletion
+165
-34
src/vs/vscode.d.ts
src/vs/vscode.d.ts
+15
-0
src/vs/workbench/api/node/extHost.api.impl.ts
src/vs/workbench/api/node/extHost.api.impl.ts
+3
-2
src/vs/workbench/api/node/extHost.protocol.ts
src/vs/workbench/api/node/extHost.protocol.ts
+3
-6
src/vs/workbench/api/node/extHostConfiguration.ts
src/vs/workbench/api/node/extHostConfiguration.ts
+57
-13
src/vs/workbench/api/node/mainThreadConfiguration.ts
src/vs/workbench/api/node/mainThreadConfiguration.ts
+6
-2
src/vs/workbench/electron-browser/extensionHost.ts
src/vs/workbench/electron-browser/extensionHost.ts
+3
-3
src/vs/workbench/services/configuration/common/configuration.ts
.../workbench/services/configuration/common/configuration.ts
+39
-1
src/vs/workbench/test/node/api/extHostConfiguration.test.ts
src/vs/workbench/test/node/api/extHostConfiguration.test.ts
+39
-7
未找到文件。
src/vs/vscode.d.ts
浏览文件 @
85cc6ab7
...
...
@@ -2688,6 +2688,21 @@ declare module 'vscode' {
*/
has
(
section
:
string
):
boolean
;
/**
* Retrieve all information about a configuration setting. A configuration value
* often consists of a *default* value, a global or installation-wide value, and
* a workspace-specific value. The *effective* value (returned by [`get`](#WorkspaceConfiguration.get))
* is computed like this: `defaultValue` overwritten by `globalValue`,
* `globalValue` overwritten by `workspaceValue`.
*
* *Note:* The configuration name must denote a leaf in the configuration tree
* (`editor.fontSize` vs `editor`) otherwise no result is returned.
*
* @param section Configuration name, supports _dotted_ names.
* @return Information about a configuration setting or `undefined`.
*/
inspect
<
T
>
(
section
:
string
):
{
key
:
string
;
defaultValue
?:
T
;
globalValue
?:
T
;
workspaceValue
?:
T
};
/**
* Update a configuration value. A value can be changed for the current
* [workspace](#workspace.rootPath) only, or globally for all instances of the
...
...
src/vs/workbench/api/node/extHost.api.impl.ts
浏览文件 @
85cc6ab7
...
...
@@ -9,6 +9,7 @@ import { TrieMap } from 'vs/base/common/map';
import
{
score
}
from
'
vs/editor/common/modes/languageSelector
'
;
import
*
as
Platform
from
'
vs/base/common/platform
'
;
import
{
IThreadService
}
from
'
vs/workbench/services/thread/common/threadService
'
;
import
{
WorkspaceConfigurationNode
}
from
'
vs/workbench/services/configuration/common/configuration
'
;
import
*
as
errors
from
'
vs/base/common/errors
'
;
import
product
from
'
vs/platform/product
'
;
import
pkg
from
'
vs/platform/package
'
;
...
...
@@ -42,7 +43,7 @@ import * as vscode from 'vscode';
import
*
as
paths
from
'
vs/base/common/paths
'
;
import
{
realpathSync
}
from
'
fs
'
;
import
{
ITelemetryInfo
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
MainContext
,
ExtHostContext
,
InstanceCollection
,
IInitConfiguration
}
from
'
./extHost.protocol
'
;
import
{
MainContext
,
ExtHostContext
,
InstanceCollection
}
from
'
./extHost.protocol
'
;
import
*
as
languageConfiguration
from
'
vs/editor/common/modes/languageConfiguration
'
;
...
...
@@ -63,7 +64,7 @@ function proposedApiFunction<T>(extension: IExtensionDescription, fn: T): T {
/**
* This method instantiates and returns the extension API surface
*/
export
function
createApiFactory
(
initDataConfiguration
:
IInitConfiguration
,
initTelemetryInfo
:
ITelemetryInfo
,
threadService
:
IThreadService
,
extensionService
:
ExtHostExtensionService
,
contextService
:
IWorkspaceContextService
):
IExtensionApiFactory
{
export
function
createApiFactory
(
initDataConfiguration
:
WorkspaceConfigurationNode
,
initTelemetryInfo
:
ITelemetryInfo
,
threadService
:
IThreadService
,
extensionService
:
ExtHostExtensionService
,
contextService
:
IWorkspaceContextService
):
IExtensionApiFactory
{
// Addressable instances
const
col
=
new
InstanceCollection
();
...
...
src/vs/workbench/api/node/extHost.protocol.ts
浏览文件 @
85cc6ab7
...
...
@@ -29,6 +29,7 @@ import * as modes from 'vs/editor/common/modes';
import
{
IResourceEdit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
ConfigurationTarget
}
from
'
vs/workbench/services/configuration/common/configurationEditing
'
;
import
{
WorkspaceConfigurationNode
}
from
'
vs/workbench/services/configuration/common/configuration
'
;
import
{
IPickOpenEntry
,
IPickOptions
}
from
'
vs/workbench/services/quickopen/common/quickOpenService
'
;
import
{
SaveReason
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
...
...
@@ -43,10 +44,6 @@ export interface IEnvironment {
extensionTestsPath
:
string
;
}
export
interface
IInitConfiguration
{
_initConfigurationBrand
:
void
;
}
export
interface
IInitData
{
parentPid
:
number
;
environment
:
IEnvironment
;
...
...
@@ -54,7 +51,7 @@ export interface IInitData {
workspace
:
IWorkspace
;
};
extensions
:
IExtensionDescription
[];
configuration
:
IInitConfiguration
;
configuration
:
WorkspaceConfigurationNode
;
telemetryInfo
:
ITelemetryInfo
;
}
...
...
@@ -232,7 +229,7 @@ export abstract class ExtHostCommandsShape {
}
export
abstract
class
ExtHostConfigurationShape
{
$acceptConfigurationChanged
(
config
:
any
)
{
throw
ni
();
}
$acceptConfigurationChanged
(
config
:
WorkspaceConfigurationNode
)
{
throw
ni
();
}
}
export
abstract
class
ExtHostDiagnosticsShape
{
...
...
src/vs/workbench/api/node/extHostConfiguration.ts
浏览文件 @
85cc6ab7
...
...
@@ -9,24 +9,25 @@ import Event, { Emitter } from 'vs/base/common/event';
import
{
WorkspaceConfiguration
}
from
'
vscode
'
;
import
{
ExtHostConfigurationShape
,
MainThreadConfigurationShape
}
from
'
./extHost.protocol
'
;
import
{
ConfigurationTarget
}
from
'
vs/workbench/services/configuration/common/configurationEditing
'
;
import
{
WorkspaceConfigurationNode
,
IWorkspaceConfigurationValue
}
from
'
vs/workbench/services/configuration/common/configuration
'
;
export
class
ExtHostConfiguration
extends
ExtHostConfigurationShape
{
private
_proxy
:
MainThreadConfigurationShape
;
private
_config
:
any
;
private
_config
:
WorkspaceConfigurationNode
;
private
_onDidChangeConfiguration
=
new
Emitter
<
void
>
();
constructor
(
proxy
:
MainThreadConfigurationShape
,
config
uration
:
any
)
{
constructor
(
proxy
:
MainThreadConfigurationShape
,
config
:
WorkspaceConfigurationNode
)
{
super
();
this
.
_proxy
=
proxy
;
this
.
_config
=
config
uration
;
this
.
_config
=
config
;
}
get
onDidChangeConfiguration
():
Event
<
void
>
{
return
this
.
_onDidChangeConfiguration
&&
this
.
_onDidChangeConfiguration
.
event
;
}
public
$acceptConfigurationChanged
(
config
:
any
)
{
public
$acceptConfigurationChanged
(
config
:
WorkspaceConfigurationNode
)
{
this
.
_config
=
config
;
this
.
_onDidChangeConfiguration
.
fire
(
undefined
);
}
...
...
@@ -39,14 +40,17 @@ export class ExtHostConfiguration extends ExtHostConfigurationShape {
const
result
:
WorkspaceConfiguration
=
{
has
(
key
:
string
):
boolean
{
return
typeof
ExtHostConfiguration
.
_lookUp
(
key
,
config
)
!==
'
undefined
'
;
return
typeof
ExtHostConfiguration
.
_lookUp
(
key
,
<
WorkspaceConfigurationNode
>
config
)
!==
'
undefined
'
;
},
get
<
T
>
(
key
:
string
,
defaultValue
?:
T
):
T
{
let
result
=
ExtHostConfiguration
.
_lookUp
(
key
,
config
);
get
<
T
>
(
key
:
string
,
defaultValue
?:
T
):
any
{
let
result
=
ExtHostConfiguration
.
_lookUp
(
key
,
<
WorkspaceConfigurationNode
>
config
);
if
(
typeof
result
===
'
undefined
'
)
{
result
=
defaultValue
;
return
defaultValue
;
}
else
if
(
isConfigurationValue
(
result
))
{
return
result
.
value
;
}
else
{
return
ExtHostConfiguration
.
_values
(
result
);
}
return
result
;
},
update
:
(
key
:
string
,
value
:
any
,
global
:
boolean
=
false
)
=>
{
key
=
section
?
`
${
section
}
.
${
key
}
`
:
key
;
...
...
@@ -56,26 +60,66 @@ export class ExtHostConfiguration extends ExtHostConfigurationShape {
}
else
{
return
this
.
_proxy
.
$removeConfigurationOption
(
target
,
key
);
}
},
inspect
(
key
:
string
)
{
let
result
=
ExtHostConfiguration
.
_lookUp
(
key
,
<
WorkspaceConfigurationNode
>
config
);
if
(
isConfigurationValue
(
result
))
{
return
{
key
:
section
?
`
${
section
}
.
${
key
}
`
:
key
,
defaultValue
:
result
.
default
,
globalValue
:
result
.
user
,
workspaceValue
:
result
.
workspace
};
}
}
};
if
(
typeof
config
===
'
object
'
)
{
mixin
(
result
,
config
,
false
);
if
(
!
isConfigurationValue
(
config
)
)
{
mixin
(
result
,
ExtHostConfiguration
.
_values
(
config
)
,
false
);
}
return
Object
.
freeze
(
result
);
}
private
static
_lookUp
(
section
:
string
,
config
:
any
)
{
private
static
_lookUp
(
section
:
string
,
config
:
WorkspaceConfigurationNode
):
WorkspaceConfigurationNode
|
IWorkspaceConfigurationValue
<
any
>
{
if
(
!
section
)
{
return
;
}
let
parts
=
section
.
split
(
'
.
'
);
let
node
=
config
;
while
(
node
&&
parts
.
length
)
{
node
=
node
[
parts
.
shift
()];
let
child
=
node
[
parts
.
shift
()];
if
(
isConfigurationValue
(
child
))
{
return
child
;
}
else
{
node
=
child
;
}
}
return
node
;
}
private
static
_values
(
node
:
WorkspaceConfigurationNode
):
any
{
let
target
=
Object
.
create
(
null
);
for
(
let
key
in
node
)
{
let
child
=
node
[
key
];
if
(
isConfigurationValue
(
child
))
{
target
[
key
]
=
child
.
value
;
}
else
{
target
[
key
]
=
ExtHostConfiguration
.
_values
(
child
);
}
}
return
target
;
}
}
function
isConfigurationValue
(
thing
:
any
):
thing
is
IWorkspaceConfigurationValue
<
any
>
{
return
typeof
thing
===
'
object
'
// must have 'value'
&&
typeof
(
<
IWorkspaceConfigurationValue
<
any
>>
thing
).
value
!==
'
undefined
'
// and at least one source 'default', 'user', or 'workspace'
&&
(
typeof
(
<
IWorkspaceConfigurationValue
<
any
>>
thing
).
default
!==
'
undefined
'
||
typeof
(
<
IWorkspaceConfigurationValue
<
any
>>
thing
).
user
!==
'
undefined
'
||
typeof
(
<
IWorkspaceConfigurationValue
<
any
>>
thing
).
workspace
!==
'
undefined
'
);
}
src/vs/workbench/api/node/mainThreadConfiguration.ts
浏览文件 @
85cc6ab7
...
...
@@ -7,7 +7,7 @@
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
IThreadService
}
from
'
vs/workbench/services/thread/common/threadService
'
;
import
{
IWorkspaceConfigurationService
}
from
'
vs/workbench/services/configuration/common/configuration
'
;
import
{
IWorkspaceConfigurationService
,
getWorkspaceConfigurationTree
}
from
'
vs/workbench/services/configuration/common/configuration
'
;
import
{
IConfigurationEditingService
,
ConfigurationTarget
}
from
'
vs/workbench/services/configuration/common/configurationEditing
'
;
import
{
MainThreadConfigurationShape
,
ExtHostContext
}
from
'
./extHost.protocol
'
;
...
...
@@ -24,7 +24,11 @@ export class MainThreadConfiguration extends MainThreadConfigurationShape {
super
();
this
.
_configurationEditingService
=
configurationEditingService
;
const
proxy
=
threadService
.
get
(
ExtHostContext
.
ExtHostConfiguration
);
this
.
_toDispose
=
configurationService
.
onDidUpdateConfiguration
(
event
=>
proxy
.
$acceptConfigurationChanged
(
event
.
config
));
this
.
_toDispose
=
configurationService
.
onDidUpdateConfiguration
(()
=>
{
const
tree
=
getWorkspaceConfigurationTree
(
configurationService
);
proxy
.
$acceptConfigurationChanged
(
tree
);
});
}
public
dispose
():
void
{
...
...
src/vs/workbench/electron-browser/extensionHost.ts
浏览文件 @
85cc6ab7
...
...
@@ -28,9 +28,9 @@ import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc';
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
WatchDog
}
from
'
vs/base/common/watchDog
'
;
import
{
createQueuedSender
,
IQueuedSender
}
from
'
vs/base/node/processes
'
;
import
{
IInitData
,
IInitConfiguration
}
from
'
vs/workbench/api/node/extHost.protocol
'
;
import
{
IInitData
}
from
'
vs/workbench/api/node/extHost.protocol
'
;
import
{
MainProcessExtensionService
}
from
'
vs/workbench/api/node/mainThreadExtensionService
'
;
import
{
IWorkspaceConfigurationService
}
from
'
vs/workbench/services/configuration/common/configuration
'
;
import
{
IWorkspaceConfigurationService
,
getWorkspaceConfigurationTree
}
from
'
vs/workbench/services/configuration/common/configuration
'
;
export
const
EXTENSION_LOG_BROADCAST_CHANNEL
=
'
vscode:extensionLog
'
;
export
const
EXTENSION_ATTACH_BROADCAST_CHANNEL
=
'
vscode:extensionAttach
'
;
...
...
@@ -258,7 +258,7 @@ export class ExtensionHostProcessWorker {
workspace
:
this
.
contextService
.
getWorkspace
()
},
extensions
:
extensionDescriptions
,
configuration
:
this
.
configurationService
.
getConfiguration
<
IInitConfiguration
>
(
),
configuration
:
getWorkspaceConfigurationTree
(
this
.
configurationService
),
telemetryInfo
};
this
.
extensionHostProcessQueuedSender
.
send
(
stringify
(
initData
));
...
...
src/vs/workbench/services/configuration/common/configuration.ts
浏览文件 @
85cc6ab7
...
...
@@ -42,4 +42,42 @@ export const WORKSPACE_STANDALONE_CONFIGURATIONS = {
'
tasks
'
:
`
${
WORKSPACE_CONFIG_FOLDER_DEFAULT_NAME
}
/tasks.json`
,
'
launch
'
:
`
${
WORKSPACE_CONFIG_FOLDER_DEFAULT_NAME
}
/launch.json`
,
'
extensions
'
:
`
${
WORKSPACE_CONFIG_FOLDER_DEFAULT_NAME
}
/extensions.json`
};
\ No newline at end of file
};
export
interface
WorkspaceConfigurationNode
{
[
part
:
string
]:
IWorkspaceConfigurationValue
<
any
>
|
WorkspaceConfigurationNode
;
}
export
function
getWorkspaceConfigurationTree
(
configurationService
:
IWorkspaceConfigurationService
):
WorkspaceConfigurationNode
{
const
result
:
WorkspaceConfigurationNode
=
Object
.
create
(
null
);
const
keyset
=
configurationService
.
keys
();
const
keys
=
[...
keyset
.
workspace
,
...
keyset
.
user
,
...
keyset
.
default
].
sort
();
let
lastKey
:
string
;
for
(
const
key
of
keys
)
{
if
(
key
!==
lastKey
)
{
lastKey
=
key
;
const
config
=
configurationService
.
lookup
(
key
);
insert
(
result
,
key
,
config
);
}
}
return
result
;
}
function
insert
(
root
:
WorkspaceConfigurationNode
,
key
:
string
,
value
:
any
):
void
{
const
parts
=
key
.
split
(
'
.
'
);
let
i
=
0
;
while
(
i
<
parts
.
length
-
1
)
{
let
child
=
root
[
parts
[
i
]];
if
(
child
)
{
root
=
<
any
>
child
;
i
+=
1
;
}
else
{
break
;
}
}
while
(
i
<
parts
.
length
-
1
)
{
root
=
root
[
parts
[
i
]]
=
Object
.
create
(
null
);
i
+=
1
;
}
root
[
parts
[
parts
.
length
-
1
]]
=
value
;
}
src/vs/workbench/test/node/api/extHostConfiguration.test.ts
浏览文件 @
85cc6ab7
...
...
@@ -10,6 +10,7 @@ import { ExtHostConfiguration } from 'vs/workbench/api/node/extHostConfiguration
import
{
MainThreadConfigurationShape
}
from
'
vs/workbench/api/node/extHost.protocol
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
ConfigurationTarget
,
ConfigurationEditingErrorCode
,
IConfigurationEditingError
}
from
'
vs/workbench/services/configuration/common/configurationEditing
'
;
import
{
WorkspaceConfigurationNode
,
IWorkspaceConfigurationValue
}
from
'
vs/workbench/services/configuration/common/configuration
'
;
suite
(
'
ExtHostConfiguration
'
,
function
()
{
...
...
@@ -21,23 +22,32 @@ suite('ExtHostConfiguration', function () {
}
};
function
createExtHostConfiguration
(
data
:
any
=
{},
shape
?:
MainThreadConfigurationShape
)
{
function
createExtHostConfiguration
(
data
:
WorkspaceConfigurationNode
=
{},
shape
?:
MainThreadConfigurationShape
)
{
if
(
!
shape
)
{
shape
=
new
class
extends
MainThreadConfigurationShape
{
};
}
return
new
ExtHostConfiguration
(
shape
,
data
);
}
function
createConfigurationValue
<
T
>
(
value
:
T
):
IWorkspaceConfigurationValue
<
T
>
{
return
{
value
,
default
:
value
,
user
:
undefined
,
workspace
:
undefined
};
}
test
(
'
has/get
'
,
function
()
{
const
all
=
createExtHostConfiguration
({
farboo
:
{
config0
:
true
,
config0
:
createConfigurationValue
(
true
)
,
nested
:
{
config1
:
42
,
config2
:
'
Das Pferd frisst kein Reis.
'
config1
:
createConfigurationValue
(
42
)
,
config2
:
createConfigurationValue
(
'
Das Pferd frisst kein Reis.
'
),
},
config4
:
''
config4
:
createConfigurationValue
(
''
)
}
});
...
...
@@ -49,10 +59,32 @@ suite('ExtHostConfiguration', function () {
assert
.
equal
(
config
[
'
config0
'
],
true
);
assert
.
equal
(
config
[
'
config4
'
],
''
);
assert
.
throws
(()
=>
config
[
'
config4
'
]
=
'
valuevalue
'
);
assert
.
ok
(
config
.
has
(
'
nested.config1
'
));
assert
.
equal
(
config
.
get
(
'
nested.config1
'
),
42
);
assert
.
ok
(
config
.
has
(
'
nested.config2
'
));
assert
.
equal
(
config
.
get
(
'
nested.config2
'
),
'
Das Pferd frisst kein Reis.
'
);
assert
.
ok
(
config
.
has
(
'
nested
'
));
assert
.
deepEqual
(
config
.
get
(
'
nested
'
),
{
config1
:
42
,
config2
:
'
Das Pferd frisst kein Reis.
'
});
});
test
(
'
getConfiguration vs get
'
,
function
()
{
const
all
=
createExtHostConfiguration
({
farboo
:
{
config0
:
createConfigurationValue
(
true
),
config4
:
createConfigurationValue
(
'
38
'
)
}
});
let
config
=
all
.
getConfiguration
(
'
farboo.config0
'
);
assert
.
equal
(
config
.
get
(
''
),
undefined
);
assert
.
equal
(
config
.
has
(
''
),
false
);
config
=
all
.
getConfiguration
(
'
farboo
'
);
assert
.
equal
(
config
.
get
(
'
config0
'
),
true
);
assert
.
equal
(
config
.
has
(
'
config0
'
),
true
);
});
test
(
'
getConfiguration vs get
'
,
function
()
{
...
...
@@ -76,7 +108,7 @@ suite('ExtHostConfiguration', function () {
test
(
'
name vs property
'
,
function
()
{
const
all
=
createExtHostConfiguration
({
farboo
:
{
get
:
'
get-prop
'
get
:
createConfigurationValue
(
'
get-prop
'
)
}
});
const
config
=
all
.
getConfiguration
(
'
farboo
'
);
...
...
@@ -90,7 +122,7 @@ suite('ExtHostConfiguration', function () {
test
(
'
udate/section to key
'
,
function
()
{
const
shape
=
new
RecordingShape
();
const
allConfig
=
createExtHostConfiguration
({
foo
:
{
bar
:
1
,
far
:
2
}
},
shape
);
const
allConfig
=
createExtHostConfiguration
({
foo
:
{
bar
:
createConfigurationValue
(
1
),
far
:
createConfigurationValue
(
2
)
}
},
shape
);
let
config
=
allConfig
.
getConfiguration
(
'
foo
'
);
config
.
update
(
'
bar
'
,
42
,
true
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录