Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
63a0da43
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,发现更多精彩内容 >>
提交
63a0da43
编写于
9月 11, 2019
作者:
D
Daniel Imms
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Have ExtHostTerminalService extend Base service
上级
b5a31251
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
37 addition
and
336 deletion
+37
-336
src/vs/workbench/api/common/extHostTerminalService.ts
src/vs/workbench/api/common/extHostTerminalService.ts
+30
-35
src/vs/workbench/api/node/extHostTerminalService.ts
src/vs/workbench/api/node/extHostTerminalService.ts
+5
-299
src/vs/workbench/services/extensions/worker/extHost.services.ts
.../workbench/services/extensions/worker/extHost.services.ts
+2
-2
未找到文件。
src/vs/workbench/api/common/extHostTerminalService.ts
浏览文件 @
63a0da43
...
...
@@ -281,24 +281,24 @@ export abstract class BaseExtHostTerminalService implements IExtHostTerminalServ
readonly
_serviceBrand
:
undefined
;
pr
ivate
_proxy
:
MainThreadTerminalServiceShape
;
pr
ivate
_activeTerminal
:
ExtHostTerminal
|
undefined
;
pr
ivate
_terminals
:
ExtHostTerminal
[]
=
[];
pr
ivate
_terminalProcesses
:
{
[
id
:
number
]:
ITerminalChildProcess
}
=
{};
pr
ivate
_getTerminalPromises
:
{
[
id
:
number
]:
Promise
<
ExtHostTerminal
>
}
=
{};
pr
otected
_proxy
:
MainThreadTerminalServiceShape
;
pr
otected
_activeTerminal
:
ExtHostTerminal
|
undefined
;
pr
otected
_terminals
:
ExtHostTerminal
[]
=
[];
pr
otected
_terminalProcesses
:
{
[
id
:
number
]:
ITerminalChildProcess
}
=
{};
pr
otected
_getTerminalPromises
:
{
[
id
:
number
]:
Promise
<
ExtHostTerminal
>
}
=
{};
public
get
activeTerminal
():
ExtHostTerminal
|
undefined
{
return
this
.
_activeTerminal
;
}
public
get
terminals
():
ExtHostTerminal
[]
{
return
this
.
_terminals
;
}
pr
ivate
readonly
_onDidCloseTerminal
:
Emitter
<
vscode
.
Terminal
>
=
new
Emitter
<
vscode
.
Terminal
>
();
pr
otected
readonly
_onDidCloseTerminal
:
Emitter
<
vscode
.
Terminal
>
=
new
Emitter
<
vscode
.
Terminal
>
();
public
get
onDidCloseTerminal
():
Event
<
vscode
.
Terminal
>
{
return
this
.
_onDidCloseTerminal
&&
this
.
_onDidCloseTerminal
.
event
;
}
pr
ivate
readonly
_onDidOpenTerminal
:
Emitter
<
vscode
.
Terminal
>
=
new
Emitter
<
vscode
.
Terminal
>
();
pr
otected
readonly
_onDidOpenTerminal
:
Emitter
<
vscode
.
Terminal
>
=
new
Emitter
<
vscode
.
Terminal
>
();
public
get
onDidOpenTerminal
():
Event
<
vscode
.
Terminal
>
{
return
this
.
_onDidOpenTerminal
&&
this
.
_onDidOpenTerminal
.
event
;
}
pr
ivate
readonly
_onDidChangeActiveTerminal
:
Emitter
<
vscode
.
Terminal
|
undefined
>
=
new
Emitter
<
vscode
.
Terminal
|
undefined
>
();
pr
otected
readonly
_onDidChangeActiveTerminal
:
Emitter
<
vscode
.
Terminal
|
undefined
>
=
new
Emitter
<
vscode
.
Terminal
|
undefined
>
();
public
get
onDidChangeActiveTerminal
():
Event
<
vscode
.
Terminal
|
undefined
>
{
return
this
.
_onDidChangeActiveTerminal
&&
this
.
_onDidChangeActiveTerminal
.
event
;
}
pr
ivate
readonly
_onDidChangeTerminalDimensions
:
Emitter
<
vscode
.
TerminalDimensionsChangeEvent
>
=
new
Emitter
<
vscode
.
TerminalDimensionsChangeEvent
>
();
pr
otected
readonly
_onDidChangeTerminalDimensions
:
Emitter
<
vscode
.
TerminalDimensionsChangeEvent
>
=
new
Emitter
<
vscode
.
TerminalDimensionsChangeEvent
>
();
public
get
onDidChangeTerminalDimensions
():
Event
<
vscode
.
TerminalDimensionsChangeEvent
>
{
return
this
.
_onDidChangeTerminalDimensions
&&
this
.
_onDidChangeTerminalDimensions
.
event
;
}
pr
ivate
readonly
_onDidWriteTerminalData
:
Emitter
<
vscode
.
TerminalDataWriteEvent
>
;
pr
otected
readonly
_onDidWriteTerminalData
:
Emitter
<
vscode
.
TerminalDataWriteEvent
>
;
public
get
onDidWriteTerminalData
():
Event
<
vscode
.
TerminalDataWriteEvent
>
{
return
this
.
_onDidWriteTerminalData
&&
this
.
_onDidWriteTerminalData
.
event
;
}
constructor
(
...
...
@@ -311,19 +311,13 @@ export abstract class BaseExtHostTerminalService implements IExtHostTerminalServ
});
}
public
createTerminal
(
name
?:
string
,
shellPath
?:
string
,
shellArgs
?:
string
[]
|
string
):
vscode
.
Terminal
{
const
terminal
=
new
ExtHostTerminal
(
this
.
_proxy
,
name
);
terminal
.
create
(
shellPath
,
shellArgs
);
this
.
_terminals
.
push
(
terminal
);
return
terminal
;
}
public
createTerminalFromOptions
(
options
:
vscode
.
TerminalOptions
):
vscode
.
Terminal
{
const
terminal
=
new
ExtHostTerminal
(
this
.
_proxy
,
options
.
name
);
terminal
.
create
(
options
.
shellPath
,
options
.
shellArgs
,
options
.
cwd
,
options
.
env
,
/*options.waitOnExit*/
undefined
,
options
.
strictEnv
,
options
.
hideFromUser
);
this
.
_terminals
.
push
(
terminal
);
return
terminal
;
}
public
abstract
createTerminal
(
name
?:
string
,
shellPath
?:
string
,
shellArgs
?:
string
[]
|
string
):
vscode
.
Terminal
;
public
abstract
createTerminalFromOptions
(
options
:
vscode
.
TerminalOptions
):
vscode
.
Terminal
;
public
abstract
getDefaultShell
(
useAutomationShell
:
boolean
,
configProvider
:
ExtHostConfigProvider
):
string
;
public
abstract
$spawnExtHostProcess
(
id
:
number
,
shellLaunchConfigDto
:
IShellLaunchConfigDto
,
activeWorkspaceRootUriComponents
:
UriComponents
,
cols
:
number
,
rows
:
number
,
isWorkspaceShellAllowed
:
boolean
):
Promise
<
void
>
;
public
abstract
$requestAvailableShells
():
Promise
<
IShellDefinitionDto
[]
>
;
public
abstract
$requestDefaultShellAndArgs
(
useAutomationShell
:
boolean
):
Promise
<
IShellAndArgsDto
>
;
public
abstract
$acceptWorkspacePermissionsChanged
(
isAllowed
:
boolean
):
void
;
public
createExtensionTerminal
(
options
:
vscode
.
ExtensionTerminalOptions
):
vscode
.
Terminal
{
const
terminal
=
new
ExtHostTerminal
(
this
.
_proxy
,
options
.
name
);
...
...
@@ -342,8 +336,6 @@ export abstract class BaseExtHostTerminalService implements IExtHostTerminalServ
this
.
_setupExtHostProcessListeners
(
id
,
p
);
}
public
abstract
getDefaultShell
(
useAutomationShell
:
boolean
,
configProvider
:
ExtHostConfigProvider
):
string
;
public
async
$acceptActiveTerminalChanged
(
id
:
number
|
null
):
Promise
<
void
>
{
const
original
=
this
.
_activeTerminal
;
if
(
id
===
null
)
{
...
...
@@ -454,8 +446,6 @@ export abstract class BaseExtHostTerminalService implements IExtHostTerminalServ
}
}
public
abstract
$spawnExtHostProcess
(
id
:
number
,
shellLaunchConfigDto
:
IShellLaunchConfigDto
,
activeWorkspaceRootUriComponents
:
UriComponents
,
cols
:
number
,
rows
:
number
,
isWorkspaceShellAllowed
:
boolean
):
Promise
<
void
>
;
public
async
$startExtensionTerminal
(
id
:
number
,
initialDimensions
:
ITerminalDimensionsDto
|
undefined
):
Promise
<
void
>
{
// Make sure the ExtHostTerminal exists so onDidOpenTerminal has fired before we call
// Pseudoterminal.start
...
...
@@ -494,7 +484,7 @@ export abstract class BaseExtHostTerminalService implements IExtHostTerminalServ
}
}
pr
ivate
_setupExtHostProcessListeners
(
id
:
number
,
p
:
ITerminalChildProcess
):
void
{
pr
otected
_setupExtHostProcessListeners
(
id
:
number
,
p
:
ITerminalChildProcess
):
void
{
p
.
onProcessReady
((
e
:
{
pid
:
number
,
cwd
:
string
})
=>
this
.
_proxy
.
$sendProcessReady
(
id
,
e
.
pid
,
e
.
cwd
));
p
.
onProcessTitleChanged
(
title
=>
this
.
_proxy
.
$sendProcessTitle
(
id
,
title
));
p
.
onProcessData
(
data
=>
this
.
_proxy
.
$sendProcessData
(
id
,
data
));
...
...
@@ -536,9 +526,6 @@ export abstract class BaseExtHostTerminalService implements IExtHostTerminalServ
return
id
;
}
public
abstract
$requestAvailableShells
():
Promise
<
IShellDefinitionDto
[]
>
;
public
abstract
$requestDefaultShellAndArgs
(
useAutomationShell
:
boolean
):
Promise
<
IShellAndArgsDto
>
;
private
_onProcessExit
(
id
:
number
,
exitCode
:
number
):
void
{
// Remove process reference
delete
this
.
_terminalProcesses
[
id
];
...
...
@@ -598,13 +585,17 @@ export abstract class BaseExtHostTerminalService implements IExtHostTerminalServ
});
return
index
;
}
public
$acceptWorkspacePermissionsChanged
(
isAllowed
:
boolean
):
void
{
// No-op for web worker ext host
}
}
export
class
WorkerExtHostTerminalService
extends
BaseExtHostTerminalService
{
public
createTerminal
(
name
?:
string
,
shellPath
?:
string
,
shellArgs
?:
string
[]
|
string
):
vscode
.
Terminal
{
throw
new
Error
(
'
Not implemented
'
);
}
public
createTerminalFromOptions
(
options
:
vscode
.
TerminalOptions
):
vscode
.
Terminal
{
throw
new
Error
(
'
Not implemented
'
);
}
public
getDefaultShell
(
useAutomationShell
:
boolean
,
configProvider
:
ExtHostConfigProvider
):
string
{
throw
new
Error
(
'
Not implemented
'
);
}
...
...
@@ -620,4 +611,8 @@ export class WorkerExtHostTerminalService extends BaseExtHostTerminalService {
public
async
$requestDefaultShellAndArgs
(
useAutomationShell
:
boolean
):
Promise
<
IShellAndArgsDto
>
{
throw
new
Error
(
'
Not implemented
'
);
}
public
$acceptWorkspacePermissionsChanged
(
isAllowed
:
boolean
):
void
{
// No-op for web worker ext host as workspace permissions aren't used
}
}
src/vs/workbench/api/node/extHostTerminalService.ts
浏览文件 @
63a0da43
...
...
@@ -9,51 +9,28 @@ import * as os from 'os';
import
{
URI
,
UriComponents
}
from
'
vs/base/common/uri
'
;
import
*
as
platform
from
'
vs/base/common/platform
'
;
import
*
as
terminalEnvironment
from
'
vs/workbench/contrib/terminal/common/terminalEnvironment
'
;
import
{
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
import
{
ExtHostTerminalServiceShape
,
MainContext
,
MainThreadTerminalServiceShape
,
IShellLaunchConfigDto
,
IShellDefinitionDto
,
IShellAndArgsDto
,
ITerminalDimensionsDto
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
IShellLaunchConfigDto
,
IShellDefinitionDto
,
IShellAndArgsDto
}
from
'
vs/workbench/api/common/extHost.protocol
'
;
import
{
ExtHostConfiguration
,
ExtHostConfigProvider
,
IExtHostConfiguration
}
from
'
vs/workbench/api/common/extHostConfiguration
'
;
import
{
ILogService
}
from
'
vs/platform/log/common/log
'
;
import
{
EXT_HOST_CREATION_DELAY
,
IShellLaunchConfig
,
ITerminalEnvironment
,
ITerminalChildProcess
}
from
'
vs/workbench/contrib/terminal/common/terminal
'
;
import
{
IShellLaunchConfig
,
ITerminalEnvironment
}
from
'
vs/workbench/contrib/terminal/common/terminal
'
;
import
{
TerminalProcess
}
from
'
vs/workbench/contrib/terminal/node/terminalProcess
'
;
import
{
timeout
}
from
'
vs/base/common/async
'
;
import
{
ExtHostWorkspace
,
IExtHostWorkspace
}
from
'
vs/workbench/api/common/extHostWorkspace
'
;
import
{
IWorkspaceFolder
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
ExtHostVariableResolverService
}
from
'
vs/workbench/api/node/extHostDebugService
'
;
import
{
ExtHostDocumentsAndEditors
,
IExtHostDocumentsAndEditors
}
from
'
vs/workbench/api/common/extHostDocumentsAndEditors
'
;
import
{
getSystemShell
,
detectAvailableShells
}
from
'
vs/workbench/contrib/terminal/node/terminal
'
;
import
{
getMainProcessParentEnv
}
from
'
vs/workbench/contrib/terminal/node/terminalEnvironment
'
;
import
{
IExtHostTerminalService
,
ExtHostTerminal
,
ExtHostPseudot
erminal
}
from
'
vs/workbench/api/common/extHostTerminalService
'
;
import
{
BaseExtHostTerminalService
,
ExtHostT
erminal
}
from
'
vs/workbench/api/common/extHostTerminalService
'
;
import
{
IExtHostRpcService
}
from
'
vs/workbench/api/common/extHostRpcService
'
;
export
class
ExtHostTerminalService
implements
IExtHostTerminalService
,
ExtHostTerminalServiceShap
e
{
export
class
ExtHostTerminalService
extends
BaseExtHostTerminalServic
e
{
readonly
_serviceBrand
:
undefined
;
private
_proxy
:
MainThreadTerminalServiceShape
;
private
_activeTerminal
:
ExtHostTerminal
|
undefined
;
private
_terminals
:
ExtHostTerminal
[]
=
[];
private
_terminalProcesses
:
{
[
id
:
number
]:
ITerminalChildProcess
}
=
{};
private
_getTerminalPromises
:
{
[
id
:
number
]:
Promise
<
ExtHostTerminal
>
}
=
{};
private
_variableResolver
:
ExtHostVariableResolverService
|
undefined
;
private
_lastActiveWorkspace
:
IWorkspaceFolder
|
undefined
;
// TODO: Pull this from main side
private
_isWorkspaceShellAllowed
:
boolean
=
false
;
public
get
activeTerminal
():
ExtHostTerminal
|
undefined
{
return
this
.
_activeTerminal
;
}
public
get
terminals
():
ExtHostTerminal
[]
{
return
this
.
_terminals
;
}
private
readonly
_onDidCloseTerminal
:
Emitter
<
vscode
.
Terminal
>
=
new
Emitter
<
vscode
.
Terminal
>
();
public
get
onDidCloseTerminal
():
Event
<
vscode
.
Terminal
>
{
return
this
.
_onDidCloseTerminal
&&
this
.
_onDidCloseTerminal
.
event
;
}
private
readonly
_onDidOpenTerminal
:
Emitter
<
vscode
.
Terminal
>
=
new
Emitter
<
vscode
.
Terminal
>
();
public
get
onDidOpenTerminal
():
Event
<
vscode
.
Terminal
>
{
return
this
.
_onDidOpenTerminal
&&
this
.
_onDidOpenTerminal
.
event
;
}
private
readonly
_onDidChangeActiveTerminal
:
Emitter
<
vscode
.
Terminal
|
undefined
>
=
new
Emitter
<
vscode
.
Terminal
|
undefined
>
();
public
get
onDidChangeActiveTerminal
():
Event
<
vscode
.
Terminal
|
undefined
>
{
return
this
.
_onDidChangeActiveTerminal
&&
this
.
_onDidChangeActiveTerminal
.
event
;
}
private
readonly
_onDidChangeTerminalDimensions
:
Emitter
<
vscode
.
TerminalDimensionsChangeEvent
>
=
new
Emitter
<
vscode
.
TerminalDimensionsChangeEvent
>
();
public
get
onDidChangeTerminalDimensions
():
Event
<
vscode
.
TerminalDimensionsChangeEvent
>
{
return
this
.
_onDidChangeTerminalDimensions
&&
this
.
_onDidChangeTerminalDimensions
.
event
;
}
private
readonly
_onDidWriteTerminalData
:
Emitter
<
vscode
.
TerminalDataWriteEvent
>
;
public
get
onDidWriteTerminalData
():
Event
<
vscode
.
TerminalDataWriteEvent
>
{
return
this
.
_onDidWriteTerminalData
&&
this
.
_onDidWriteTerminalData
.
event
;
}
constructor
(
@
IExtHostRpcService
extHostRpc
:
IExtHostRpcService
,
@
IExtHostConfiguration
private
_extHostConfiguration
:
ExtHostConfiguration
,
...
...
@@ -61,11 +38,7 @@ export class ExtHostTerminalService implements IExtHostTerminalService, ExtHostT
@
IExtHostDocumentsAndEditors
private
_extHostDocumentsAndEditors
:
ExtHostDocumentsAndEditors
,
@
ILogService
private
_logService
:
ILogService
)
{
this
.
_proxy
=
extHostRpc
.
getProxy
(
MainContext
.
MainThreadTerminalService
);
this
.
_onDidWriteTerminalData
=
new
Emitter
<
vscode
.
TerminalDataWriteEvent
>
({
onFirstListenerAdd
:
()
=>
this
.
_proxy
.
$startSendingDataEvents
(),
onLastListenerRemove
:
()
=>
this
.
_proxy
.
$stopSendingDataEvents
()
});
super
(
extHostRpc
);
this
.
_updateLastActiveWorkspace
();
this
.
_updateVariableResolver
();
this
.
_registerListeners
();
...
...
@@ -85,23 +58,6 @@ export class ExtHostTerminalService implements IExtHostTerminalService, ExtHostT
return
terminal
;
}
public
createExtensionTerminal
(
options
:
vscode
.
ExtensionTerminalOptions
):
vscode
.
Terminal
{
const
terminal
=
new
ExtHostTerminal
(
this
.
_proxy
,
options
.
name
);
const
p
=
new
ExtHostPseudoterminal
(
options
.
pty
);
terminal
.
createExtensionTerminal
().
then
(
id
=>
this
.
_setupExtHostProcessListeners
(
id
,
p
));
this
.
_terminals
.
push
(
terminal
);
return
terminal
;
}
public
attachPtyToTerminal
(
id
:
number
,
pty
:
vscode
.
Pseudoterminal
):
void
{
const
terminal
=
this
.
_getTerminalByIdEventually
(
id
);
if
(
!
terminal
)
{
throw
new
Error
(
`Cannot resolve terminal with id
${
id
}
for virtual process`
);
}
const
p
=
new
ExtHostPseudoterminal
(
pty
);
this
.
_setupExtHostProcessListeners
(
id
,
p
);
}
public
getDefaultShell
(
useAutomationShell
:
boolean
,
configProvider
:
ExtHostConfigProvider
):
string
{
const
fetchSetting
=
(
key
:
string
)
=>
{
const
setting
=
configProvider
...
...
@@ -133,116 +89,6 @@ export class ExtHostTerminalService implements IExtHostTerminalService, ExtHostT
return
terminalEnvironment
.
getDefaultShellArgs
(
fetchSetting
,
this
.
_isWorkspaceShellAllowed
,
useAutomationShell
,
this
.
_lastActiveWorkspace
,
this
.
_variableResolver
,
this
.
_logService
);
}
public
async
$acceptActiveTerminalChanged
(
id
:
number
|
null
):
Promise
<
void
>
{
const
original
=
this
.
_activeTerminal
;
if
(
id
===
null
)
{
this
.
_activeTerminal
=
undefined
;
if
(
original
!==
this
.
_activeTerminal
)
{
this
.
_onDidChangeActiveTerminal
.
fire
(
this
.
_activeTerminal
);
}
return
;
}
const
terminal
=
await
this
.
_getTerminalByIdEventually
(
id
);
if
(
terminal
)
{
this
.
_activeTerminal
=
terminal
;
if
(
original
!==
this
.
_activeTerminal
)
{
this
.
_onDidChangeActiveTerminal
.
fire
(
this
.
_activeTerminal
);
}
}
}
/** @deprecated */
public
async
$acceptTerminalProcessData
(
id
:
number
,
data
:
string
):
Promise
<
void
>
{
const
terminal
=
await
this
.
_getTerminalByIdEventually
(
id
);
if
(
terminal
)
{
terminal
.
_fireOnData
(
data
);
}
}
public
async
$acceptTerminalProcessData2
(
id
:
number
,
data
:
string
):
Promise
<
void
>
{
const
terminal
=
await
this
.
_getTerminalByIdEventually
(
id
);
if
(
terminal
)
{
this
.
_onDidWriteTerminalData
.
fire
({
terminal
,
data
});
}
}
public
async
$acceptTerminalDimensions
(
id
:
number
,
cols
:
number
,
rows
:
number
):
Promise
<
void
>
{
const
terminal
=
await
this
.
_getTerminalByIdEventually
(
id
);
if
(
terminal
)
{
if
(
terminal
.
setDimensions
(
cols
,
rows
))
{
this
.
_onDidChangeTerminalDimensions
.
fire
({
terminal
:
terminal
,
dimensions
:
terminal
.
dimensions
as
vscode
.
TerminalDimensions
});
}
}
}
public
async
$acceptTerminalMaximumDimensions
(
id
:
number
,
cols
:
number
,
rows
:
number
):
Promise
<
void
>
{
await
this
.
_getTerminalByIdEventually
(
id
);
if
(
this
.
_terminalProcesses
[
id
])
{
// Extension pty terminal only - when virtual process resize fires it means that the
// terminal's maximum dimensions changed
this
.
_terminalProcesses
[
id
].
resize
(
cols
,
rows
);
}
}
public
async
$acceptTerminalTitleChange
(
id
:
number
,
name
:
string
):
Promise
<
void
>
{
await
this
.
_getTerminalByIdEventually
(
id
);
const
extHostTerminal
=
this
.
_getTerminalObjectById
(
this
.
terminals
,
id
);
if
(
extHostTerminal
)
{
extHostTerminal
.
name
=
name
;
}
}
public
async
$acceptTerminalClosed
(
id
:
number
):
Promise
<
void
>
{
await
this
.
_getTerminalByIdEventually
(
id
);
const
index
=
this
.
_getTerminalObjectIndexById
(
this
.
terminals
,
id
);
if
(
index
!==
null
)
{
const
terminal
=
this
.
_terminals
.
splice
(
index
,
1
)[
0
];
this
.
_onDidCloseTerminal
.
fire
(
terminal
);
}
}
public
$acceptTerminalOpened
(
id
:
number
,
name
:
string
):
void
{
const
index
=
this
.
_getTerminalObjectIndexById
(
this
.
_terminals
,
id
);
if
(
index
!==
null
)
{
// The terminal has already been created (via createTerminal*), only fire the event
this
.
_onDidOpenTerminal
.
fire
(
this
.
terminals
[
index
]);
this
.
terminals
[
index
].
isOpen
=
true
;
return
;
}
const
terminal
=
new
ExtHostTerminal
(
this
.
_proxy
,
name
,
id
);
this
.
_terminals
.
push
(
terminal
);
this
.
_onDidOpenTerminal
.
fire
(
terminal
);
terminal
.
isOpen
=
true
;
}
public
async
$acceptTerminalProcessId
(
id
:
number
,
processId
:
number
):
Promise
<
void
>
{
const
terminal
=
await
this
.
_getTerminalByIdEventually
(
id
);
if
(
terminal
)
{
terminal
.
_setProcessId
(
processId
);
}
}
public
performTerminalIdAction
(
id
:
number
,
callback
:
(
terminal
:
ExtHostTerminal
)
=>
void
):
void
{
// TODO: Use await this._getTerminalByIdEventually(id);
let
terminal
=
this
.
_getTerminalById
(
id
);
if
(
terminal
)
{
callback
(
terminal
);
}
else
{
// Retry one more time in case the terminal has not yet been initialized.
setTimeout
(()
=>
{
terminal
=
this
.
_getTerminalById
(
id
);
if
(
terminal
)
{
callback
(
terminal
);
}
},
EXT_HOST_CREATION_DELAY
*
2
);
}
}
private
_apiInspectConfigToPlain
<
T
>
(
config
:
{
key
:
string
;
defaultValue
?:
T
;
globalValue
?:
T
;
workspaceValue
?:
T
,
workspaceFolderValue
?:
T
}
|
undefined
):
{
user
:
T
|
undefined
,
value
:
T
|
undefined
,
default
:
T
|
undefined
}
{
...
...
@@ -349,86 +195,6 @@ export class ExtHostTerminalService implements IExtHostTerminalService, ExtHostT
this
.
_setupExtHostProcessListeners
(
id
,
new
TerminalProcess
(
shellLaunchConfig
,
initialCwd
,
cols
,
rows
,
env
,
enableConpty
,
this
.
_logService
));
}
public
async
$startExtensionTerminal
(
id
:
number
,
initialDimensions
:
ITerminalDimensionsDto
|
undefined
):
Promise
<
void
>
{
// Make sure the ExtHostTerminal exists so onDidOpenTerminal has fired before we call
// Pseudoterminal.start
const
terminal
=
await
this
.
_getTerminalByIdEventually
(
id
);
if
(
!
terminal
)
{
return
;
}
// Wait for onDidOpenTerminal to fire
let
openPromise
:
Promise
<
void
>
;
if
(
terminal
.
isOpen
)
{
openPromise
=
Promise
.
resolve
();
}
else
{
openPromise
=
new
Promise
<
void
>
(
r
=>
{
// Ensure open is called after onDidOpenTerminal
const
listener
=
this
.
onDidOpenTerminal
(
async
e
=>
{
if
(
e
===
terminal
)
{
listener
.
dispose
();
r
();
}
});
});
}
await
openPromise
;
// Processes should be initialized here for normal virtual process terminals, however for
// tasks they are responsible for attaching the virtual process to a terminal so this
// function may be called before tasks is able to attach to the terminal.
let
retries
=
5
;
while
(
retries
--
>
0
)
{
if
(
this
.
_terminalProcesses
[
id
])
{
(
this
.
_terminalProcesses
[
id
]
as
ExtHostPseudoterminal
).
startSendingEvents
(
initialDimensions
);
return
;
}
await
timeout
(
50
);
}
}
private
_setupExtHostProcessListeners
(
id
:
number
,
p
:
ITerminalChildProcess
):
void
{
p
.
onProcessReady
((
e
:
{
pid
:
number
,
cwd
:
string
})
=>
this
.
_proxy
.
$sendProcessReady
(
id
,
e
.
pid
,
e
.
cwd
));
p
.
onProcessTitleChanged
(
title
=>
this
.
_proxy
.
$sendProcessTitle
(
id
,
title
));
p
.
onProcessData
(
data
=>
this
.
_proxy
.
$sendProcessData
(
id
,
data
));
p
.
onProcessExit
(
exitCode
=>
this
.
_onProcessExit
(
id
,
exitCode
));
if
(
p
.
onProcessOverrideDimensions
)
{
p
.
onProcessOverrideDimensions
(
e
=>
this
.
_proxy
.
$sendOverrideDimensions
(
id
,
e
));
}
this
.
_terminalProcesses
[
id
]
=
p
;
}
public
$acceptProcessInput
(
id
:
number
,
data
:
string
):
void
{
this
.
_terminalProcesses
[
id
].
input
(
data
);
}
public
$acceptProcessResize
(
id
:
number
,
cols
:
number
,
rows
:
number
):
void
{
try
{
this
.
_terminalProcesses
[
id
].
resize
(
cols
,
rows
);
}
catch
(
error
)
{
// We tried to write to a closed pipe / channel.
if
(
error
.
code
!==
'
EPIPE
'
&&
error
.
code
!==
'
ERR_IPC_CHANNEL_CLOSED
'
)
{
throw
(
error
);
}
}
}
public
$acceptProcessShutdown
(
id
:
number
,
immediate
:
boolean
):
void
{
this
.
_terminalProcesses
[
id
].
shutdown
(
immediate
);
}
public
$acceptProcessRequestInitialCwd
(
id
:
number
):
void
{
this
.
_terminalProcesses
[
id
].
getInitialCwd
().
then
(
initialCwd
=>
this
.
_proxy
.
$sendProcessInitialCwd
(
id
,
initialCwd
));
}
public
$acceptProcessRequestCwd
(
id
:
number
):
void
{
this
.
_terminalProcesses
[
id
].
getCwd
().
then
(
cwd
=>
this
.
_proxy
.
$sendProcessCwd
(
id
,
cwd
));
}
public
$acceptProcessRequestLatency
(
id
:
number
):
number
{
return
id
;
}
public
$requestAvailableShells
():
Promise
<
IShellDefinitionDto
[]
>
{
return
detectAvailableShells
();
}
...
...
@@ -441,66 +207,6 @@ export class ExtHostTerminalService implements IExtHostTerminalService, ExtHostT
});
}
private
_onProcessExit
(
id
:
number
,
exitCode
:
number
):
void
{
// Remove process reference
delete
this
.
_terminalProcesses
[
id
];
// Send exit event to main side
this
.
_proxy
.
$sendProcessExit
(
id
,
exitCode
);
}
// TODO: This could be improved by using a single promise and resolve it when the terminal is ready
private
_getTerminalByIdEventually
(
id
:
number
,
retries
:
number
=
5
):
Promise
<
ExtHostTerminal
|
undefined
>
{
if
(
!
this
.
_getTerminalPromises
[
id
])
{
this
.
_getTerminalPromises
[
id
]
=
this
.
_createGetTerminalPromise
(
id
,
retries
);
}
else
{
this
.
_getTerminalPromises
[
id
].
then
(
c
=>
{
return
this
.
_createGetTerminalPromise
(
id
,
retries
);
});
}
return
this
.
_getTerminalPromises
[
id
];
}
private
_createGetTerminalPromise
(
id
:
number
,
retries
:
number
=
5
):
Promise
<
ExtHostTerminal
>
{
return
new
Promise
(
c
=>
{
if
(
retries
===
0
)
{
c
(
undefined
);
return
;
}
const
terminal
=
this
.
_getTerminalById
(
id
);
if
(
terminal
)
{
c
(
terminal
);
}
else
{
// This should only be needed immediately after createTerminalRenderer is called as
// the ExtHostTerminal has not yet been iniitalized
timeout
(
200
).
then
(()
=>
c
(
this
.
_createGetTerminalPromise
(
id
,
retries
-
1
)));
}
});
}
private
_getTerminalById
(
id
:
number
):
ExtHostTerminal
|
null
{
return
this
.
_getTerminalObjectById
(
this
.
_terminals
,
id
);
}
private
_getTerminalObjectById
<
T
extends
ExtHostTerminal
>
(
array
:
T
[],
id
:
number
):
T
|
null
{
const
index
=
this
.
_getTerminalObjectIndexById
(
array
,
id
);
return
index
!==
null
?
array
[
index
]
:
null
;
}
private
_getTerminalObjectIndexById
<
T
extends
ExtHostTerminal
>
(
array
:
T
[],
id
:
number
):
number
|
null
{
let
index
:
number
|
null
=
null
;
array
.
some
((
item
,
i
)
=>
{
const
thisId
=
item
.
_id
;
if
(
thisId
===
id
)
{
index
=
i
;
return
true
;
}
return
false
;
});
return
index
;
}
public
$acceptWorkspacePermissionsChanged
(
isAllowed
:
boolean
):
void
{
this
.
_isWorkspaceShellAllowed
=
isAllowed
;
}
...
...
src/vs/workbench/services/extensions/worker/extHost.services.ts
浏览文件 @
63a0da43
...
...
@@ -10,7 +10,7 @@ import { IExtHostDecorations, ExtHostDecorations } from 'vs/workbench/api/common
import
{
IExtHostConfiguration
,
ExtHostConfiguration
}
from
'
vs/workbench/api/common/extHostConfiguration
'
;
import
{
IExtHostCommands
,
ExtHostCommands
}
from
'
vs/workbench/api/common/extHostCommands
'
;
import
{
IExtHostDocumentsAndEditors
,
ExtHostDocumentsAndEditors
}
from
'
vs/workbench/api/common/extHostDocumentsAndEditors
'
;
import
{
IExtHostTerminalService
}
from
'
vs/workbench/api/common/extHostTerminalService
'
;
import
{
IExtHostTerminalService
,
WorkerExtHostTerminalService
}
from
'
vs/workbench/api/common/extHostTerminalService
'
;
import
{
IExtHostTask
}
from
'
vs/workbench/api/common/extHostTask
'
;
import
{
IExtHostDebugService
}
from
'
vs/workbench/api/common/extHostDebugService
'
;
import
{
IExtHostSearch
}
from
'
vs/workbench/api/common/extHostSearch
'
;
...
...
@@ -48,7 +48,7 @@ function NotImplementedProxy<T>(name: ServiceIdentifier<T>): { new(): T } {
}
};
}
registerSingleton
(
IExtHostTerminalService
,
class
extends
NotImplementedProxy
(
IExtHostTerminalService
)
{
}
);
registerSingleton
(
IExtHostTerminalService
,
WorkerExtHostTerminalService
);
registerSingleton
(
IExtHostTask
,
class
extends
NotImplementedProxy
(
IExtHostTask
)
{
});
registerSingleton
(
IExtHostDebugService
,
class
extends
NotImplementedProxy
(
IExtHostDebugService
)
{
});
registerSingleton
(
IExtHostSearch
,
class
extends
NotImplementedProxy
(
IExtHostSearch
)
{
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录