@@ -32,43 +32,39 @@ import { IProductService } from 'vs/platform/product/common/productService';
32
32
import { join } from 'path' ;
33
33
import { memoize } from 'vs/base/common/decorators' ;
34
34
35
- export function traceRpc ( ) : Function {
36
- function createDecorator ( mapFn : ( fn : Function , key : string ) => Function ) : Function {
37
- return ( target : any , key : string , descriptor : any ) => {
38
- let fnKey : string | null = null ;
39
- let fn : Function | null = null ;
40
-
41
- if ( typeof descriptor . value === 'function' ) {
42
- fnKey = 'value' ;
43
- fn = descriptor . value ;
44
- } else if ( typeof descriptor . get === 'function' ) {
45
- fnKey = 'get' ;
46
- fn = descriptor . get ;
47
- }
35
+ export function traceRpc ( _target : any , key : string , descriptor : any ) {
36
+ let fnKey : string | null = null ;
37
+ let fn : Function | null = null ;
48
38
49
- if ( ! fn ) {
50
- throw new Error ( 'not supported' ) ;
51
- }
39
+ if ( typeof descriptor . value === 'function' ) {
40
+ fnKey = 'value' ;
41
+ fn = descriptor . value ;
52
42
53
- descriptor [ fnKey ! ] = mapFn ( fn , key ) ;
54
- } ;
43
+ if ( fn ! . length !== 0 ) {
44
+ console . warn ( 'Memoize should only be used in functions with zero parameters' ) ;
45
+ }
46
+ } else if ( typeof descriptor . get === 'function' ) {
47
+ fnKey = 'get' ;
48
+ fn = descriptor . get ;
55
49
}
56
- return createDecorator ( ( fn , key ) => {
57
- // The PtyService type is unsafe, this decorator should only be used on PtyService
58
- return async function ( this : PtyService , ...args : any [ ] ) {
59
- if ( this . traceRpcArgs . logService . getLevel ( ) === LogLevel . Trace ) {
60
- this . traceRpcArgs . logService . trace ( `[RPC Request] PtyService#${ fn . name } (${ args . map ( e => JSON . stringify ( e ) ) . join ( ', ' ) } )` ) ;
61
- }
62
- if ( this . traceRpcArgs . simulatedLatency ) {
63
- await timeout ( this . traceRpcArgs . simulatedLatency ) ;
64
- }
65
- const result = await fn . apply ( this , args ) ;
66
- if ( this . traceRpcArgs . logService . getLevel ( ) === LogLevel . Trace ) {
67
- this . traceRpcArgs . logService . trace ( `[RPC Response] PtyService#${ fn . name } ` , result ) ;
68
- }
69
- return result ;
70
- } ;
71
- } ) ;
50
+
51
+ if ( ! fn ) {
52
+ throw new Error ( 'not supported' ) ;
53
+ }
54
+
55
+ descriptor [ fnKey ! ] = async function ( ...args : any [ ] ) {
56
+ if ( this . traceRpcArgs . logService . getLevel ( ) === LogLevel . Trace ) {
57
+ this . traceRpcArgs . logService . trace ( `[RPC Request] PtyService#${ fnKey } (${ args . map ( e => JSON . stringify ( e ) ) . join ( ', ' ) } )` ) ;
58
+ }
59
+ if ( this . traceRpcArgs . simulatedLatency ) {
60
+ await timeout ( this . traceRpcArgs . simulatedLatency ) ;
61
+ }
62
+ const result = await fn . apply ( this , args ) ;
63
+ if ( this . traceRpcArgs . logService . getLevel ( ) === LogLevel . Trace ) {
64
+ this . traceRpcArgs . logService . trace ( `[RPC Response] PtyService#${ fnKey } ` , result ) ;
65
+ }
66
+ return result ;
67
+ } ;
72
68
}
73
69
74
70
type WorkspaceId = string ;
@@ -131,7 +127,7 @@ export class PtyService extends Disposable implements IPtyService {
131
127
this . _detachInstanceRequestStore . onCreateRequest ( this . _onDidRequestDetach . fire , this . _onDidRequestDetach ) ;
132
128
}
133
129
134
- @traceRpc ( )
130
+ @traceRpc
135
131
async refreshIgnoreProcessNames ( names : string [ ] ) : Promise < void > {
136
132
ignoreProcessNames . length = 0 ;
137
133
ignoreProcessNames . push ( ...names ) ;
@@ -143,12 +139,12 @@ export class PtyService extends Disposable implements IPtyService {
143
139
onPtyHostResponsive ?: Event < void > | undefined ;
144
140
onPtyHostRequestResolveVariables ?: Event < IRequestResolveVariablesEvent > | undefined ;
145
141
146
- @traceRpc ( )
142
+ @traceRpc
147
143
async requestDetachInstance ( workspaceId : string , instanceId : number ) : Promise < IProcessDetails | undefined > {
148
144
return this . _detachInstanceRequestStore . createRequest ( { workspaceId, instanceId } ) ;
149
145
}
150
146
151
- @traceRpc ( )
147
+ @traceRpc
152
148
async acceptDetachInstanceReply ( requestId : number , persistentProcessId : number ) : Promise < void > {
153
149
let processDetails : IProcessDetails | undefined = undefined ;
154
150
const pty = this . _ptys . get ( persistentProcessId ) ;
@@ -158,7 +154,7 @@ export class PtyService extends Disposable implements IPtyService {
158
154
this . _detachInstanceRequestStore . acceptReply ( requestId , processDetails ) ;
159
155
}
160
156
161
- @traceRpc ( )
157
+ @traceRpc
162
158
async freePortKillProcess ( port : string ) : Promise < { port : string ; processId : string } > {
163
159
const stdout = await new Promise < string > ( ( resolve , reject ) => {
164
160
exec ( isWindows ? `netstat -ano | findstr "${ port } "` : `lsof -nP -iTCP -sTCP:LISTEN | grep ${ port } ` , { } , ( err , stdout ) => {
@@ -184,7 +180,7 @@ export class PtyService extends Disposable implements IPtyService {
184
180
throw new Error ( `Could not kill process with port ${ port } ` ) ;
185
181
}
186
182
187
- @traceRpc ( )
183
+ @traceRpc
188
184
async serializeTerminalState ( ids : number [ ] ) : Promise < string > {
189
185
const promises : Promise < ISerializedTerminalState > [ ] = [ ] ;
190
186
for ( const [ persistentProcessId , persistentProcess ] of this . _ptys . entries ( ) ) {
@@ -210,7 +206,7 @@ export class PtyService extends Disposable implements IPtyService {
210
206
return JSON . stringify ( serialized ) ;
211
207
}
212
208
213
- @traceRpc ( )
209
+ @traceRpc
214
210
async reviveTerminalProcesses ( state : ISerializedTerminalState [ ] , dateTimeFormatLocale : string ) {
215
211
for ( const terminal of state ) {
216
212
const restoreMessage = localize ( 'terminal-history-restored' , "History restored" ) ;
@@ -244,12 +240,12 @@ export class PtyService extends Disposable implements IPtyService {
244
240
}
245
241
}
246
242
247
- @traceRpc ( )
243
+ @traceRpc
248
244
async shutdownAll ( ) : Promise < void > {
249
245
this . dispose ( ) ;
250
246
}
251
247
252
- @traceRpc ( )
248
+ @traceRpc
253
249
async createProcess (
254
250
shellLaunchConfig : IShellLaunchConfig ,
255
251
cwd : string ,
@@ -296,7 +292,7 @@ export class PtyService extends Disposable implements IPtyService {
296
292
return id ;
297
293
}
298
294
299
- @traceRpc ( )
295
+ @traceRpc
300
296
async attachToProcess ( id : number ) : Promise < void > {
301
297
try {
302
298
await this . _throwIfNoPty ( id ) . attach ( ) ;
@@ -307,44 +303,44 @@ export class PtyService extends Disposable implements IPtyService {
307
303
}
308
304
}
309
305
310
- @traceRpc ( )
306
+ @traceRpc
311
307
async updateTitle ( id : number , title : string , titleSource : TitleEventSource ) : Promise < void > {
312
308
this . _throwIfNoPty ( id ) . setTitle ( title , titleSource ) ;
313
309
}
314
310
315
- @traceRpc ( )
311
+ @traceRpc
316
312
async updateIcon ( id : number , userInitiated : boolean , icon : URI | { light : URI ; dark : URI } | { id : string ; color ?: { id : string } } , color ?: string ) : Promise < void > {
317
313
this . _throwIfNoPty ( id ) . setIcon ( userInitiated , icon , color ) ;
318
314
}
319
315
320
- @traceRpc ( )
316
+ @traceRpc
321
317
async clearBuffer ( id : number ) : Promise < void > {
322
318
this . _throwIfNoPty ( id ) . clearBuffer ( ) ;
323
319
}
324
320
325
- @traceRpc ( )
321
+ @traceRpc
326
322
async refreshProperty < T extends ProcessPropertyType > ( id : number , type : T ) : Promise < IProcessPropertyMap [ T ] > {
327
323
return this . _throwIfNoPty ( id ) . refreshProperty ( type ) ;
328
324
}
329
325
330
- @traceRpc ( )
326
+ @traceRpc
331
327
async updateProperty < T extends ProcessPropertyType > ( id : number , type : T , value : IProcessPropertyMap [ T ] ) : Promise < void > {
332
328
return this . _throwIfNoPty ( id ) . updateProperty ( type , value ) ;
333
329
}
334
330
335
- @traceRpc ( )
331
+ @traceRpc
336
332
async detachFromProcess ( id : number , forcePersist ?: boolean ) : Promise < void > {
337
333
return this . _throwIfNoPty ( id ) . detach ( forcePersist ) ;
338
334
}
339
335
340
- @traceRpc ( )
336
+ @traceRpc
341
337
async reduceConnectionGraceTime ( ) : Promise < void > {
342
338
for ( const pty of this . _ptys . values ( ) ) {
343
339
pty . reduceGraceTime ( ) ;
344
340
}
345
341
}
346
342
347
- @traceRpc ( )
343
+ @traceRpc
348
344
async listProcesses ( ) : Promise < IProcessDetails [ ] > {
349
345
const persistentProcesses = Array . from ( this . _ptys . entries ( ) ) . filter ( ( [ _ , pty ] ) => pty . shouldPersistTerminal ) ;
350
346
@@ -354,88 +350,88 @@ export class PtyService extends Disposable implements IPtyService {
354
350
return allTerminals . filter ( entry => entry . isOrphan ) ;
355
351
}
356
352
357
- @traceRpc ( )
353
+ @traceRpc
358
354
async start ( id : number ) : Promise < ITerminalLaunchError | { injectedArgs : string [ ] } | undefined > {
359
355
const pty = this . _ptys . get ( id ) ;
360
356
return pty ? pty . start ( ) : { message : `Could not find pty with id "${ id } "` } ;
361
357
}
362
358
363
- @traceRpc ( )
359
+ @traceRpc
364
360
async shutdown ( id : number , immediate : boolean ) : Promise < void > {
365
361
// Don't throw if the pty is already shutdown
366
362
return this . _ptys . get ( id ) ?. shutdown ( immediate ) ;
367
363
}
368
- @traceRpc ( )
364
+ @traceRpc
369
365
async input ( id : number , data : string ) : Promise < void > {
370
366
return this . _throwIfNoPty ( id ) . input ( data ) ;
371
367
}
372
- @traceRpc ( )
368
+ @traceRpc
373
369
async processBinary ( id : number , data : string ) : Promise < void > {
374
370
return this . _throwIfNoPty ( id ) . writeBinary ( data ) ;
375
371
}
376
- @traceRpc ( )
372
+ @traceRpc
377
373
async resize ( id : number , cols : number , rows : number ) : Promise < void > {
378
374
return this . _throwIfNoPty ( id ) . resize ( cols , rows ) ;
379
375
}
380
- @traceRpc ( )
376
+ @traceRpc
381
377
async getInitialCwd ( id : number ) : Promise < string > {
382
378
return this . _throwIfNoPty ( id ) . getInitialCwd ( ) ;
383
379
}
384
- @traceRpc ( )
380
+ @traceRpc
385
381
async getCwd ( id : number ) : Promise < string > {
386
382
return this . _throwIfNoPty ( id ) . getCwd ( ) ;
387
383
}
388
- @traceRpc ( )
384
+ @traceRpc
389
385
async acknowledgeDataEvent ( id : number , charCount : number ) : Promise < void > {
390
386
return this . _throwIfNoPty ( id ) . acknowledgeDataEvent ( charCount ) ;
391
387
}
392
- @traceRpc ( )
388
+ @traceRpc
393
389
async setUnicodeVersion ( id : number , version : '6' | '11' ) : Promise < void > {
394
390
return this . _throwIfNoPty ( id ) . setUnicodeVersion ( version ) ;
395
391
}
396
- @traceRpc ( )
392
+ @traceRpc
397
393
async getLatency ( id : number ) : Promise < number > {
398
394
return 0 ;
399
395
}
400
- @traceRpc ( )
396
+ @traceRpc
401
397
async orphanQuestionReply ( id : number ) : Promise < void > {
402
398
return this . _throwIfNoPty ( id ) . orphanQuestionReply ( ) ;
403
399
}
404
400
405
- @traceRpc ( )
401
+ @traceRpc
406
402
async installAutoReply ( match : string , reply : string ) {
407
403
this . _autoReplies . set ( match , reply ) ;
408
404
// If the auto reply exists on any existing terminals it will be overridden
409
405
for ( const p of this . _ptys . values ( ) ) {
410
406
p . installAutoReply ( match , reply ) ;
411
407
}
412
408
}
413
- @traceRpc ( )
409
+ @traceRpc
414
410
async uninstallAllAutoReplies ( ) {
415
411
for ( const match of this . _autoReplies . keys ( ) ) {
416
412
for ( const p of this . _ptys . values ( ) ) {
417
413
p . uninstallAutoReply ( match ) ;
418
414
}
419
415
}
420
416
}
421
- @traceRpc ( )
417
+ @traceRpc
422
418
async uninstallAutoReply ( match : string ) {
423
419
for ( const p of this . _ptys . values ( ) ) {
424
420
p . uninstallAutoReply ( match ) ;
425
421
}
426
422
}
427
423
428
- @traceRpc ( )
424
+ @traceRpc
429
425
async getDefaultSystemShell ( osOverride : OperatingSystem = OS ) : Promise < string > {
430
426
return getSystemShell ( osOverride , process . env ) ;
431
427
}
432
428
433
- @traceRpc ( )
429
+ @traceRpc
434
430
async getEnvironment ( ) : Promise < IProcessEnvironment > {
435
431
return { ...process . env } ;
436
432
}
437
433
438
- @traceRpc ( )
434
+ @traceRpc
439
435
async getWslPath ( original : string , direction : 'unix-to-win' | 'win-to-unix' | unknown ) : Promise < string > {
440
436
if ( direction === 'win-to-unix' ) {
441
437
if ( ! isWindows ) {
@@ -488,7 +484,7 @@ export class PtyService extends Disposable implements IPtyService {
488
484
return undefined ;
489
485
}
490
486
491
- @traceRpc ( )
487
+ @traceRpc
492
488
async getRevivedPtyNewId ( id : number ) : Promise < number | undefined > {
493
489
try {
494
490
return this . _revivedPtyIdMap . get ( id ) ?. newId ;
@@ -498,12 +494,12 @@ export class PtyService extends Disposable implements IPtyService {
498
494
return undefined ;
499
495
}
500
496
501
- @traceRpc ( )
497
+ @traceRpc
502
498
async setTerminalLayoutInfo ( args : ISetTerminalLayoutInfoArgs ) : Promise < void > {
503
499
this . _workspaceLayoutInfos . set ( args . workspaceId , args ) ;
504
500
}
505
501
506
- @traceRpc ( )
502
+ @traceRpc
507
503
async getTerminalLayoutInfo ( args : IGetTerminalLayoutInfoArgs ) : Promise < ITerminalsLayoutInfo | undefined > {
508
504
const layout = this . _workspaceLayoutInfos . get ( args . workspaceId ) ;
509
505
if ( layout ) {
0 commit comments