@@ -27,7 +27,7 @@ import { Emitter, Event, WaitUntilEvent } from '@theia/core/lib/common/event';
27
27
import { EditorManager , EditorWidget } from '@theia/editor/lib/browser' ;
28
28
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor' ;
29
29
import { LabelProvider , PreferenceScope , PreferenceService , QuickPickValue , StorageService } from '@theia/core/lib/browser' ;
30
- import { QuickPickService } from '@theia/core/lib/common/quick-pick-service' ;
30
+ import { QuickPickItem , QuickPickItemOrSeparator , QuickPickService } from '@theia/core/lib/common/quick-pick-service' ;
31
31
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service' ;
32
32
import { DebugConfigurationModel } from './debug-configuration-model' ;
33
33
import { DebugSessionOptions , DynamicDebugConfigurationSessionOptions } from './debug-session-options' ;
@@ -40,12 +40,15 @@ import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-mo
40
40
import * as monaco from '@theia/monaco-editor-core' ;
41
41
import { ICommandService } from '@theia/monaco-editor-core/esm/vs/platform/commands/common/commands' ;
42
42
import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices' ;
43
- import { nls } from '@theia/core' ;
43
+ import { ActionMenuNode , CommandService , MenuCommandExecutor , MenuModelRegistry , MenuPath , nls } from '@theia/core' ;
44
44
import { DebugCompound } from '../common/debug-compound' ;
45
-
45
+ import { IReference } from '@theia/monaco-editor-core/esm/vs/base/common/lifecycle' ;
46
+ import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model' ;
46
47
export interface WillProvideDebugConfiguration extends WaitUntilEvent {
47
48
}
48
49
50
+ export const DEBUG_CREATE_CONFIGURATION_MENU : MenuPath = [ 'debug-create-configuration' ] ;
51
+
49
52
@injectable ( )
50
53
export class DebugConfigurationManager {
51
54
@@ -76,6 +79,15 @@ export class DebugConfigurationManager {
76
79
@inject ( WorkspaceVariableContribution )
77
80
protected readonly workspaceVariables : WorkspaceVariableContribution ;
78
81
82
+ @inject ( MenuModelRegistry )
83
+ protected readonly menuRegistry : MenuModelRegistry ;
84
+
85
+ @inject ( MenuCommandExecutor )
86
+ protected readonly menuCommandExecutor : MenuCommandExecutor ;
87
+
88
+ @inject ( CommandService )
89
+ protected readonly commandService : CommandService ;
90
+
79
91
protected readonly onDidChangeEmitter = new Emitter < void > ( ) ;
80
92
readonly onDidChange : Event < void > = this . onDidChangeEmitter . event ;
81
93
@@ -453,13 +465,72 @@ export class DebugConfigurationManager {
453
465
} catch {
454
466
// Just keep going
455
467
}
468
+
469
+ // no configuration yet. Proceed to create the file or use any action registered on the `debug/createConfiguration` menu.
456
470
const debugType = await this . selectDebugType ( ) ;
457
471
const configurations = debugType ? await this . provideDebugConfigurations ( debugType , model . workspaceFolderUri ) : [ ] ;
472
+ const commandQuickPicks = this . buildItemsFromMenu ( ) ;
473
+
474
+ if ( commandQuickPicks . length > 0 ) {
475
+ const quickPickItems : QuickPickItemOrSeparator [ ] = [ ] ;
476
+ const GENERATE_FILE_ID = 'debug-generate-file' ;
477
+ const item : QuickPickItem = {
478
+ // basic action to provide a launch.json skeleton and user can edit it.
479
+ label : nls . localize ( 'theia/debug/generateLaunchFile' , 'generate launch.json' ) ,
480
+ id : GENERATE_FILE_ID
481
+ } ;
482
+ quickPickItems . push ( item ) ;
483
+ quickPickItems . push ( { type : 'separator' } ) ;
484
+ quickPickItems . push ( ...commandQuickPicks ) ;
485
+
486
+ const selected = await this . quickPickService . show ( quickPickItems , { canSelectMany : false } ) ;
487
+ if ( selected && selected . id ) {
488
+ if ( selected . id === GENERATE_FILE_ID ) {
489
+ await this . updateTextModel ( textModel , configurations ) ;
490
+ } else {
491
+ await this . commandService . executeCommand ( selected . id ) ;
492
+ }
493
+ }
494
+ } else {
495
+ await this . updateTextModel ( textModel , configurations ) ;
496
+ }
497
+ }
498
+
499
+ protected async updateTextModel ( textModel : IReference < MonacoEditorModel > , configurations : DebugConfiguration [ ] ) : Promise < void > {
458
500
const content = this . getInitialConfigurationContent ( configurations ) ;
459
501
textModel . object . textEditorModel . setValue ( content ) ; // Will clobber anything the user has entered!
460
502
await textModel . object . save ( ) ;
461
503
}
462
504
505
+ protected buildItemsFromMenu ( ) : QuickPickItemOrSeparator [ ] {
506
+ const menu = this . menuRegistry . getMenu ( DEBUG_CREATE_CONFIGURATION_MENU ) ;
507
+ const quickPickItems = [ ] ;
508
+ for ( const child of menu . children ) {
509
+ if ( child . children ) {
510
+ for ( const grandchild of child . children ) {
511
+ if ( grandchild instanceof ActionMenuNode ) {
512
+ const { command, label, when } = grandchild ;
513
+ if ( this . menuCommandExecutor . isVisible ( DEBUG_CREATE_CONFIGURATION_MENU , command ) && ( ! when || this . contextKeyService . match ( when ) ) ) {
514
+ quickPickItems . push ( {
515
+ label : label ,
516
+ id : command
517
+ } ) ;
518
+ }
519
+ }
520
+ }
521
+ } else if ( child instanceof ActionMenuNode ) {
522
+ const { command, label, when } = child ;
523
+ if ( this . menuCommandExecutor . isVisible ( DEBUG_CREATE_CONFIGURATION_MENU , command ) && ( ! when || this . contextKeyService . match ( when ) ) ) {
524
+ quickPickItems . push ( {
525
+ label : label ,
526
+ id : command
527
+ } ) ;
528
+ }
529
+ }
530
+ }
531
+ return quickPickItems ;
532
+ }
533
+
463
534
protected async provideDebugConfigurations ( debugType : string , workspaceFolderUri : string | undefined ) : Promise < DebugConfiguration [ ] > {
464
535
await this . fireWillProvideDebugConfiguration ( ) ;
465
536
return this . debug . provideDebugConfigurations ( debugType , workspaceFolderUri ) ;
0 commit comments