Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
8f18e874
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,发现更多精彩内容 >>
提交
8f18e874
编写于
12月 14, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ExtHostCommands, MainThreadCommands, #40169
上级
785aac7d
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
31 addition
and
28 deletion
+31
-28
src/vs/workbench/api/electron-browser/mainThreadCommands.ts
src/vs/workbench/api/electron-browser/mainThreadCommands.ts
+4
-0
src/vs/workbench/api/node/extHost.protocol.ts
src/vs/workbench/api/node/extHost.protocol.ts
+2
-2
src/vs/workbench/api/node/extHostCommands.ts
src/vs/workbench/api/node/extHostCommands.ts
+25
-26
未找到文件。
src/vs/workbench/api/electron-browser/mainThreadCommands.ts
浏览文件 @
8f18e874
...
...
@@ -9,6 +9,7 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
ExtHostContext
,
MainThreadCommandsShape
,
ExtHostCommandsShape
,
MainContext
,
IExtHostContext
}
from
'
../node/extHost.protocol
'
;
import
{
extHostNamedCustomer
}
from
'
vs/workbench/api/electron-browser/extHostCustomers
'
;
import
{
revive
}
from
'
vs/base/common/marshalling
'
;
@
extHostNamedCustomer
(
MainContext
.
MainThreadCommands
)
export
class
MainThreadCommands
implements
MainThreadCommandsShape
{
...
...
@@ -70,6 +71,9 @@ export class MainThreadCommands implements MainThreadCommandsShape {
}
$executeCommand
<
T
>
(
id
:
string
,
args
:
any
[]):
Thenable
<
T
>
{
for
(
let
i
=
0
;
i
<
args
.
length
;
i
++
)
{
args
[
i
]
=
revive
(
args
[
i
],
0
);
}
return
this
.
_commandService
.
executeCommand
<
T
>
(
id
,
...
args
);
}
...
...
src/vs/workbench/api/node/extHost.protocol.ts
浏览文件 @
8f18e874
...
...
@@ -731,7 +731,7 @@ export interface ExtHostWindowShape {
// --- proxy identifiers
export
const
MainContext
=
{
MainThreadCommands
:
<
ProxyIdentifier
<
MainThreadCommandsShape
>>
createMainId
<
MainThreadCommandsShape
>
(
'
MainThreadCommands
'
,
ProxyType
.
CustomMarshaller
),
MainThreadCommands
:
<
ProxyIdentifier
<
MainThreadCommandsShape
>>
createMainId
<
MainThreadCommandsShape
>
(
'
MainThreadCommands
'
),
MainThreadConfiguration
:
createMainId
<
MainThreadConfigurationShape
>
(
'
MainThreadConfiguration
'
,
ProxyType
.
CustomMarshaller
),
MainThreadDebugService
:
createMainId
<
MainThreadDebugServiceShape
>
(
'
MainThreadDebugService
'
,
ProxyType
.
CustomMarshaller
),
MainThreadDecorations
:
createMainId
<
MainThreadDecorationsShape
>
(
'
MainThreadDecorations
'
),
...
...
@@ -761,7 +761,7 @@ export const MainContext = {
};
export
const
ExtHostContext
=
{
ExtHostCommands
:
createExtId
<
ExtHostCommandsShape
>
(
'
ExtHostCommands
'
,
ProxyType
.
CustomMarshaller
),
ExtHostCommands
:
createExtId
<
ExtHostCommandsShape
>
(
'
ExtHostCommands
'
),
ExtHostConfiguration
:
createExtId
<
ExtHostConfigurationShape
>
(
'
ExtHostConfiguration
'
,
ProxyType
.
CustomMarshaller
),
ExtHostDiagnostics
:
createExtId
<
ExtHostDiagnosticsShape
>
(
'
ExtHostDiagnostics
'
),
ExtHostDebugService
:
createExtId
<
ExtHostDebugServiceShape
>
(
'
ExtHostDebugService
'
,
ProxyType
.
CustomMarshaller
),
...
...
src/vs/workbench/api/node/extHostCommands.ts
浏览文件 @
8f18e874
...
...
@@ -15,6 +15,7 @@ import { isFalsyOrEmpty } from 'vs/base/common/arrays';
import
*
as
modes
from
'
vs/editor/common/modes
'
;
import
*
as
vscode
from
'
vscode
'
;
import
{
ILogService
}
from
'
vs/platform/log/common/log
'
;
import
{
revive
}
from
'
vs/base/common/marshalling
'
;
interface
CommandHandler
{
callback
:
Function
;
...
...
@@ -28,18 +29,21 @@ export interface ArgumentProcessor {
export
class
ExtHostCommands
implements
ExtHostCommandsShape
{
private
_commands
=
new
Map
<
string
,
CommandHandler
>
();
private
_proxy
:
MainThreadCommandsShape
;
private
_converter
:
CommandsConverter
;
private
_argumentProcessors
:
ArgumentProcessor
[]
=
[];
private
readonly
_commands
=
new
Map
<
string
,
CommandHandler
>
();
private
readonly
_proxy
:
MainThreadCommandsShape
;
private
readonly
_converter
:
CommandsConverter
;
private
readonly
_logService
:
ILogService
;
private
readonly
_argumentProcessors
:
ArgumentProcessor
[];
constructor
(
mainContext
:
IMainContext
,
heapService
:
ExtHostHeapService
,
private
logService
:
ILogService
logService
:
ILogService
)
{
this
.
_proxy
=
mainContext
.
getProxy
(
MainContext
.
MainThreadCommands
);
this
.
_converter
=
new
CommandsConverter
(
this
,
heapService
);
this
.
_logService
=
logService
;
this
.
_argumentProcessors
=
[{
processArgument
(
a
)
{
return
revive
(
a
,
0
);
}
}];
}
get
converter
():
CommandsConverter
{
...
...
@@ -51,7 +55,7 @@ export class ExtHostCommands implements ExtHostCommandsShape {
}
registerCommand
(
id
:
string
,
callback
:
<
T
>
(...
args
:
any
[])
=>
T
|
Thenable
<
T
>
,
thisArg
?:
any
,
description
?:
ICommandHandlerDescription
):
extHostTypes
.
Disposable
{
this
.
logService
.
trace
(
'
ExtHostCommands#registerCommand
'
,
id
);
this
.
_
logService
.
trace
(
'
ExtHostCommands#registerCommand
'
,
id
);
if
(
!
id
.
trim
().
length
)
{
throw
new
Error
(
'
invalid id
'
);
...
...
@@ -72,12 +76,12 @@ export class ExtHostCommands implements ExtHostCommandsShape {
}
executeCommand
<
T
>
(
id
:
string
,
...
args
:
any
[]):
Thenable
<
T
>
{
this
.
logService
.
trace
(
'
ExtHostCommands#executeCommand
'
,
id
);
this
.
_
logService
.
trace
(
'
ExtHostCommands#executeCommand
'
,
id
);
if
(
this
.
_commands
.
has
(
id
))
{
// we stay inside the extension host and support
// to pass any kind of parameters around
return
this
.
$executeContributedCommand
<
T
>
(
id
,
...
args
);
return
this
.
_executeContributedCommand
<
T
>
(
id
,
args
);
}
else
{
// automagically convert some argument types
...
...
@@ -99,17 +103,10 @@ export class ExtHostCommands implements ExtHostCommandsShape {
return
this
.
_proxy
.
$executeCommand
<
T
>
(
id
,
args
);
}
}
$executeContributedCommand
<
T
>
(
id
:
string
,
...
args
:
any
[]):
Thenable
<
T
>
{
let
command
=
this
.
_commands
.
get
(
id
);
if
(
!
command
)
{
return
Promise
.
reject
(
new
Error
(
`Contributed command '
${
id
}
' does not exist.`
));
}
let
{
callback
,
thisArg
,
description
}
=
command
;
private
_executeContributedCommand
<
T
>
(
id
:
string
,
args
:
any
[]):
Thenable
<
T
>
{
let
{
callback
,
thisArg
,
description
}
=
this
.
_commands
.
get
(
id
);
if
(
description
)
{
for
(
let
i
=
0
;
i
<
description
.
args
.
length
;
i
++
)
{
try
{
...
...
@@ -120,24 +117,26 @@ export class ExtHostCommands implements ExtHostCommandsShape {
}
}
args
=
args
.
map
(
arg
=>
this
.
_argumentProcessors
.
reduce
((
r
,
p
)
=>
p
.
processArgument
(
r
),
arg
));
try
{
let
result
=
callback
.
apply
(
thisArg
,
args
);
return
Promise
.
resolve
(
result
);
}
catch
(
err
)
{
// console.log(err);
// try {
// console.log(toErrorMessage(err));
// } catch (err) {
// //
// }
this
.
_logService
.
error
(
err
,
id
);
return
Promise
.
reject
(
new
Error
(
`Running the contributed command:'
${
id
}
' failed.`
));
}
}
$executeContributedCommand
<
T
>
(
id
:
string
,
...
args
:
any
[]):
Thenable
<
T
>
{
if
(
!
this
.
_commands
.
has
(
id
))
{
return
Promise
.
reject
(
new
Error
(
`Contributed command '
${
id
}
' does not exist.`
));
}
else
{
args
=
args
.
map
(
arg
=>
this
.
_argumentProcessors
.
reduce
((
r
,
p
)
=>
p
.
processArgument
(
r
),
arg
));
return
this
.
_executeContributedCommand
(
id
,
args
);
}
}
getCommands
(
filterUnderscoreCommands
:
boolean
=
false
):
Thenable
<
string
[]
>
{
this
.
logService
.
trace
(
'
ExtHostCommands#getCommands
'
,
filterUnderscoreCommands
);
this
.
_
logService
.
trace
(
'
ExtHostCommands#getCommands
'
,
filterUnderscoreCommands
);
return
this
.
_proxy
.
$getCommands
().
then
(
result
=>
{
if
(
filterUnderscoreCommands
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录