Skip to content

Commit 8b2a407

Browse files
committed
Support debug/createConfiguration proposed menu API
fixes eclipse-theia#14114 contributed on behalf of STMicroelectronics Signed-off-by: Remi Schnekenburger <[email protected]>
1 parent 1a7486e commit 8b2a407

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<!-- ## Unreleased
88
9+
- [debug] support 'debug/createConfiguration' menu extension [14215](https://github.com/eclipse-theia/theia/pull/14215) - Contributed on behalf of STMicroelectronics
910
- [plugin] move stubbed API TerminalShellIntegration into main API [#14168](https://github.com/eclipse-theia/theia/pull/14168) - Contributed on behalf of STMicroelectronics
1011
- [plugin] support evolution on proposed API extensionAny [#14199](https://github.com/eclipse-theia/theia/pull/14199) - Contributed on behalf of STMicroelectronics
1112
- [plugin] updated TreeView reveal options to be readonly [#14198](https://github.com/eclipse-theia/theia/pull/14198) - Contributed on behalf of STMicroelectronics

packages/debug/src/browser/debug-configuration-manager.ts

+74-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { Emitter, Event, WaitUntilEvent } from '@theia/core/lib/common/event';
2727
import { EditorManager, EditorWidget } from '@theia/editor/lib/browser';
2828
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
2929
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';
3131
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
3232
import { DebugConfigurationModel } from './debug-configuration-model';
3333
import { DebugSessionOptions, DynamicDebugConfigurationSessionOptions } from './debug-session-options';
@@ -40,12 +40,15 @@ import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-mo
4040
import * as monaco from '@theia/monaco-editor-core';
4141
import { ICommandService } from '@theia/monaco-editor-core/esm/vs/platform/commands/common/commands';
4242
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';
4444
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';
4647
export interface WillProvideDebugConfiguration extends WaitUntilEvent {
4748
}
4849

50+
export const DEBUG_CREATE_CONFIGURATION_MENU: MenuPath = ['debug-create-configuration'];
51+
4952
@injectable()
5053
export class DebugConfigurationManager {
5154

@@ -76,6 +79,15 @@ export class DebugConfigurationManager {
7679
@inject(WorkspaceVariableContribution)
7780
protected readonly workspaceVariables: WorkspaceVariableContribution;
7881

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+
7991
protected readonly onDidChangeEmitter = new Emitter<void>();
8092
readonly onDidChange: Event<void> = this.onDidChangeEmitter.event;
8193

@@ -453,13 +465,72 @@ export class DebugConfigurationManager {
453465
} catch {
454466
// Just keep going
455467
}
468+
469+
// no configuration yet. Proceed to create the file or use any action registered on the `debug/createConfiguration` menu.
456470
const debugType = await this.selectDebugType();
457471
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> {
458500
const content = this.getInitialConfigurationContent(configurations);
459501
textModel.object.textEditorModel.setValue(content); // Will clobber anything the user has entered!
460502
await textModel.object.save();
461503
}
462504

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+
463534
protected async provideDebugConfigurations(debugType: string, workspaceFolderUri: string | undefined): Promise<DebugConfiguration[]> {
464535
await this.fireWillProvideDebugConfiguration();
465536
return this.debug.provideDebugConfigurations(debugType, workspaceFolderUri);

packages/plugin-ext/src/main/browser/menus/vscode-theia-menu-mappings.ts

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { Navigatable } from '@theia/core/lib/browser/navigatable';
2020
import { injectable } from '@theia/core/shared/inversify';
2121
import { URI as CodeUri } from '@theia/core/shared/vscode-uri';
2222
import { DebugStackFramesWidget } from '@theia/debug/lib/browser/view/debug-stack-frames-widget';
23+
import { DEBUG_CREATE_CONFIGURATION_MENU } from '@theia/debug/lib/browser/debug-configuration-manager';
2324
import { DebugThreadsWidget } from '@theia/debug/lib/browser/view/debug-threads-widget';
2425
import { DebugToolBar } from '@theia/debug/lib/browser/view/debug-toolbar-widget';
2526
import { DebugVariablesWidget } from '@theia/debug/lib/browser/view/debug-variables-widget';
@@ -46,6 +47,7 @@ export const implementedVSCodeContributionPoints = [
4647
'comments/comment/title',
4748
'comments/commentThread/context',
4849
'debug/callstack/context',
50+
'debug/createConfiguration',
4951
'debug/variables/context',
5052
'debug/toolBar',
5153
'editor/context',
@@ -79,6 +81,7 @@ export const codeToTheiaMappings = new Map<ContributionPoint, MenuPath[]>([
7981
['comments/comment/title', [COMMENT_TITLE]],
8082
['comments/commentThread/context', [COMMENT_THREAD_CONTEXT]],
8183
['debug/callstack/context', [DebugStackFramesWidget.CONTEXT_MENU, DebugThreadsWidget.CONTEXT_MENU]],
84+
['debug/createConfiguration', [DEBUG_CREATE_CONFIGURATION_MENU]],
8285
['debug/variables/context', [DebugVariablesWidget.CONTEXT_MENU]],
8386
['debug/toolBar', [DebugToolBar.MENU]],
8487
['editor/context', [EDITOR_CONTEXT_MENU]],

0 commit comments

Comments
 (0)