@@ -30,54 +30,51 @@ import { formatMessageForTerminal } from 'vs/platform/terminal/common/terminalSt
30
30
import { IPtyHostProcessReplayEvent } from 'vs/platform/terminal/common/capabilities/capabilities' ;
31
31
import { IProductService } from 'vs/platform/product/common/productService' ;
32
32
import { join } from 'path' ;
33
+ import { memoize } from 'vs/base/common/decorators' ;
33
34
34
- type WorkspaceId = string ;
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
48
36
- let SerializeAddon : typeof XtermSerializeAddon ;
37
- let Unicode11Addon : typeof XtermUnicode11Addon ;
49
+ if ( ! fn ) {
50
+ throw new Error ( 'not supported' ) ;
51
+ }
38
52
39
- let traceLogService : ILogService | undefined ;
40
- let simulatedLatency : number = 0 ;
41
- export function traceRpc ( ) : Function {
53
+ descriptor [ fnKey ! ] = mapFn ( fn , key ) ;
54
+ } ;
55
+ }
42
56
return createDecorator ( ( fn , key ) => {
43
- return async function ( this : any , ... args : any [ ] ) {
44
-
45
- if ( traceLogService ? .getLevel ( ) === LogLevel . Trace ) {
46
- traceLogService ? .trace ( `[RPC Request] PtyService#${ fn . name } (${ args . map ( e => JSON . stringify ( e ) ) . join ( ', ' ) } )` ) ;
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 ( ', ' ) } )` ) ;
47
61
}
48
- // TODO: Use PtyService as this?
49
- if ( simulatedLatency ) {
50
- await timeout ( simulatedLatency ) ;
62
+ if ( this . traceRpcArgs . simulatedLatency ) {
63
+ await timeout ( this . traceRpcArgs . simulatedLatency ) ;
51
64
}
52
65
const result = await fn . apply ( this , args ) ;
53
- if ( traceLogService ? .getLevel ( ) === LogLevel . Trace ) {
54
- traceLogService ? .trace ( `[RPC Response] PtyService#${ fn . name } ` , result ) ;
66
+ if ( this . traceRpcArgs . logService . getLevel ( ) === LogLevel . Trace ) {
67
+ this . traceRpcArgs . logService . trace ( `[RPC Response] PtyService#${ fn . name } ` , result ) ;
55
68
}
56
69
return result ;
57
70
} ;
58
71
} ) ;
59
72
}
60
73
61
- function createDecorator ( mapFn : ( fn : Function , key : string ) => Function ) : Function {
62
- return ( target : any , key : string , descriptor : any ) => {
63
- let fnKey : string | null = null ;
64
- let fn : Function | null = null ;
65
-
66
- if ( typeof descriptor . value === 'function' ) {
67
- fnKey = 'value' ;
68
- fn = descriptor . value ;
69
- } else if ( typeof descriptor . get === 'function' ) {
70
- fnKey = 'get' ;
71
- fn = descriptor . get ;
72
- }
73
-
74
- if ( ! fn ) {
75
- throw new Error ( 'not supported' ) ;
76
- }
74
+ type WorkspaceId = string ;
77
75
78
- descriptor [ fnKey ! ] = mapFn ( fn , key ) ;
79
- } ;
80
- }
76
+ let SerializeAddon : typeof XtermSerializeAddon ;
77
+ let Unicode11Addon : typeof XtermUnicode11Addon ;
81
78
82
79
export class PtyService extends Disposable implements IPtyService {
83
80
declare readonly _serviceBrand : undefined ;
@@ -106,6 +103,14 @@ export class PtyService extends Disposable implements IPtyService {
106
103
private readonly _onDidChangeProperty = this . _register ( new Emitter < { id : number ; property : IProcessProperty < any > } > ( ) ) ;
107
104
readonly onDidChangeProperty = this . _onDidChangeProperty . event ;
108
105
106
+ @memoize
107
+ get traceRpcArgs ( ) : { logService : ILogService ; simulatedLatency : number } {
108
+ return {
109
+ logService : this . _logService ,
110
+ simulatedLatency : this . _simulatedLatency
111
+ } ;
112
+ }
113
+
109
114
constructor (
110
115
private _lastPtyId : number ,
111
116
private readonly _logService : ILogService ,
@@ -115,9 +120,6 @@ export class PtyService extends Disposable implements IPtyService {
115
120
) {
116
121
super ( ) ;
117
122
118
- traceLogService = this . _logService ;
119
- simulatedLatency = this . _simulatedLatency ;
120
-
121
123
this . _register ( toDisposable ( ( ) => {
122
124
for ( const pty of this . _ptys . values ( ) ) {
123
125
pty . shutdown ( true ) ;
0 commit comments