44 *--------------------------------------------------------------------------------------------*/
55
66import * as nls from 'vs/nls' ;
7- import { dispose , IDisposable } from 'vs/base/common/lifecycle' ;
7+ import { dispose , IDisposable , DisposableStore } from 'vs/base/common/lifecycle' ;
88import { Event , Emitter } from 'vs/base/common/event' ;
99import * as strings from 'vs/base/common/strings' ;
1010import * as objects from 'vs/base/common/objects' ;
@@ -37,7 +37,7 @@ import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cance
3737import { withUndefinedAsNull } from 'vs/base/common/types' ;
3838import { sequence } from 'vs/base/common/async' ;
3939import { IHistoryService } from 'vs/workbench/services/history/common/history' ;
40- import { first } from 'vs/base/common/arrays' ;
40+ import { first , flatten } from 'vs/base/common/arrays' ;
4141import { getVisibleAndSorted } from 'vs/workbench/contrib/debug/common/debugUtils' ;
4242import { DebugConfigurationProviderTriggerKind } from 'vs/workbench/api/common/extHostTypes' ;
4343
@@ -258,14 +258,23 @@ export class ConfigurationManager implements IConfigurationManager {
258258 return acc ;
259259 }
260260
261- const explicitTypes = e . activationEvents . filter ( e => e . includes ( `${ onDebugDynamicConfigurationsName } :` ) ) . map ( type => type . slice ( onDebugDynamicConfigurationsName . length + 1 ) ) ;
261+ const explicitTypes : string [ ] = [ ] ;
262+ let hasGenericEvent = false ;
263+ for ( const event of e . activationEvents ) {
264+ if ( event === onDebugDynamicConfigurationsName ) {
265+ hasGenericEvent = true ;
266+ } else if ( event . startsWith ( `${ onDebugDynamicConfigurationsName } :` ) ) {
267+ explicitTypes . push ( event . slice ( onDebugDynamicConfigurationsName . length + 1 ) ) ;
268+ }
269+ }
270+
262271 if ( explicitTypes . length ) {
263- return [ ... acc , ... explicitTypes ] ;
272+ return acc . concat ( explicitTypes ) ;
264273 }
265274
266- if ( e . activationEvents . includes ( onDebugDynamicConfigurationsName ) ) {
275+ if ( hasGenericEvent ) {
267276 const debuggerType = e . contributes ?. debuggers ?. [ 0 ] . type ;
268- return debuggerType ? [ ... acc , debuggerType ] : acc ;
277+ return debuggerType ? acc . concat ( debuggerType ) : acc ;
269278 }
270279
271280 return acc ;
@@ -275,23 +284,24 @@ export class ConfigurationManager implements IConfigurationManager {
275284 return {
276285 label : this . getDebuggerLabel ( type ) ! ,
277286 pick : async ( ) => {
278- const input = this . quickInputService . createQuickPick < IDynamicPickItem > ( ) ;
287+ const disposables = new DisposableStore ( ) ;
288+ const input = disposables . add ( this . quickInputService . createQuickPick < IDynamicPickItem > ( ) ) ;
279289 input . busy = true ;
280290 input . placeholder = nls . localize ( 'selectConfiguration' , "Select Launch Configuration" ) ;
281291 input . show ( ) ;
282292
283293 let chosenDidCancel = false ;
284294 const chosenPromise = new Promise < IDynamicPickItem | undefined > ( resolve => {
285- input . onDidAccept ( ( ) => resolve ( input . activeItems [ 0 ] ) ) ;
286- input . onDidTriggerItemButton ( async ( context ) => {
295+ disposables . add ( input . onDidAccept ( ( ) => resolve ( input . activeItems [ 0 ] ) ) ) ;
296+ disposables . add ( input . onDidTriggerItemButton ( async ( context ) => {
287297 resolve ( undefined ) ;
288298 const { launch, config } = context . item ;
289299 await launch . openConfigFile ( false , config . type ) ;
290300 // Only Launch have a pin trigger button
291301 await ( launch as Launch ) . writeConfiguration ( config ) ;
292302 this . selectConfiguration ( launch , config . name ) ;
293- } ) ;
294- input . onDidHide ( ( ) => { chosenDidCancel = true ; resolve ( ) ; } ) ;
303+ } ) ) ;
304+ disposables . add ( input . onDidHide ( ( ) => { chosenDidCancel = true ; resolve ( ) ; } ) ) ;
295305 } ) ;
296306
297307 await this . activateDebuggers ( onDebugDynamicConfigurationsName , type ) ;
@@ -312,8 +322,12 @@ export class ConfigurationManager implements IConfigurationManager {
312322 }
313323 } ) ;
314324
315- const items = await Promise . all ( picks ) . then ( result => result . reduce ( ( first , second ) => first . concat ( second ) , [ ] ) ) ;
325+ const nestedPicks = await Promise . all ( picks ) ;
326+ const items = flatten ( nestedPicks ) ;
327+
316328 let chosen : IDynamicPickItem | undefined ;
329+
330+ // If there's exactly one item to choose from, pick it automatically
317331 if ( items . length === 1 && ! chosenDidCancel ) {
318332 chosen = items [ 0 ] ;
319333 } else {
@@ -322,7 +336,8 @@ export class ConfigurationManager implements IConfigurationManager {
322336 chosen = await chosenPromise ;
323337 }
324338
325- input . dispose ( ) ;
339+ disposables . dispose ( ) ;
340+
326341 if ( ! chosen ) {
327342 // User canceled quick input we should notify the provider to cancel computing configurations
328343 token . cancel ( ) ;
0 commit comments