Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
f2e07e14
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,发现更多精彩内容 >>
提交
f2e07e14
编写于
1月 24, 2018
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove support for custom marshaller (#40169)
上级
fabd8a57
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
25 addition
and
80 deletion
+25
-80
src/vs/workbench/services/extensions/node/proxyIdentifier.ts
src/vs/workbench/services/extensions/node/proxyIdentifier.ts
+5
-12
src/vs/workbench/services/extensions/node/rpcProtocol.ts
src/vs/workbench/services/extensions/node/rpcProtocol.ts
+12
-55
src/vs/workbench/test/electron-browser/api/testRPCProtocol.ts
...vs/workbench/test/electron-browser/api/testRPCProtocol.ts
+8
-13
未找到文件。
src/vs/workbench/services/extensions/node/proxyIdentifier.ts
浏览文件 @
f2e07e14
...
...
@@ -27,29 +27,22 @@ export class ProxyIdentifier<T> {
public
readonly
isMain
:
boolean
;
public
readonly
id
:
string
;
public
readonly
isFancy
:
boolean
;
constructor
(
isMain
:
boolean
,
id
:
string
,
isFancy
:
boolean
)
{
constructor
(
isMain
:
boolean
,
id
:
string
)
{
this
.
isMain
=
isMain
;
this
.
id
=
id
;
this
.
isFancy
=
isFancy
;
}
}
export
const
enum
ProxyType
{
NativeJSON
=
0
,
CustomMarshaller
=
1
}
/**
* Using `isFancy` indicates that arguments or results of type `URI` or `RegExp`
* will be serialized/deserialized automatically, but this has a performance cost,
* as each argument/result must be visited.
*/
export
function
createMainContextProxyIdentifier
<
T
>
(
identifier
:
string
,
type
:
ProxyType
=
ProxyType
.
NativeJSON
):
ProxyIdentifier
<
T
>
{
return
new
ProxyIdentifier
(
true
,
'
m
'
+
identifier
,
type
===
ProxyType
.
CustomMarshaller
);
export
function
createMainContextProxyIdentifier
<
T
>
(
identifier
:
string
):
ProxyIdentifier
<
T
>
{
return
new
ProxyIdentifier
(
true
,
'
m
'
+
identifier
);
}
export
function
createExtHostContextProxyIdentifier
<
T
>
(
identifier
:
string
,
type
:
ProxyType
=
ProxyType
.
NativeJSON
):
ProxyIdentifier
<
T
>
{
return
new
ProxyIdentifier
(
false
,
'
e
'
+
identifier
,
type
===
ProxyType
.
CustomMarshaller
);
export
function
createExtHostContextProxyIdentifier
<
T
>
(
identifier
:
string
):
ProxyIdentifier
<
T
>
{
return
new
ProxyIdentifier
(
false
,
'
e
'
+
identifier
);
}
src/vs/workbench/services/extensions/node/rpcProtocol.ts
浏览文件 @
f2e07e14
...
...
@@ -5,7 +5,6 @@
'
use strict
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
*
as
marshalling
from
'
vs/base/common/marshalling
'
;
import
*
as
errors
from
'
vs/base/common/errors
'
;
import
{
IMessagePassingProtocol
}
from
'
vs/base/parts/ipc/common/ipc
'
;
import
{
LazyPromise
}
from
'
vs/workbench/services/extensions/node/lazyPromise
'
;
...
...
@@ -46,17 +45,17 @@ export class RPCProtocol implements IRPCProtocol {
public
getProxy
<
T
>
(
identifier
:
ProxyIdentifier
<
T
>
):
T
{
if
(
!
this
.
_proxies
[
identifier
.
id
])
{
this
.
_proxies
[
identifier
.
id
]
=
this
.
_createProxy
(
identifier
.
id
,
identifier
.
isFancy
);
this
.
_proxies
[
identifier
.
id
]
=
this
.
_createProxy
(
identifier
.
id
);
}
return
this
.
_proxies
[
identifier
.
id
];
}
private
_createProxy
<
T
>
(
proxyId
:
string
,
isFancy
:
boolean
):
T
{
private
_createProxy
<
T
>
(
proxyId
:
string
):
T
{
let
handler
=
{
get
:
(
target
,
name
:
string
)
=>
{
if
(
!
target
[
name
]
&&
name
.
charCodeAt
(
0
)
===
CharCode
.
DollarSign
)
{
target
[
name
]
=
(...
myArgs
:
any
[])
=>
{
return
this
.
_remoteCall
(
proxyId
,
name
,
myArgs
,
isFancy
);
return
this
.
_remoteCall
(
proxyId
,
name
,
myArgs
);
};
}
return
target
[
name
];
...
...
@@ -90,38 +89,27 @@ export class RPCProtocol implements IRPCProtocol {
case
MessageType
.
Request
:
this
.
_receiveRequest
(
msg
);
break
;
case
MessageType
.
FancyRequest
:
this
.
_receiveRequest
(
marshalling
.
revive
(
msg
,
0
));
break
;
case
MessageType
.
Cancel
:
this
.
_receiveCancel
(
msg
);
break
;
case
MessageType
.
Reply
:
this
.
_receiveReply
(
msg
);
break
;
case
MessageType
.
FancyReply
:
this
.
_receiveReply
(
marshalling
.
revive
(
msg
,
0
));
break
;
case
MessageType
.
ReplyErr
:
this
.
_receiveReplyErr
(
msg
);
break
;
}
}
private
_receiveRequest
(
msg
:
RequestMessage
|
FancyRequestMessage
):
void
{
private
_receiveRequest
(
msg
:
RequestMessage
):
void
{
const
callId
=
msg
.
id
;
const
proxyId
=
msg
.
proxyId
;
const
isFancy
=
(
msg
.
type
===
MessageType
.
FancyRequest
);
// a fancy request gets a fancy reply
this
.
_invokedHandlers
[
callId
]
=
this
.
_invokeHandler
(
proxyId
,
msg
.
method
,
msg
.
args
);
this
.
_invokedHandlers
[
callId
].
then
((
r
)
=>
{
delete
this
.
_invokedHandlers
[
callId
];
if
(
isFancy
)
{
this
.
_multiplexor
.
send
(
MessageFactory
.
fancyReplyOK
(
callId
,
r
));
}
else
{
this
.
_multiplexor
.
send
(
MessageFactory
.
replyOK
(
callId
,
r
));
}
this
.
_multiplexor
.
send
(
MessageFactory
.
replyOK
(
callId
,
r
));
},
(
err
)
=>
{
delete
this
.
_invokedHandlers
[
callId
];
this
.
_multiplexor
.
send
(
MessageFactory
.
replyErr
(
callId
,
err
));
...
...
@@ -135,7 +123,7 @@ export class RPCProtocol implements IRPCProtocol {
}
}
private
_receiveReply
(
msg
:
ReplyMessage
|
FancyReplyMessage
):
void
{
private
_receiveReply
(
msg
:
ReplyMessage
):
void
{
const
callId
=
msg
.
id
;
if
(
!
this
.
_pendingRPCReplies
.
hasOwnProperty
(
callId
))
{
return
;
...
...
@@ -186,7 +174,7 @@ export class RPCProtocol implements IRPCProtocol {
return
method
.
apply
(
actor
,
args
);
}
private
_remoteCall
(
proxyId
:
string
,
methodName
:
string
,
args
:
any
[]
,
isFancy
:
boolean
):
TPromise
<
any
>
{
private
_remoteCall
(
proxyId
:
string
,
methodName
:
string
,
args
:
any
[]):
TPromise
<
any
>
{
if
(
this
.
_isDisposed
)
{
return
TPromise
.
wrapError
<
any
>
(
errors
.
canceled
());
}
...
...
@@ -197,13 +185,7 @@ export class RPCProtocol implements IRPCProtocol {
});
this
.
_pendingRPCReplies
[
callId
]
=
result
;
if
(
isFancy
)
{
this
.
_multiplexor
.
send
(
MessageFactory
.
fancyRequest
(
callId
,
proxyId
,
methodName
,
args
));
}
else
{
this
.
_multiplexor
.
send
(
MessageFactory
.
request
(
callId
,
proxyId
,
methodName
,
args
));
}
this
.
_multiplexor
.
send
(
MessageFactory
.
request
(
callId
,
proxyId
,
methodName
,
args
));
return
result
;
}
}
...
...
@@ -256,10 +238,6 @@ class MessageFactory {
return
`{"type":
${
MessageType
.
Request
}
,"id":"
${
req
}
","proxyId":"
${
rpcId
}
","method":"
${
method
}
","args":
${
JSON
.
stringify
(
args
)}
}`
;
}
public
static
fancyRequest
(
req
:
string
,
rpcId
:
string
,
method
:
string
,
args
:
any
[]):
string
{
return
`{"type":
${
MessageType
.
FancyRequest
}
,"id":"
${
req
}
","proxyId":"
${
rpcId
}
","method":"
${
method
}
","args":
${
marshalling
.
stringify
(
args
)}
}`
;
}
public
static
replyOK
(
req
:
string
,
res
:
any
):
string
{
if
(
typeof
res
===
'
undefined
'
)
{
return
`{"type":
${
MessageType
.
Reply
}
,"id":"
${
req
}
"}`
;
...
...
@@ -267,13 +245,6 @@ class MessageFactory {
return
`{"type":
${
MessageType
.
Reply
}
,"id":"
${
req
}
","res":
${
JSON
.
stringify
(
res
)}
}`
;
}
public
static
fancyReplyOK
(
req
:
string
,
res
:
any
):
string
{
if
(
typeof
res
===
'
undefined
'
)
{
return
`{"type":
${
MessageType
.
Reply
}
,"id":"
${
req
}
"}`
;
}
return
`{"type":
${
MessageType
.
FancyReply
}
,"id":"
${
req
}
","res":
${
marshalling
.
stringify
(
res
)}
}`
;
}
public
static
replyErr
(
req
:
string
,
err
:
any
):
string
{
if
(
err
instanceof
Error
)
{
return
`{"type":
${
MessageType
.
ReplyErr
}
,"id":"
${
req
}
","err":
${
JSON
.
stringify
(
errors
.
transformErrorForSerialization
(
err
))}
}`
;
...
...
@@ -284,11 +255,9 @@ class MessageFactory {
const
enum
MessageType
{
Request
=
1
,
FancyRequest
=
2
,
Cancel
=
3
,
Reply
=
4
,
FancyReply
=
5
,
ReplyErr
=
6
Cancel
=
2
,
Reply
=
3
,
ReplyErr
=
4
}
class
RequestMessage
{
...
...
@@ -298,13 +267,6 @@ class RequestMessage {
method
:
string
;
args
:
any
[];
}
class
FancyRequestMessage
{
type
:
MessageType
.
FancyRequest
;
id
:
string
;
proxyId
:
string
;
method
:
string
;
args
:
any
[];
}
class
CancelMessage
{
type
:
MessageType
.
Cancel
;
id
:
string
;
...
...
@@ -314,15 +276,10 @@ class ReplyMessage {
id
:
string
;
res
:
any
;
}
class
FancyReplyMessage
{
type
:
MessageType
.
FancyReply
;
id
:
string
;
res
:
any
;
}
class
ReplyErrMessage
{
type
:
MessageType
.
ReplyErr
;
id
:
string
;
err
:
errors
.
SerializedError
;
}
type
RPCMessage
=
RequestMessage
|
FancyRequestMessage
|
CancelMessage
|
ReplyMessage
|
Fancy
ReplyMessage
|
ReplyErrMessage
;
type
RPCMessage
=
RequestMessage
|
CancelMessage
|
ReplyMessage
|
ReplyErrMessage
;
src/vs/workbench/test/electron-browser/api/testRPCProtocol.ts
浏览文件 @
f2e07e14
...
...
@@ -8,7 +8,6 @@
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
ProxyIdentifier
,
IRPCProtocol
}
from
'
vs/workbench/services/extensions/node/proxyIdentifier
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
*
as
marshalling
from
'
vs/base/common/marshalling
'
;
export
function
SingleProxyRPCProtocol
(
thing
:
any
):
IRPCProtocol
{
return
{
...
...
@@ -70,17 +69,17 @@ export class TestRPCProtocol implements IRPCProtocol {
public
getProxy
<
T
>
(
identifier
:
ProxyIdentifier
<
T
>
):
T
{
if
(
!
this
.
_proxies
[
identifier
.
id
])
{
this
.
_proxies
[
identifier
.
id
]
=
this
.
_createProxy
(
identifier
.
id
,
identifier
.
isFancy
);
this
.
_proxies
[
identifier
.
id
]
=
this
.
_createProxy
(
identifier
.
id
);
}
return
this
.
_proxies
[
identifier
.
id
];
}
private
_createProxy
<
T
>
(
proxyId
:
string
,
isFancy
:
boolean
):
T
{
private
_createProxy
<
T
>
(
proxyId
:
string
):
T
{
let
handler
=
{
get
:
(
target
,
name
:
string
)
=>
{
if
(
!
target
[
name
]
&&
name
.
charCodeAt
(
0
)
===
CharCode
.
DollarSign
)
{
target
[
name
]
=
(...
myArgs
:
any
[])
=>
{
return
this
.
_remoteCall
(
proxyId
,
name
,
myArgs
,
isFancy
);
return
this
.
_remoteCall
(
proxyId
,
name
,
myArgs
);
};
}
return
target
[
name
];
...
...
@@ -94,7 +93,7 @@ export class TestRPCProtocol implements IRPCProtocol {
return
value
;
}
protected
_remoteCall
(
proxyId
:
string
,
path
:
string
,
args
:
any
[]
,
isFancy
:
boolean
):
TPromise
<
any
>
{
protected
_remoteCall
(
proxyId
:
string
,
path
:
string
,
args
:
any
[]):
TPromise
<
any
>
{
this
.
_callCount
++
;
return
new
TPromise
<
any
>
((
c
)
=>
{
...
...
@@ -102,7 +101,7 @@ export class TestRPCProtocol implements IRPCProtocol {
}).
then
(()
=>
{
const
instance
=
this
.
_locals
[
proxyId
];
// pretend the args went over the wire... (invoke .toJSON on objects...)
const
wireArgs
=
simulateWireTransfer
(
args
,
isFancy
);
const
wireArgs
=
simulateWireTransfer
(
args
);
let
p
:
Thenable
<
any
>
;
try
{
let
result
=
(
<
Function
>
instance
[
path
]).
apply
(
instance
,
wireArgs
);
...
...
@@ -114,7 +113,7 @@ export class TestRPCProtocol implements IRPCProtocol {
return
p
.
then
(
result
=>
{
this
.
_callCount
--
;
// pretend the result went over the wire... (invoke .toJSON on objects...)
const
wireResult
=
simulateWireTransfer
(
result
,
isFancy
);
const
wireResult
=
simulateWireTransfer
(
result
);
return
wireResult
;
},
err
=>
{
this
.
_callCount
--
;
...
...
@@ -128,13 +127,9 @@ export class TestRPCProtocol implements IRPCProtocol {
}
}
function
simulateWireTransfer
<
T
>
(
obj
:
T
,
isFancy
:
boolean
):
T
{
function
simulateWireTransfer
<
T
>
(
obj
:
T
):
T
{
if
(
!
obj
)
{
return
obj
;
}
return
(
isFancy
?
marshalling
.
parse
(
marshalling
.
stringify
(
obj
))
:
JSON
.
parse
(
JSON
.
stringify
(
obj
))
);
return
JSON
.
parse
(
JSON
.
stringify
(
obj
));
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录