-
-
Notifications
You must be signed in to change notification settings - Fork 436
/
Copy pathdebug-configuration-widget.tsx
76 lines (71 loc) · 2.74 KB
/
debug-configuration-widget.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { SelectOption } from '@theia/core/lib/browser/widgets/select-component';
import { DisposableCollection } from '@theia/core/lib/common/disposable';
import { nls } from '@theia/core/lib/common/nls';
import { injectable } from '@theia/core/shared/inversify';
import React from '@theia/core/shared/react';
import { DebugAction } from '@theia/debug/lib/browser/view/debug-action';
import { DebugConfigurationSelect as TheiaDebugConfigurationSelect } from '@theia/debug/lib/browser/view/debug-configuration-select';
import { DebugConfigurationWidget as TheiaDebugConfigurationWidget } from '@theia/debug/lib/browser/view/debug-configuration-widget';
/**
* Patched to programmatically update the debug config <select> in the widget.
*/
@injectable()
export class DebugConfigurationWidget extends TheiaDebugConfigurationWidget {
override render(): React.ReactNode {
return (
<React.Fragment>
<DebugAction
run={this.start}
label={nls.localizeByDefault('Start Debugging')}
iconClass="debug-start"
ref={this.setStepRef}
/>
{/* The customized select component that will refresh when the config manager did change */}
<DebugConfigurationSelect
manager={this.manager}
quickInputService={this.quickInputService}
isMultiRoot={this.workspaceService.isMultiRootWorkspaceOpened}
/>
<DebugAction
run={this.openConfiguration}
label={nls.localizeByDefault('Open {0}', '"launch.json"')}
iconClass="settings-gear"
/>
<DebugAction
run={this.openConsole}
label={nls.localizeByDefault('Debug Console')}
iconClass="terminal"
/>
</React.Fragment>
);
}
}
class DebugConfigurationSelect extends TheiaDebugConfigurationSelect {
private readonly toDisposeOnUnmount = new DisposableCollection();
override componentDidMount(): void {
super.componentDidMount();
this.toDisposeOnUnmount.push(
this['manager'].onDidChange(() => this.refreshDebugConfigurations())
);
}
protected override renderOptions(): SelectOption[] {
const options = super.renderOptions();
const addConfiguration = options[options.length - 1];
const separator = options[options.length - 2];
// Remove "Add configuration..." and the preceding separator options.
// They're expected to be the last two items.
if (
addConfiguration.value ===
TheiaDebugConfigurationSelect.ADD_CONFIGURATION &&
separator.separator
) {
options.splice(options.length - 2, 2);
return options;
}
// Something is unexpected with the select options.
return options;
}
override componentWillUnmount(): void {
this.toDisposeOnUnmount.dispose();
}
}