@@ -33,7 +33,7 @@ import * as os from 'os';
33
33
import { delay } from './common/promiseUtil' ;
34
34
import { Container } from 'inversify' ;
35
35
import { createTargetContainer , provideLaunchParams } from './ioc' ;
36
- import { disposeContainer } from './ioc-extras' ;
36
+ import { disposeContainer , IInitializeParams } from './ioc-extras' ;
37
37
38
38
const localize = nls . loadMessageBundle ( ) ;
39
39
@@ -51,16 +51,15 @@ export class Binder implements IDisposable {
51
51
private _delegate : IBinderDelegate ;
52
52
private _disposables : IDisposable [ ] ;
53
53
private _threads = new Map < ITarget , { thread : Thread ; debugAdapter : DebugAdapter } > ( ) ;
54
- private _launchers = new Set < ILauncher > ( ) ;
55
54
private _terminationCount = 0 ;
56
55
private _onTargetListChangedEmitter = new EventEmitter < void > ( ) ;
57
56
readonly onTargetListChanged = this . _onTargetListChangedEmitter . event ;
58
57
private _dap : Promise < Dap . Api > ;
59
58
private _targetOrigin : ITargetOrigin ;
60
59
private _launchParams ?: AnyLaunchConfiguration ;
61
- private _clientCapabilities : Dap . InitializeParams | undefined ;
62
60
private _asyncStackPolicy ?: IAsyncStackPolicy ;
63
61
private _serviceTree = new WeakMap < ITarget , Container > ( ) ;
62
+ private _launchers ?: ReadonlySet < ILauncher > ;
64
63
65
64
constructor (
66
65
delegate : IBinderDelegate ,
@@ -69,7 +68,6 @@ export class Binder implements IDisposable {
69
68
private readonly _rootServices : Container ,
70
69
targetOrigin : ITargetOrigin ,
71
70
) {
72
- this . _launchers = new Set ( _rootServices . getAll ( ILauncher ) ) ;
73
71
this . _delegate = delegate ;
74
72
this . _dap = connection . dap ( ) ;
75
73
this . _targetOrigin = targetOrigin ;
@@ -79,23 +77,9 @@ export class Binder implements IDisposable {
79
77
installUnhandledErrorReporter ( _rootServices . get ( ILogger ) , telemetryReporter ) ,
80
78
] ;
81
79
82
- for ( const launcher of this . _launchers ) {
83
- this . _launchers . add ( launcher ) ;
84
- launcher . onTargetListChanged (
85
- ( ) => {
86
- const targets = this . targetList ( ) ;
87
- this . _attachToNewTargets ( targets , launcher ) ;
88
- this . _detachOrphanThreads ( targets ) ;
89
- this . _onTargetListChangedEmitter . fire ( ) ;
90
- } ,
91
- undefined ,
92
- this . _disposables ,
93
- ) ;
94
- }
95
-
96
80
this . _dap . then ( dap => {
97
81
dap . on ( 'initialize' , async clientCapabilities => {
98
- this . _clientCapabilities = clientCapabilities ;
82
+ this . _rootServices . bind ( IInitializeParams ) . toConstantValue ( clientCapabilities ) ;
99
83
const capabilities = DebugAdapter . capabilities ( ) ;
100
84
if ( clientCapabilities . clientID === 'vscode' ) {
101
85
filterErrorsReportedToTelemetry ( ) ;
@@ -141,8 +125,29 @@ export class Binder implements IDisposable {
141
125
} ) ;
142
126
}
143
127
128
+ private getLaunchers ( ) {
129
+ if ( ! this . _launchers ) {
130
+ this . _launchers = new Set ( this . _rootServices . getAll ( ILauncher ) ) ;
131
+
132
+ for ( const launcher of this . _launchers ) {
133
+ launcher . onTargetListChanged (
134
+ ( ) => {
135
+ const targets = this . targetList ( ) ;
136
+ this . _attachToNewTargets ( targets , launcher ) ;
137
+ this . _detachOrphanThreads ( targets ) ;
138
+ this . _onTargetListChangedEmitter . fire ( ) ;
139
+ } ,
140
+ undefined ,
141
+ this . _disposables ,
142
+ ) ;
143
+ }
144
+ }
145
+
146
+ return this . _launchers ;
147
+ }
148
+
144
149
private async _disconnect ( ) {
145
- await Promise . all ( [ ...this . _launchers ] . map ( l => l . disconnect ( ) ) ) ;
150
+ await Promise . all ( [ ...this . getLaunchers ( ) ] . map ( l => l . disconnect ( ) ) ) ;
146
151
147
152
const didTerminate = ( ) => ! this . targetList . length && this . _terminationCount === 0 ;
148
153
if ( didTerminate ( ) ) {
@@ -174,7 +179,7 @@ export class Binder implements IDisposable {
174
179
if ( params . rootPath ) params . rootPath = urlUtils . platformPathToPreferredCase ( params . rootPath ) ;
175
180
this . _launchParams = params ;
176
181
let results = await Promise . all (
177
- [ ...this . _launchers ] . map ( l => this . _launch ( l , params , cts . token ) ) ,
182
+ [ ...this . getLaunchers ( ) ] . map ( l => this . _launch ( l , params , cts . token ) ) ,
178
183
) ;
179
184
results = results . filter ( result => ! ! result ) ;
180
185
if ( results . length ) return errors . createUserError ( results . join ( '\n' ) ) ;
@@ -217,7 +222,7 @@ export class Binder implements IDisposable {
217
222
}
218
223
219
224
async _restart ( ) {
220
- await Promise . all ( [ ...this . _launchers ] . map ( l => l . restart ( ) ) ) ;
225
+ await Promise . all ( [ ...this . getLaunchers ( ) ] . map ( l => l . restart ( ) ) ) ;
221
226
}
222
227
223
228
async _launch (
@@ -263,16 +268,12 @@ export class Binder implements IDisposable {
263
268
264
269
let result : ILaunchResult ;
265
270
try {
266
- result = await launcher . launch (
267
- params ,
268
- {
269
- telemetryReporter : this . telemetryReporter ,
270
- cancellationToken,
271
- targetOrigin : this . _targetOrigin ,
272
- dap : await this . _dap ,
273
- } ,
274
- this . _clientCapabilities ! ,
275
- ) ;
271
+ result = await launcher . launch ( params , {
272
+ telemetryReporter : this . telemetryReporter ,
273
+ cancellationToken,
274
+ targetOrigin : this . _targetOrigin ,
275
+ dap : await this . _dap ,
276
+ } ) ;
276
277
} catch ( e ) {
277
278
if ( e instanceof TaskCancelledError ) {
278
279
result = {
@@ -310,15 +311,16 @@ export class Binder implements IDisposable {
310
311
dispose ( ) {
311
312
for ( const disposable of this . _disposables ) disposable . dispose ( ) ;
312
313
this . _disposables = [ ] ;
313
- for ( const launcher of this . _launchers ) launcher . dispose ( ) ;
314
- this . _launchers . clear ( ) ;
315
314
disposeContainer ( this . _rootServices ) ;
316
315
this . _detachOrphanThreads ( [ ] ) ;
317
316
}
318
317
319
318
targetList ( ) : ITarget [ ] {
320
319
const result : ITarget [ ] = [ ] ;
321
- for ( const delegate of this . _launchers ) result . push ( ...delegate . targetList ( ) ) ;
320
+ for ( const delegate of this . getLaunchers ( ) ) {
321
+ result . push ( ...delegate . targetList ( ) ) ;
322
+ }
323
+
322
324
return result ;
323
325
}
324
326
0 commit comments