Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
83938cf1
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,发现更多精彩内容 >>
提交
83938cf1
编写于
9月 04, 2018
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use numeric ids for rpc proxies
上级
a5fd3d14
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
71 addition
and
56 deletion
+71
-56
src/vs/workbench/services/extensions/electron-browser/extensionService.ts
.../services/extensions/electron-browser/extensionService.ts
+4
-4
src/vs/workbench/services/extensions/node/proxyIdentifier.ts
src/vs/workbench/services/extensions/node/proxyIdentifier.ts
+18
-10
src/vs/workbench/services/extensions/node/rpcProtocol.ts
src/vs/workbench/services/extensions/node/rpcProtocol.ts
+45
-38
src/vs/workbench/test/electron-browser/api/testRPCProtocol.ts
...vs/workbench/test/electron-browser/api/testRPCProtocol.ts
+4
-4
未找到文件。
src/vs/workbench/services/extensions/electron-browser/extensionService.ts
浏览文件 @
83938cf1
...
...
@@ -46,6 +46,9 @@ import { Schemas } from 'vs/base/common/network';
import
{
getPathFromAmdModule
}
from
'
vs/base/common/amd
'
;
import
{
isEqualOrParent
}
from
'
vs/base/common/resources
'
;
// Enable to see detailed message communication between window and extension host
const
LOG_EXTENSION_HOST_COMMUNICATION
=
false
;
let
_SystemExtensionsRoot
:
string
=
null
;
function
getSystemExtensionsRoot
():
string
{
if
(
!
_SystemExtensionsRoot
)
{
...
...
@@ -97,9 +100,6 @@ class ExtraBuiltInExtensionResolver implements IExtensionResolver {
}
}
// Enable to see detailed message communication between window and extension host
const
logExtensionHostCommunication
=
false
;
function
messageWithSource
(
source
:
string
,
message
:
string
):
string
{
if
(
source
)
{
return
`[
${
source
}
]:
${
message
}
`
;
...
...
@@ -181,7 +181,7 @@ export class ExtensionHostProcessManager extends Disposable {
private
_createExtensionHostCustomers
(
protocol
:
IMessagePassingProtocol
):
ExtHostExtensionServiceShape
{
let
logger
:
IRPCProtocolLogger
=
null
;
if
(
logExtensionHostCommunication
||
this
.
_environmentService
.
logExtensionHostCommunication
)
{
if
(
LOG_EXTENSION_HOST_COMMUNICATION
||
this
.
_environmentService
.
logExtensionHostCommunication
)
{
logger
=
new
RPCLogger
();
}
...
...
src/vs/workbench/services/extensions/node/proxyIdentifier.ts
浏览文件 @
83938cf1
...
...
@@ -22,27 +22,35 @@ export interface IRPCProtocol {
}
export
class
ProxyIdentifier
<
T
>
{
public
static
count
=
0
;
_proxyIdentifierBrand
:
void
;
_suppressCompilerUnusedWarning
:
T
;
public
readonly
isMain
:
boolean
;
public
readonly
id
:
string
;
public
readonly
sid
:
string
;
public
readonly
nid
:
number
;
constructor
(
isMain
:
boolean
,
id
:
string
)
{
constructor
(
isMain
:
boolean
,
s
id
:
string
)
{
this
.
isMain
=
isMain
;
this
.
id
=
id
;
this
.
sid
=
sid
;
this
.
nid
=
(
++
ProxyIdentifier
.
count
);
}
}
/**
* 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.
*/
const
identifiers
:
ProxyIdentifier
<
any
>
[]
=
[];
export
function
createMainContextProxyIdentifier
<
T
>
(
identifier
:
string
):
ProxyIdentifier
<
T
>
{
return
new
ProxyIdentifier
(
true
,
'
m
'
+
identifier
);
const
result
=
new
ProxyIdentifier
<
T
>
(
true
,
identifier
);
identifiers
[
result
.
nid
]
=
result
;
return
result
;
}
export
function
createExtHostContextProxyIdentifier
<
T
>
(
identifier
:
string
):
ProxyIdentifier
<
T
>
{
return
new
ProxyIdentifier
(
false
,
'
e
'
+
identifier
);
const
result
=
new
ProxyIdentifier
<
T
>
(
false
,
identifier
);
identifiers
[
result
.
nid
]
=
result
;
return
result
;
}
export
function
getStringIdentifierForProxy
(
nid
:
number
):
string
{
return
identifiers
[
nid
].
sid
;
}
src/vs/workbench/services/extensions/node/rpcProtocol.ts
浏览文件 @
83938cf1
...
...
@@ -8,7 +8,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import
*
as
errors
from
'
vs/base/common/errors
'
;
import
{
IMessagePassingProtocol
}
from
'
vs/base/parts/ipc/node/ipc
'
;
import
{
LazyPromise
}
from
'
vs/workbench/services/extensions/node/lazyPromise
'
;
import
{
ProxyIdentifier
,
IRPCProtocol
}
from
'
vs/workbench/services/extensions/node/proxyIdentifier
'
;
import
{
ProxyIdentifier
,
IRPCProtocol
,
getStringIdentifierForProxy
}
from
'
vs/workbench/services/extensions/node/proxyIdentifier
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
MarshalledObject
}
from
'
vs/base/common/marshalling
'
;
...
...
@@ -96,8 +96,8 @@ export class RPCProtocol implements IRPCProtocol {
private
readonly
_logger
:
IRPCProtocolLogger
;
private
readonly
_uriTransformer
:
IURITransformer
;
private
_isDisposed
:
boolean
;
private
readonly
_locals
:
{
[
id
:
string
]:
any
;
}
;
private
readonly
_proxies
:
{
[
id
:
string
]:
any
;
}
;
private
readonly
_locals
:
any
[]
;
private
readonly
_proxies
:
any
[]
;
private
_lastMessageId
:
number
;
private
readonly
_invokedHandlers
:
{
[
req
:
string
]:
TPromise
<
any
>
;
};
private
readonly
_pendingRPCReplies
:
{
[
msgId
:
string
]:
LazyPromise
;
};
...
...
@@ -107,8 +107,12 @@ export class RPCProtocol implements IRPCProtocol {
this
.
_logger
=
logger
;
this
.
_uriTransformer
=
transformer
;
this
.
_isDisposed
=
false
;
this
.
_locals
=
Object
.
create
(
null
);
this
.
_proxies
=
Object
.
create
(
null
);
this
.
_locals
=
[];
this
.
_proxies
=
[];
for
(
let
i
=
0
,
len
=
ProxyIdentifier
.
count
;
i
<
len
;
i
++
)
{
this
.
_locals
[
i
]
=
null
;
this
.
_proxies
[
i
]
=
null
;
}
this
.
_lastMessageId
=
0
;
this
.
_invokedHandlers
=
Object
.
create
(
null
);
this
.
_pendingRPCReplies
=
{};
...
...
@@ -133,18 +137,19 @@ 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
);
const
rpcId
=
identifier
.
nid
;
if
(
!
this
.
_proxies
[
rpcId
])
{
this
.
_proxies
[
rpcId
]
=
this
.
_createProxy
(
rpcId
);
}
return
this
.
_proxies
[
identifier
.
i
d
];
return
this
.
_proxies
[
rpcI
d
];
}
private
_createProxy
<
T
>
(
proxyId
:
string
):
T
{
private
_createProxy
<
T
>
(
rpcId
:
number
):
T
{
let
handler
=
{
get
:
(
target
:
any
,
name
:
string
)
=>
{
if
(
!
target
[
name
]
&&
name
.
charCodeAt
(
0
)
===
CharCode
.
DollarSign
)
{
target
[
name
]
=
(...
myArgs
:
any
[])
=>
{
return
this
.
_remoteCall
(
proxy
Id
,
name
,
myArgs
);
return
this
.
_remoteCall
(
rpc
Id
,
name
,
myArgs
);
};
}
return
target
[
name
];
...
...
@@ -154,15 +159,15 @@ export class RPCProtocol implements IRPCProtocol {
}
public
set
<
T
,
R
extends
T
>
(
identifier
:
ProxyIdentifier
<
T
>
,
value
:
R
):
R
{
this
.
_locals
[
identifier
.
id
]
=
value
;
this
.
_locals
[
identifier
.
n
id
]
=
value
;
return
value
;
}
public
assertRegistered
(
identifiers
:
ProxyIdentifier
<
any
>
[]):
void
{
for
(
let
i
=
0
,
len
=
identifiers
.
length
;
i
<
len
;
i
++
)
{
const
identifier
=
identifiers
[
i
];
if
(
!
this
.
_locals
[
identifier
.
id
])
{
throw
new
Error
(
`Missing actor
${
identifier
.
id
}
(isMain:
${
identifier
.
isMain
}
)`
);
if
(
!
this
.
_locals
[
identifier
.
n
id
])
{
throw
new
Error
(
`Missing actor
${
identifier
.
s
id
}
(isMain:
${
identifier
.
isMain
}
)`
);
}
}
}
...
...
@@ -230,9 +235,9 @@ export class RPCProtocol implements IRPCProtocol {
}
}
private
_receiveRequest
(
msgLength
:
number
,
req
:
number
,
rpcId
:
string
,
method
:
string
,
args
:
any
[]):
void
{
private
_receiveRequest
(
msgLength
:
number
,
req
:
number
,
rpcId
:
number
,
method
:
string
,
args
:
any
[]):
void
{
if
(
this
.
_logger
)
{
this
.
_logger
.
logIncoming
(
msgLength
,
`receiveRequest
${
req
}
,
${
rpcId
}
.
${
method
}
:`
,
args
);
this
.
_logger
.
logIncoming
(
msgLength
,
`receiveRequest
${
req
}
,
${
getStringIdentifierForProxy
(
rpcId
)
}
.
${
method
}
:`
,
args
);
}
const
callId
=
String
(
req
);
...
...
@@ -302,27 +307,27 @@ export class RPCProtocol implements IRPCProtocol {
pendingReply
.
resolveErr
(
err
);
}
private
_invokeHandler
(
proxyId
:
string
,
methodName
:
string
,
args
:
any
[]):
TPromise
<
any
>
{
private
_invokeHandler
(
rpcId
:
number
,
methodName
:
string
,
args
:
any
[]):
TPromise
<
any
>
{
try
{
return
TPromise
.
as
(
this
.
_doInvokeHandler
(
proxy
Id
,
methodName
,
args
));
return
TPromise
.
as
(
this
.
_doInvokeHandler
(
rpc
Id
,
methodName
,
args
));
}
catch
(
err
)
{
return
TPromise
.
wrapError
(
err
);
}
}
private
_doInvokeHandler
(
proxyId
:
string
,
methodName
:
string
,
args
:
any
[]):
any
{
if
(
!
this
.
_locals
[
proxyId
])
{
throw
new
Error
(
'
Unknown actor
'
+
proxyId
);
private
_doInvokeHandler
(
rpcId
:
number
,
methodName
:
string
,
args
:
any
[]):
any
{
const
actor
=
this
.
_locals
[
rpcId
];
if
(
!
actor
)
{
throw
new
Error
(
'
Unknown actor
'
+
getStringIdentifierForProxy
(
rpcId
));
}
let
actor
=
this
.
_locals
[
proxyId
];
let
method
=
actor
[
methodName
];
if
(
typeof
method
!==
'
function
'
)
{
throw
new
Error
(
'
Unknown method
'
+
methodName
+
'
on actor
'
+
proxyId
);
throw
new
Error
(
'
Unknown method
'
+
methodName
+
'
on actor
'
+
getStringIdentifierForProxy
(
rpcId
)
);
}
return
method
.
apply
(
actor
,
args
);
}
private
_remoteCall
(
proxyId
:
string
,
methodName
:
string
,
args
:
any
[]):
TPromise
<
any
>
{
private
_remoteCall
(
rpcId
:
number
,
methodName
:
string
,
args
:
any
[]):
TPromise
<
any
>
{
if
(
this
.
_isDisposed
)
{
return
TPromise
.
wrapError
<
any
>
(
errors
.
canceled
());
}
...
...
@@ -341,9 +346,9 @@ export class RPCProtocol implements IRPCProtocol {
if
(
this
.
_uriTransformer
)
{
args
=
transformOutgoingURIs
(
args
,
this
.
_uriTransformer
);
}
const
msg
=
MessageIO
.
serializeRequest
(
req
,
proxy
Id
,
methodName
,
args
);
const
msg
=
MessageIO
.
serializeRequest
(
req
,
rpc
Id
,
methodName
,
args
);
if
(
this
.
_logger
)
{
this
.
_logger
.
logOutgoing
(
msg
.
byteLength
,
`request
${
req
}
:
${
proxyId
}
.
${
methodName
}
:`
,
args
);
this
.
_logger
.
logOutgoing
(
msg
.
byteLength
,
`request
${
req
}
:
${
getStringIdentifierForProxy
(
rpcId
)
}
.
${
methodName
}
:`
,
args
);
}
this
.
_protocol
.
send
(
msg
);
return
result
;
...
...
@@ -375,6 +380,10 @@ class MessageBuffer {
this
.
_offset
=
offset
;
}
public
static
sizeUInt8
():
number
{
return
1
;
}
public
writeUInt8
(
n
:
number
):
void
{
this
.
_buff
.
writeUInt8
(
n
,
this
.
_offset
,
true
);
this
.
_offset
+=
1
;
}
...
...
@@ -495,7 +504,7 @@ class MessageIO {
return
false
;
}
public
static
serializeRequest
(
req
:
number
,
rpcId
:
string
,
method
:
string
,
args
:
any
[]):
Buffer
{
public
static
serializeRequest
(
req
:
number
,
rpcId
:
number
,
method
:
string
,
args
:
any
[]):
Buffer
{
if
(
this
.
_arrayContainsBuffer
(
args
))
{
let
massagedArgs
:
(
string
|
Buffer
)[]
=
new
Array
(
args
.
length
);
let
argsLengths
:
number
[]
=
new
Array
(
args
.
length
);
...
...
@@ -514,25 +523,24 @@ class MessageIO {
return
this
.
_requestJSONArgs
(
req
,
rpcId
,
method
,
JSON
.
stringify
(
args
));
}
private
static
_requestJSONArgs
(
req
:
number
,
rpcId
:
string
,
method
:
string
,
args
:
string
):
Buffer
{
const
rpcIdByteLength
=
Buffer
.
byteLength
(
rpcId
,
'
utf8
'
);
private
static
_requestJSONArgs
(
req
:
number
,
rpcId
:
number
,
method
:
string
,
args
:
string
):
Buffer
{
const
methodByteLength
=
Buffer
.
byteLength
(
method
,
'
utf8
'
);
const
argsByteLength
=
Buffer
.
byteLength
(
args
,
'
utf8
'
);
let
len
=
0
;
len
+=
MessageBuffer
.
size
ShortString
(
rpcId
,
rpcIdByteLength
);
len
+=
MessageBuffer
.
size
UInt8
(
);
len
+=
MessageBuffer
.
sizeShortString
(
method
,
methodByteLength
);
len
+=
MessageBuffer
.
sizeLongString
(
args
,
argsByteLength
);
let
result
=
MessageBuffer
.
alloc
(
MessageType
.
RequestJSONArgs
,
req
,
len
);
result
.
write
ShortString
(
rpcId
,
rpcIdByteLength
);
result
.
write
UInt8
(
rpcId
);
result
.
writeShortString
(
method
,
methodByteLength
);
result
.
writeLongString
(
args
,
argsByteLength
);
return
result
.
buffer
;
}
public
static
deserializeRequestJSONArgs
(
buff
:
MessageBuffer
):
{
rpcId
:
string
;
method
:
string
;
args
:
any
[];
}
{
const
rpcId
=
buff
.
read
ShortString
();
public
static
deserializeRequestJSONArgs
(
buff
:
MessageBuffer
):
{
rpcId
:
number
;
method
:
string
;
args
:
any
[];
}
{
const
rpcId
=
buff
.
read
UInt8
();
const
method
=
buff
.
readShortString
();
const
args
=
buff
.
readLongString
();
return
{
...
...
@@ -542,24 +550,23 @@ class MessageIO {
};
}
private
static
_requestMixedArgs
(
req
:
number
,
rpcId
:
string
,
method
:
string
,
args
:
(
string
|
Buffer
)[],
argsLengths
:
number
[]):
Buffer
{
const
rpcIdByteLength
=
Buffer
.
byteLength
(
rpcId
,
'
utf8
'
);
private
static
_requestMixedArgs
(
req
:
number
,
rpcId
:
number
,
method
:
string
,
args
:
(
string
|
Buffer
)[],
argsLengths
:
number
[]):
Buffer
{
const
methodByteLength
=
Buffer
.
byteLength
(
method
,
'
utf8
'
);
let
len
=
0
;
len
+=
MessageBuffer
.
size
ShortString
(
rpcId
,
rpcIdByteLength
);
len
+=
MessageBuffer
.
size
UInt8
(
);
len
+=
MessageBuffer
.
sizeShortString
(
method
,
methodByteLength
);
len
+=
MessageBuffer
.
sizeMixedArray
(
args
,
argsLengths
);
let
result
=
MessageBuffer
.
alloc
(
MessageType
.
RequestMixedArgs
,
req
,
len
);
result
.
write
ShortString
(
rpcId
,
rpcIdByteLength
);
result
.
write
UInt8
(
rpcId
);
result
.
writeShortString
(
method
,
methodByteLength
);
result
.
writeMixedArray
(
args
,
argsLengths
);
return
result
.
buffer
;
}
public
static
deserializeRequestMixedArgs
(
buff
:
MessageBuffer
):
{
rpcId
:
string
;
method
:
string
;
args
:
any
[];
}
{
const
rpcId
=
buff
.
read
ShortString
();
public
static
deserializeRequestMixedArgs
(
buff
:
MessageBuffer
):
{
rpcId
:
number
;
method
:
string
;
args
:
any
[];
}
{
const
rpcId
=
buff
.
read
UInt8
();
const
method
=
buff
.
readShortString
();
const
rawargs
=
buff
.
readMixedArray
();
const
args
:
any
[]
=
new
Array
(
rawargs
.
length
);
...
...
src/vs/workbench/test/electron-browser/api/testRPCProtocol.ts
浏览文件 @
83938cf1
...
...
@@ -70,10 +70,10 @@ export class TestRPCProtocol implements IExtHostContext {
}
public
getProxy
<
T
>
(
identifier
:
ProxyIdentifier
<
T
>
):
T
{
if
(
!
this
.
_proxies
[
identifier
.
id
])
{
this
.
_proxies
[
identifier
.
id
]
=
this
.
_createProxy
(
identifier
.
id
);
if
(
!
this
.
_proxies
[
identifier
.
s
id
])
{
this
.
_proxies
[
identifier
.
sid
]
=
this
.
_createProxy
(
identifier
.
s
id
);
}
return
this
.
_proxies
[
identifier
.
id
];
return
this
.
_proxies
[
identifier
.
s
id
];
}
private
_createProxy
<
T
>
(
proxyId
:
string
):
T
{
...
...
@@ -91,7 +91,7 @@ export class TestRPCProtocol implements IExtHostContext {
}
public
set
<
T
,
R
extends
T
>
(
identifier
:
ProxyIdentifier
<
T
>
,
value
:
R
):
R
{
this
.
_locals
[
identifier
.
id
]
=
value
;
this
.
_locals
[
identifier
.
s
id
]
=
value
;
return
value
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录