@@ -20,49 +20,73 @@ import { IReconnectConstants, TerminalIpcChannels } from 'vs/platform/terminal/c
20
20
import { HeartbeatService } from 'vs/platform/terminal/node/heartbeatService' ;
21
21
import { PtyService } from 'vs/platform/terminal/node/ptyService' ;
22
22
import { isUtilityProcess } from 'vs/base/parts/sandbox/node/electronTypes' ;
23
+ import { timeout } from 'vs/base/common/async' ;
23
24
24
- const _isUtilityProcess = isUtilityProcess ( process ) ;
25
+ startPtyHost ( ) ;
25
26
26
- let server : ChildProcessServer < string > | UtilityProcessServer ;
27
- if ( _isUtilityProcess ) {
28
- server = new UtilityProcessServer ( ) ;
29
- } else {
30
- server = new ChildProcessServer ( TerminalIpcChannels . PtyHost ) ;
31
- }
27
+ async function startPtyHost ( ) {
28
+ // Parse environment variables
29
+ const startupDelay = parseInt ( process . env . VSCODE_STARTUP_DELAY ?? '0' ) ;
30
+ const simulatedLatency = parseInt ( process . env . VSCODE_LATENCY ?? '0' ) ;
31
+ const reconnectConstants : IReconnectConstants = {
32
+ graceTime : parseInt ( process . env . VSCODE_RECONNECT_GRACE_TIME || '0' ) ,
33
+ shortGraceTime : parseInt ( process . env . VSCODE_RECONNECT_SHORT_GRACE_TIME || '0' ) ,
34
+ scrollback : parseInt ( process . env . VSCODE_RECONNECT_SCROLLBACK || '100' )
35
+ } ;
36
+ const lastPtyId = parseInt ( process . env . VSCODE_LAST_PTY_ID || '0' ) ;
32
37
33
- const lastPtyId = parseInt ( process . env . VSCODE_LAST_PTY_ID || '0' ) ;
34
- delete process . env . VSCODE_LAST_PTY_ID ;
38
+ // Sanitize environment
39
+ delete process . env . VSCODE_RECONNECT_GRACE_TIME ;
40
+ delete process . env . VSCODE_RECONNECT_SHORT_GRACE_TIME ;
41
+ delete process . env . VSCODE_RECONNECT_SCROLLBACK ;
42
+ delete process . env . VSCODE_LATENCY ;
43
+ delete process . env . VSCODE_STARTUP_DELAY ;
44
+ delete process . env . VSCODE_LAST_PTY_ID ;
35
45
36
- const productService : IProductService = { _serviceBrand : undefined , ...product } ;
37
- const environmentService = new NativeEnvironmentService ( parseArgs ( process . argv , OPTIONS ) , productService ) ;
46
+ // Setup RPC
47
+ const _isUtilityProcess = isUtilityProcess ( process ) ;
48
+ let server : ChildProcessServer < string > | UtilityProcessServer ;
49
+ if ( _isUtilityProcess ) {
50
+ server = new UtilityProcessServer ( ) ;
51
+ } else {
52
+ server = new ChildProcessServer ( TerminalIpcChannels . PtyHost ) ;
53
+ }
38
54
39
- // Logging
40
- const loggerService = new LoggerService ( getLogLevel ( environmentService ) , environmentService . logsHome ) ;
41
- server . registerChannel ( TerminalIpcChannels . Logger , new LoggerChannel ( loggerService , ( ) => DefaultURITransformer ) ) ;
42
- const logger = loggerService . createLogger ( 'ptyhost' , { name : localize ( 'ptyHost' , "Pty Host" ) } ) ;
43
- const logService = new LogService ( logger , [ new ConsoleLogger ( ) ] ) ;
55
+ // Services
56
+ const productService : IProductService = { _serviceBrand : undefined , ...product } ;
57
+ const environmentService = new NativeEnvironmentService ( parseArgs ( process . argv , OPTIONS ) , productService ) ;
58
+ const loggerService = new LoggerService ( getLogLevel ( environmentService ) , environmentService . logsHome ) ;
59
+ server . registerChannel ( TerminalIpcChannels . Logger , new LoggerChannel ( loggerService , ( ) => DefaultURITransformer ) ) ;
60
+ const logger = loggerService . createLogger ( 'ptyhost' , { name : localize ( 'ptyHost' , "Pty Host" ) } ) ;
61
+ const logService = new LogService ( logger , [ new ConsoleLogger ( ) ] ) ;
44
62
45
- const heartbeatService = new HeartbeatService ( ) ;
46
- server . registerChannel ( TerminalIpcChannels . Heartbeat , ProxyChannel . fromService ( heartbeatService ) ) ;
63
+ // Log and apply developer config
64
+ if ( startupDelay ) {
65
+ logService . warn ( `Pty Host startup is delayed ${ startupDelay } ms` ) ;
66
+ await timeout ( startupDelay ) ;
67
+ }
68
+ if ( simulatedLatency ) {
69
+ logService . warn ( `Pty host is simulating ${ simulatedLatency } ms latency` ) ;
70
+ }
47
71
48
- const reconnectConstants : IReconnectConstants = {
49
- graceTime : parseInt ( process . env . VSCODE_RECONNECT_GRACE_TIME || '0' ) ,
50
- shortGraceTime : parseInt ( process . env . VSCODE_RECONNECT_SHORT_GRACE_TIME || '0' ) ,
51
- scrollback : parseInt ( process . env . VSCODE_RECONNECT_SCROLLBACK || '100' )
52
- } ;
53
- delete process . env . VSCODE_RECONNECT_GRACE_TIME ;
54
- delete process . env . VSCODE_RECONNECT_SHORT_GRACE_TIME ;
55
- delete process . env . VSCODE_RECONNECT_SCROLLBACK ;
72
+ // Heartbeat responsiveness tracking
73
+ const heartbeatService = new HeartbeatService ( ) ;
74
+ server . registerChannel ( TerminalIpcChannels . Heartbeat , ProxyChannel . fromService ( heartbeatService ) ) ;
56
75
57
- const ptyService = new PtyService ( lastPtyId , logService , productService , reconnectConstants ) ;
58
- const ptyServiceChannel = ProxyChannel . fromService ( ptyService ) ;
59
- server . registerChannel ( TerminalIpcChannels . PtyHost , ptyServiceChannel ) ;
60
- if ( _isUtilityProcess ) {
61
- server . registerChannel ( TerminalIpcChannels . PtyHostWindow , ptyServiceChannel ) ;
62
- }
76
+ // Init pty service
77
+ const ptyService = new PtyService ( lastPtyId , logService , productService , reconnectConstants , simulatedLatency ) ;
78
+ const ptyServiceChannel = ProxyChannel . fromService ( ptyService ) ;
79
+ server . registerChannel ( TerminalIpcChannels . PtyHost , ptyServiceChannel ) ;
63
80
64
- process . once ( 'exit' , ( ) => {
65
- logService . dispose ( ) ;
66
- heartbeatService . dispose ( ) ;
67
- ptyService . dispose ( ) ;
68
- } ) ;
81
+ // Register a channel for direct communication via Message Port
82
+ if ( _isUtilityProcess ) {
83
+ server . registerChannel ( TerminalIpcChannels . PtyHostWindow , ptyServiceChannel ) ;
84
+ }
85
+
86
+ // Clean up
87
+ process . once ( 'exit' , ( ) => {
88
+ logService . dispose ( ) ;
89
+ heartbeatService . dispose ( ) ;
90
+ ptyService . dispose ( ) ;
91
+ } ) ;
92
+ }
0 commit comments