Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gzupanda
code-server
提交
0a01338e
C
code-server
项目概览
gzupanda
/
code-server
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
code-server
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
0a01338e
编写于
11月 10, 2020
作者:
A
Asher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Deduplicate child process message dance
上级
d969a5bd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
72 addition
and
40 deletion
+72
-40
src/node/vscode.ts
src/node/vscode.ts
+72
-40
未找到文件。
src/node/vscode.ts
浏览文件 @
0a01338e
...
...
@@ -13,6 +13,7 @@ export class VscodeProvider {
public
readonly
serverRootPath
:
string
public
readonly
vsRootPath
:
string
private
_vscode
?:
Promise
<
cp
.
ChildProcess
>
private
timeoutInterval
=
10000
// 10s, matches VS Code's timeouts.
public
constructor
()
{
this
.
vsRootPath
=
path
.
resolve
(
rootPath
,
"
lib/vscode
"
)
...
...
@@ -52,33 +53,25 @@ export class VscodeProvider {
const
vscode
=
await
this
.
fork
()
logger
.
debug
(
"
setting up vs code...
"
)
return
new
Promise
<
ipc
.
WorkbenchOptions
>
((
resolve
,
reject
)
=>
{
const
onExit
=
(
code
:
number
|
null
)
=>
reject
(
new
Error
(
`VS Code exited unexpectedly with code
${
code
}
`
))
vscode
.
once
(
"
message
"
,
(
message
:
ipc
.
VscodeMessage
)
=>
{
logger
.
debug
(
"
got message from vs code
"
,
field
(
"
message
"
,
message
))
vscode
.
off
(
"
error
"
,
reject
)
vscode
.
off
(
"
exit
"
,
onExit
)
return
message
.
type
===
"
options
"
&&
message
.
id
===
id
?
resolve
(
message
.
options
)
:
reject
(
new
Error
(
"
Unexpected response during initialization
"
))
})
vscode
.
once
(
"
error
"
,
reject
)
vscode
.
once
(
"
exit
"
,
onExit
)
this
.
send
(
{
type
:
"
init
"
,
id
,
options
:
{
...
options
,
startPath
,
},
this
.
send
(
{
type
:
"
init
"
,
id
,
options
:
{
...
options
,
startPath
,
},
vscode
,
)
},
vscode
,
)
const
message
=
await
this
.
onMessage
<
ipc
.
OptionsMessage
>
(
vscode
,
(
message
):
message
is
ipc
.
OptionsMessage
=>
{
// There can be parallel initializations so wait for the right ID.
return
message
.
type
===
"
options
"
&&
message
.
id
===
id
})
return
message
.
options
}
private
fork
():
Promise
<
cp
.
ChildProcess
>
{
...
...
@@ -88,32 +81,71 @@ export class VscodeProvider {
logger
.
debug
(
"
forking vs code...
"
)
const
vscode
=
cp
.
fork
(
path
.
join
(
this
.
serverRootPath
,
"
fork
"
))
vscode
.
on
(
"
error
"
,
(
error
)
=>
{
logger
.
error
(
error
.
message
)
const
dispose
=
()
=>
{
vscode
.
removeAllListeners
()
vscode
.
kill
()
this
.
_vscode
=
undefined
}
vscode
.
on
(
"
error
"
,
(
error
:
Error
)
=>
{
logger
.
error
(
error
.
message
)
if
(
error
.
stack
)
{
logger
.
debug
(
error
.
stack
)
}
dispose
()
})
vscode
.
on
(
"
exit
"
,
(
code
)
=>
{
logger
.
error
(
`VS Code exited unexpectedly with code
${
code
}
`
)
this
.
_vscode
=
undefined
dispose
()
})
this
.
_vscode
=
new
Promise
((
resolve
,
reject
)
=>
{
const
onExit
=
(
code
:
number
|
null
)
=>
reject
(
new
Error
(
`VS Code exited unexpectedly with code
${
code
}
`
))
this
.
_vscode
=
this
.
onMessage
<
ipc
.
ReadyMessage
>
(
vscode
,
(
message
):
message
is
ipc
.
ReadyMessage
=>
{
return
message
.
type
===
"
ready
"
}).
then
(()
=>
vscode
)
vscode
.
once
(
"
message
"
,
(
message
:
ipc
.
VscodeMessage
)
=>
{
logger
.
debug
(
"
got message from vs code
"
,
field
(
"
message
"
,
message
))
vscode
.
off
(
"
error
"
,
reject
)
vscode
.
off
(
"
exit
"
,
onExit
)
return
message
.
type
===
"
ready
"
?
resolve
(
vscode
)
:
reject
(
new
Error
(
"
Unexpected response waiting for ready response
"
))
return
this
.
_vscode
}
/**
* Listen to a single message from a process. Reject if the process errors,
* exits, or times out.
*
* `fn` is a function that determines whether the message is the one we're
* waiting for.
*/
private
onMessage
<
T
extends
ipc
.
VscodeMessage
>
(
proc
:
cp
.
ChildProcess
,
fn
:
(
message
:
ipc
.
VscodeMessage
)
=>
message
is
T
,
):
Promise
<
T
>
{
return
new
Promise
((
resolve
,
_reject
)
=>
{
const
reject
=
(
error
:
Error
)
=>
{
clearTimeout
(
timeout
)
_reject
(
error
)
}
const
onExit
=
(
code
:
number
|
null
)
=>
{
reject
(
new
Error
(
`VS Code exited unexpectedly with code
${
code
}
`
))
}
const
timeout
=
setTimeout
(()
=>
{
reject
(
new
Error
(
"
timed out
"
))
},
this
.
timeoutInterval
)
proc
.
on
(
"
message
"
,
(
message
:
ipc
.
VscodeMessage
)
=>
{
logger
.
debug
(
"
got message from vscode
"
,
field
(
"
message
"
,
message
))
proc
.
off
(
"
error
"
,
reject
)
proc
.
off
(
"
exit
"
,
onExit
)
if
(
fn
(
message
))
{
clearTimeout
(
timeout
)
resolve
(
message
)
}
})
vscode
.
once
(
"
error
"
,
reject
)
vscode
.
once
(
"
exit
"
,
onExit
)
proc
.
once
(
"
error
"
,
reject
)
proc
.
once
(
"
exit
"
,
onExit
)
})
return
this
.
_vscode
}
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录