@@ -32,43 +32,39 @@ import { IProductService } from 'vs/platform/product/common/productService';
3232import { join } from 'path' ;
3333import { memoize } from 'vs/base/common/decorators' ;
3434
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 ;
4838
49- if ( ! fn ) {
50- throw new Error ( 'not supported' ) ;
51- }
39+ if ( typeof descriptor . value === 'function' ) {
40+ fnKey = 'value' ;
41+ fn = descriptor . value ;
5242
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 ;
5549 }
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+ } ;
7268}
7369
7470type WorkspaceId = string ;
@@ -131,7 +127,7 @@ export class PtyService extends Disposable implements IPtyService {
131127 this . _detachInstanceRequestStore . onCreateRequest ( this . _onDidRequestDetach . fire , this . _onDidRequestDetach ) ;
132128 }
133129
134- @traceRpc ( )
130+ @traceRpc
135131 async refreshIgnoreProcessNames ( names : string [ ] ) : Promise < void > {
136132 ignoreProcessNames . length = 0 ;
137133 ignoreProcessNames . push ( ...names ) ;
@@ -143,12 +139,12 @@ export class PtyService extends Disposable implements IPtyService {
143139 onPtyHostResponsive ?: Event < void > | undefined ;
144140 onPtyHostRequestResolveVariables ?: Event < IRequestResolveVariablesEvent > | undefined ;
145141
146- @traceRpc ( )
142+ @traceRpc
147143 async requestDetachInstance ( workspaceId : string , instanceId : number ) : Promise < IProcessDetails | undefined > {
148144 return this . _detachInstanceRequestStore . createRequest ( { workspaceId, instanceId } ) ;
149145 }
150146
151- @traceRpc ( )
147+ @traceRpc
152148 async acceptDetachInstanceReply ( requestId : number , persistentProcessId : number ) : Promise < void > {
153149 let processDetails : IProcessDetails | undefined = undefined ;
154150 const pty = this . _ptys . get ( persistentProcessId ) ;
@@ -158,7 +154,7 @@ export class PtyService extends Disposable implements IPtyService {
158154 this . _detachInstanceRequestStore . acceptReply ( requestId , processDetails ) ;
159155 }
160156
161- @traceRpc ( )
157+ @traceRpc
162158 async freePortKillProcess ( port : string ) : Promise < { port : string ; processId : string } > {
163159 const stdout = await new Promise < string > ( ( resolve , reject ) => {
164160 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 {
184180 throw new Error ( `Could not kill process with port ${ port } ` ) ;
185181 }
186182
187- @traceRpc ( )
183+ @traceRpc
188184 async serializeTerminalState ( ids : number [ ] ) : Promise < string > {
189185 const promises : Promise < ISerializedTerminalState > [ ] = [ ] ;
190186 for ( const [ persistentProcessId , persistentProcess ] of this . _ptys . entries ( ) ) {
@@ -210,7 +206,7 @@ export class PtyService extends Disposable implements IPtyService {
210206 return JSON . stringify ( serialized ) ;
211207 }
212208
213- @traceRpc ( )
209+ @traceRpc
214210 async reviveTerminalProcesses ( state : ISerializedTerminalState [ ] , dateTimeFormatLocale : string ) {
215211 for ( const terminal of state ) {
216212 const restoreMessage = localize ( 'terminal-history-restored' , "History restored" ) ;
@@ -244,12 +240,12 @@ export class PtyService extends Disposable implements IPtyService {
244240 }
245241 }
246242
247- @traceRpc ( )
243+ @traceRpc
248244 async shutdownAll ( ) : Promise < void > {
249245 this . dispose ( ) ;
250246 }
251247
252- @traceRpc ( )
248+ @traceRpc
253249 async createProcess (
254250 shellLaunchConfig : IShellLaunchConfig ,
255251 cwd : string ,
@@ -296,7 +292,7 @@ export class PtyService extends Disposable implements IPtyService {
296292 return id ;
297293 }
298294
299- @traceRpc ( )
295+ @traceRpc
300296 async attachToProcess ( id : number ) : Promise < void > {
301297 try {
302298 await this . _throwIfNoPty ( id ) . attach ( ) ;
@@ -307,44 +303,44 @@ export class PtyService extends Disposable implements IPtyService {
307303 }
308304 }
309305
310- @traceRpc ( )
306+ @traceRpc
311307 async updateTitle ( id : number , title : string , titleSource : TitleEventSource ) : Promise < void > {
312308 this . _throwIfNoPty ( id ) . setTitle ( title , titleSource ) ;
313309 }
314310
315- @traceRpc ( )
311+ @traceRpc
316312 async updateIcon ( id : number , userInitiated : boolean , icon : URI | { light : URI ; dark : URI } | { id : string ; color ?: { id : string } } , color ?: string ) : Promise < void > {
317313 this . _throwIfNoPty ( id ) . setIcon ( userInitiated , icon , color ) ;
318314 }
319315
320- @traceRpc ( )
316+ @traceRpc
321317 async clearBuffer ( id : number ) : Promise < void > {
322318 this . _throwIfNoPty ( id ) . clearBuffer ( ) ;
323319 }
324320
325- @traceRpc ( )
321+ @traceRpc
326322 async refreshProperty < T extends ProcessPropertyType > ( id : number , type : T ) : Promise < IProcessPropertyMap [ T ] > {
327323 return this . _throwIfNoPty ( id ) . refreshProperty ( type ) ;
328324 }
329325
330- @traceRpc ( )
326+ @traceRpc
331327 async updateProperty < T extends ProcessPropertyType > ( id : number , type : T , value : IProcessPropertyMap [ T ] ) : Promise < void > {
332328 return this . _throwIfNoPty ( id ) . updateProperty ( type , value ) ;
333329 }
334330
335- @traceRpc ( )
331+ @traceRpc
336332 async detachFromProcess ( id : number , forcePersist ?: boolean ) : Promise < void > {
337333 return this . _throwIfNoPty ( id ) . detach ( forcePersist ) ;
338334 }
339335
340- @traceRpc ( )
336+ @traceRpc
341337 async reduceConnectionGraceTime ( ) : Promise < void > {
342338 for ( const pty of this . _ptys . values ( ) ) {
343339 pty . reduceGraceTime ( ) ;
344340 }
345341 }
346342
347- @traceRpc ( )
343+ @traceRpc
348344 async listProcesses ( ) : Promise < IProcessDetails [ ] > {
349345 const persistentProcesses = Array . from ( this . _ptys . entries ( ) ) . filter ( ( [ _ , pty ] ) => pty . shouldPersistTerminal ) ;
350346
@@ -354,88 +350,88 @@ export class PtyService extends Disposable implements IPtyService {
354350 return allTerminals . filter ( entry => entry . isOrphan ) ;
355351 }
356352
357- @traceRpc ( )
353+ @traceRpc
358354 async start ( id : number ) : Promise < ITerminalLaunchError | { injectedArgs : string [ ] } | undefined > {
359355 const pty = this . _ptys . get ( id ) ;
360356 return pty ? pty . start ( ) : { message : `Could not find pty with id "${ id } "` } ;
361357 }
362358
363- @traceRpc ( )
359+ @traceRpc
364360 async shutdown ( id : number , immediate : boolean ) : Promise < void > {
365361 // Don't throw if the pty is already shutdown
366362 return this . _ptys . get ( id ) ?. shutdown ( immediate ) ;
367363 }
368- @traceRpc ( )
364+ @traceRpc
369365 async input ( id : number , data : string ) : Promise < void > {
370366 return this . _throwIfNoPty ( id ) . input ( data ) ;
371367 }
372- @traceRpc ( )
368+ @traceRpc
373369 async processBinary ( id : number , data : string ) : Promise < void > {
374370 return this . _throwIfNoPty ( id ) . writeBinary ( data ) ;
375371 }
376- @traceRpc ( )
372+ @traceRpc
377373 async resize ( id : number , cols : number , rows : number ) : Promise < void > {
378374 return this . _throwIfNoPty ( id ) . resize ( cols , rows ) ;
379375 }
380- @traceRpc ( )
376+ @traceRpc
381377 async getInitialCwd ( id : number ) : Promise < string > {
382378 return this . _throwIfNoPty ( id ) . getInitialCwd ( ) ;
383379 }
384- @traceRpc ( )
380+ @traceRpc
385381 async getCwd ( id : number ) : Promise < string > {
386382 return this . _throwIfNoPty ( id ) . getCwd ( ) ;
387383 }
388- @traceRpc ( )
384+ @traceRpc
389385 async acknowledgeDataEvent ( id : number , charCount : number ) : Promise < void > {
390386 return this . _throwIfNoPty ( id ) . acknowledgeDataEvent ( charCount ) ;
391387 }
392- @traceRpc ( )
388+ @traceRpc
393389 async setUnicodeVersion ( id : number , version : '6' | '11' ) : Promise < void > {
394390 return this . _throwIfNoPty ( id ) . setUnicodeVersion ( version ) ;
395391 }
396- @traceRpc ( )
392+ @traceRpc
397393 async getLatency ( id : number ) : Promise < number > {
398394 return 0 ;
399395 }
400- @traceRpc ( )
396+ @traceRpc
401397 async orphanQuestionReply ( id : number ) : Promise < void > {
402398 return this . _throwIfNoPty ( id ) . orphanQuestionReply ( ) ;
403399 }
404400
405- @traceRpc ( )
401+ @traceRpc
406402 async installAutoReply ( match : string , reply : string ) {
407403 this . _autoReplies . set ( match , reply ) ;
408404 // If the auto reply exists on any existing terminals it will be overridden
409405 for ( const p of this . _ptys . values ( ) ) {
410406 p . installAutoReply ( match , reply ) ;
411407 }
412408 }
413- @traceRpc ( )
409+ @traceRpc
414410 async uninstallAllAutoReplies ( ) {
415411 for ( const match of this . _autoReplies . keys ( ) ) {
416412 for ( const p of this . _ptys . values ( ) ) {
417413 p . uninstallAutoReply ( match ) ;
418414 }
419415 }
420416 }
421- @traceRpc ( )
417+ @traceRpc
422418 async uninstallAutoReply ( match : string ) {
423419 for ( const p of this . _ptys . values ( ) ) {
424420 p . uninstallAutoReply ( match ) ;
425421 }
426422 }
427423
428- @traceRpc ( )
424+ @traceRpc
429425 async getDefaultSystemShell ( osOverride : OperatingSystem = OS ) : Promise < string > {
430426 return getSystemShell ( osOverride , process . env ) ;
431427 }
432428
433- @traceRpc ( )
429+ @traceRpc
434430 async getEnvironment ( ) : Promise < IProcessEnvironment > {
435431 return { ...process . env } ;
436432 }
437433
438- @traceRpc ( )
434+ @traceRpc
439435 async getWslPath ( original : string , direction : 'unix-to-win' | 'win-to-unix' | unknown ) : Promise < string > {
440436 if ( direction === 'win-to-unix' ) {
441437 if ( ! isWindows ) {
@@ -488,7 +484,7 @@ export class PtyService extends Disposable implements IPtyService {
488484 return undefined ;
489485 }
490486
491- @traceRpc ( )
487+ @traceRpc
492488 async getRevivedPtyNewId ( id : number ) : Promise < number | undefined > {
493489 try {
494490 return this . _revivedPtyIdMap . get ( id ) ?. newId ;
@@ -498,12 +494,12 @@ export class PtyService extends Disposable implements IPtyService {
498494 return undefined ;
499495 }
500496
501- @traceRpc ( )
497+ @traceRpc
502498 async setTerminalLayoutInfo ( args : ISetTerminalLayoutInfoArgs ) : Promise < void > {
503499 this . _workspaceLayoutInfos . set ( args . workspaceId , args ) ;
504500 }
505501
506- @traceRpc ( )
502+ @traceRpc
507503 async getTerminalLayoutInfo ( args : IGetTerminalLayoutInfoArgs ) : Promise < ITerminalsLayoutInfo | undefined > {
508504 const layout = this . _workspaceLayoutInfos . get ( args . workspaceId ) ;
509505 if ( layout ) {
0 commit comments