3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { DisposableStore , Disposable , IDisposable } from 'vs/base/common/lifecycle' ;
6
+ import { DisposableStore , Disposable , IDisposable , MutableDisposable } from 'vs/base/common/lifecycle' ;
7
7
import { ExtHostContext , ExtHostTerminalServiceShape , MainThreadTerminalServiceShape , MainContext , TerminalLaunchConfig , ITerminalDimensionsDto , ExtHostTerminalIdentifier , TerminalQuickFix } from 'vs/workbench/api/common/extHost.protocol' ;
8
8
import { extHostNamedCustomer , IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers' ;
9
9
import { URI } from 'vs/base/common/uri' ;
@@ -33,18 +33,19 @@ import { ITerminalQuickFixService, ITerminalQuickFixOptions, ITerminalQuickFix }
33
33
@extHostNamedCustomer ( MainContext . MainThreadTerminalService )
34
34
export class MainThreadTerminalService implements MainThreadTerminalServiceShape {
35
35
36
- private _proxy : ExtHostTerminalServiceShape ;
36
+ private readonly _store = new DisposableStore ( ) ;
37
+ private readonly _proxy : ExtHostTerminalServiceShape ;
38
+
37
39
/**
38
40
* Stores a map from a temporary terminal id (a UUID generated on the extension host side)
39
41
* to a numeric terminal id (an id generated on the renderer side)
40
42
* This comes in play only when dealing with terminals created on the extension host side
41
43
*/
42
- private _extHostTerminals = new Map < string , Promise < ITerminalInstance > > ( ) ;
43
- private readonly _toDispose = new DisposableStore ( ) ;
44
+ private readonly _extHostTerminals = new Map < string , Promise < ITerminalInstance > > ( ) ;
44
45
private readonly _terminalProcessProxies = new Map < number , ITerminalProcessExtHostProxy > ( ) ;
45
46
private readonly _profileProviders = new Map < string , IDisposable > ( ) ;
46
47
private readonly _quickFixProviders = new Map < string , IDisposable > ( ) ;
47
- private _dataEventTracker : TerminalDataEventTracker | undefined ;
48
+ private readonly _dataEventTracker = new MutableDisposable < TerminalDataEventTracker > ( ) ;
48
49
/**
49
50
* A single shared terminal link provider for the exthost. When an ext registers a link
50
51
* provider, this is registered with the terminal on the renderer side and all links are
@@ -72,25 +73,25 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
72
73
this . _proxy = _extHostContext . getProxy ( ExtHostContext . ExtHostTerminalService ) ;
73
74
74
75
// ITerminalService listeners
75
- this . _toDispose . add ( _terminalService . onDidCreateInstance ( ( instance ) => {
76
+ this . _store . add ( _terminalService . onDidCreateInstance ( ( instance ) => {
76
77
this . _onTerminalOpened ( instance ) ;
77
78
this . _onInstanceDimensionsChanged ( instance ) ;
78
79
} ) ) ;
79
80
80
- this . _toDispose . add ( _terminalService . onDidDisposeInstance ( instance => this . _onTerminalDisposed ( instance ) ) ) ;
81
- this . _toDispose . add ( _terminalService . onDidReceiveProcessId ( instance => this . _onTerminalProcessIdReady ( instance ) ) ) ;
82
- this . _toDispose . add ( _terminalService . onDidChangeInstanceDimensions ( instance => this . _onInstanceDimensionsChanged ( instance ) ) ) ;
83
- this . _toDispose . add ( _terminalService . onDidMaximumDimensionsChange ( instance => this . _onInstanceMaximumDimensionsChanged ( instance ) ) ) ;
84
- this . _toDispose . add ( _terminalService . onDidRequestStartExtensionTerminal ( e => this . _onRequestStartExtensionTerminal ( e ) ) ) ;
85
- this . _toDispose . add ( _terminalService . onDidChangeActiveInstance ( instance => this . _onActiveTerminalChanged ( instance ? instance . instanceId : null ) ) ) ;
86
- this . _toDispose . add ( _terminalService . onDidChangeInstanceTitle ( instance => instance && this . _onTitleChanged ( instance . instanceId , instance . title ) ) ) ;
87
- this . _toDispose . add ( _terminalService . onDidInputInstanceData ( instance => this . _proxy . $acceptTerminalInteraction ( instance . instanceId ) ) ) ;
81
+ this . _store . add ( _terminalService . onDidDisposeInstance ( instance => this . _onTerminalDisposed ( instance ) ) ) ;
82
+ this . _store . add ( _terminalService . onDidReceiveProcessId ( instance => this . _onTerminalProcessIdReady ( instance ) ) ) ;
83
+ this . _store . add ( _terminalService . onDidChangeInstanceDimensions ( instance => this . _onInstanceDimensionsChanged ( instance ) ) ) ;
84
+ this . _store . add ( _terminalService . onDidMaximumDimensionsChange ( instance => this . _onInstanceMaximumDimensionsChanged ( instance ) ) ) ;
85
+ this . _store . add ( _terminalService . onDidRequestStartExtensionTerminal ( e => this . _onRequestStartExtensionTerminal ( e ) ) ) ;
86
+ this . _store . add ( _terminalService . onDidChangeActiveInstance ( instance => this . _onActiveTerminalChanged ( instance ? instance . instanceId : null ) ) ) ;
87
+ this . _store . add ( _terminalService . onDidChangeInstanceTitle ( instance => instance && this . _onTitleChanged ( instance . instanceId , instance . title ) ) ) ;
88
+ this . _store . add ( _terminalService . onDidInputInstanceData ( instance => this . _proxy . $acceptTerminalInteraction ( instance . instanceId ) ) ) ;
88
89
89
90
// Set initial ext host state
90
- this . _terminalService . instances . forEach ( t => {
91
- this . _onTerminalOpened ( t ) ;
92
- t . processReady . then ( ( ) => this . _onTerminalProcessIdReady ( t ) ) ;
93
- } ) ;
91
+ for ( const instance of this . _terminalService . instances ) {
92
+ this . _onTerminalOpened ( instance ) ;
93
+ instance . processReady . then ( ( ) => this . _onTerminalProcessIdReady ( instance ) ) ;
94
+ }
94
95
const activeInstance = this . _terminalService . activeInstance ;
95
96
if ( activeInstance ) {
96
97
this . _proxy . $acceptActiveTerminalChanged ( activeInstance . instanceId ) ;
@@ -107,12 +108,18 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
107
108
this . _os = env ?. os || OS ;
108
109
this . _updateDefaultProfile ( ) ;
109
110
} ) ;
110
- this . _terminalProfileService . onDidChangeAvailableProfiles ( ( ) => this . _updateDefaultProfile ( ) ) ;
111
+ this . _store . add ( this . _terminalProfileService . onDidChangeAvailableProfiles ( ( ) => this . _updateDefaultProfile ( ) ) ) ;
111
112
}
112
113
113
114
public dispose ( ) : void {
114
- this . _toDispose . dispose ( ) ;
115
+ this . _store . dispose ( ) ;
115
116
this . _linkProvider ?. dispose ( ) ;
117
+ for ( const provider of this . _profileProviders . values ( ) ) {
118
+ provider . dispose ( ) ;
119
+ }
120
+ for ( const provider of this . _quickFixProviders . values ( ) ) {
121
+ provider . dispose ( ) ;
122
+ }
116
123
}
117
124
118
125
private async _updateDefaultProfile ( ) {
@@ -161,7 +168,7 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
161
168
} ) ;
162
169
this . _extHostTerminals . set ( extHostTerminalId , terminal ) ;
163
170
const terminalInstance = await terminal ;
164
- this . _toDispose . add ( terminalInstance . onDisposed ( ( ) => {
171
+ this . _store . add ( terminalInstance . onDisposed ( ( ) => {
165
172
this . _extHostTerminals . delete ( extHostTerminalId ) ;
166
173
} ) ) ;
167
174
}
@@ -208,20 +215,21 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
208
215
}
209
216
210
217
public $startSendingDataEvents ( ) : void {
211
- if ( ! this . _dataEventTracker ) {
212
- this . _dataEventTracker = this . _instantiationService . createInstance ( TerminalDataEventTracker , ( id , data ) => {
218
+ if ( ! this . _dataEventTracker . value ) {
219
+ this . _dataEventTracker . value = this . _instantiationService . createInstance ( TerminalDataEventTracker , ( id , data ) => {
213
220
this . _onTerminalData ( id , data ) ;
214
221
} ) ;
215
222
// Send initial events if they exist
216
- this . _terminalService . instances . forEach ( t => {
217
- t . initialDataEvents ?. forEach ( d => this . _onTerminalData ( t . instanceId , d ) ) ;
218
- } ) ;
223
+ for ( const instance of this . _terminalService . instances ) {
224
+ for ( const data of instance . initialDataEvents || [ ] ) {
225
+ this . _onTerminalData ( instance . instanceId , data ) ;
226
+ }
227
+ }
219
228
}
220
229
}
221
230
222
231
public $stopSendingDataEvents ( ) : void {
223
- this . _dataEventTracker ?. dispose ( ) ;
224
- this . _dataEventTracker = undefined ;
232
+ this . _dataEventTracker . clear ( ) ;
225
233
}
226
234
227
235
public $startLinkProvider ( ) : void {
@@ -429,7 +437,9 @@ class TerminalDataEventTracker extends Disposable {
429
437
430
438
this . _register ( this . _bufferer = new TerminalDataBufferer ( this . _callback ) ) ;
431
439
432
- this . _terminalService . instances . forEach ( instance => this . _registerInstance ( instance ) ) ;
440
+ for ( const instance of this . _terminalService . instances ) {
441
+ this . _registerInstance ( instance ) ;
442
+ }
433
443
this . _register ( this . _terminalService . onDidCreateInstance ( instance => this . _registerInstance ( instance ) ) ) ;
434
444
this . _register ( this . _terminalService . onDidDisposeInstance ( instance => this . _bufferer . stopBuffering ( instance . instanceId ) ) ) ;
435
445
}
0 commit comments