@opensumi/ide-debug 2.21.3 → 2.21.4-rc-1668395886.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/lib/browser/debug-contribution.d.ts +2 -147
  2. package/lib/browser/debug-contribution.d.ts.map +1 -1
  3. package/lib/browser/debug-contribution.js +48 -197
  4. package/lib/browser/debug-contribution.js.map +1 -1
  5. package/lib/browser/debug-session-manager.d.ts +2 -3
  6. package/lib/browser/debug-session-manager.d.ts.map +1 -1
  7. package/lib/browser/debug-session-manager.js +2 -3
  8. package/lib/browser/debug-session-manager.js.map +1 -1
  9. package/lib/browser/debug-session.d.ts +3 -4
  10. package/lib/browser/debug-session.d.ts.map +1 -1
  11. package/lib/browser/debug-session.js.map +1 -1
  12. package/lib/browser/editor/debug-editor-contribution.d.ts +2 -2
  13. package/lib/browser/editor/debug-editor-contribution.d.ts.map +1 -1
  14. package/lib/browser/editor/debug-editor-contribution.js +2 -3
  15. package/lib/browser/editor/debug-editor-contribution.js.map +1 -1
  16. package/lib/browser/editor/debug-model-manager.d.ts +2 -9
  17. package/lib/browser/editor/debug-model-manager.d.ts.map +1 -1
  18. package/lib/browser/editor/debug-model-manager.js +8 -15
  19. package/lib/browser/editor/debug-model-manager.js.map +1 -1
  20. package/lib/browser/index.d.ts +0 -14
  21. package/lib/browser/index.d.ts.map +1 -1
  22. package/lib/browser/index.js +6 -15
  23. package/lib/browser/index.js.map +1 -1
  24. package/lib/browser/model/debug-source.d.ts +3 -3
  25. package/lib/browser/model/debug-source.d.ts.map +1 -1
  26. package/lib/browser/model/debug-source.js.map +1 -1
  27. package/lib/browser/model/debug-watch.d.ts.map +1 -1
  28. package/lib/browser/model/debug-watch.js +1 -2
  29. package/lib/browser/model/debug-watch.js.map +1 -1
  30. package/lib/browser/view/console/debug-console-session.d.ts +2 -1
  31. package/lib/browser/view/console/debug-console-session.d.ts.map +1 -1
  32. package/lib/browser/view/console/debug-console-session.js.map +1 -1
  33. package/lib/browser/view/console/debug-console.contribution.d.ts.map +1 -1
  34. package/lib/browser/view/console/debug-console.contribution.js +21 -23
  35. package/lib/browser/view/console/debug-console.contribution.js.map +1 -1
  36. package/lib/browser/view/console/debug-console.module.less +1 -1
  37. package/lib/browser/view/console/debug-console.view.js +2 -2
  38. package/lib/browser/view/console/debug-console.view.js.map +1 -1
  39. package/lib/browser/view/frames/debug-call-stack.contribution.js +5 -5
  40. package/lib/browser/view/frames/debug-call-stack.contribution.js.map +1 -1
  41. package/lib/browser/view/variables/debug-variables.contribution.d.ts.map +1 -1
  42. package/lib/browser/view/variables/debug-variables.contribution.js +12 -13
  43. package/lib/browser/view/variables/debug-variables.contribution.js.map +1 -1
  44. package/lib/browser/view/variables/debug-variables.module.less +1 -1
  45. package/lib/browser/view/variables/debug-variables.view.js +1 -1
  46. package/lib/browser/view/variables/debug-variables.view.js.map +1 -1
  47. package/lib/browser/view/watch/debug-watch.contribution.d.ts.map +1 -1
  48. package/lib/browser/view/watch/debug-watch.contribution.js +21 -19
  49. package/lib/browser/view/watch/debug-watch.contribution.js.map +1 -1
  50. package/lib/browser/view/watch/debug-watch.module.less +1 -1
  51. package/lib/browser/view/watch/debug-watch.view.js +1 -1
  52. package/lib/browser/view/watch/debug-watch.view.js.map +1 -1
  53. package/lib/common/commands.d.ts +46 -0
  54. package/lib/common/commands.d.ts.map +1 -0
  55. package/lib/common/commands.js +149 -0
  56. package/lib/common/commands.js.map +1 -0
  57. package/lib/common/debug-console.d.ts +18 -0
  58. package/lib/common/debug-console.d.ts.map +1 -0
  59. package/lib/common/debug-console.js +5 -0
  60. package/lib/common/debug-console.js.map +1 -0
  61. package/lib/common/debug-model.d.ts +17 -2
  62. package/lib/common/debug-model.d.ts.map +1 -1
  63. package/lib/common/debug-model.js +9 -1
  64. package/lib/common/debug-model.js.map +1 -1
  65. package/lib/common/index.d.ts +2 -0
  66. package/lib/common/index.d.ts.map +1 -1
  67. package/lib/common/index.js +2 -0
  68. package/lib/common/index.js.map +1 -1
  69. package/package.json +25 -24
  70. package/src/browser/assets/breakpoint-conditional-disabled.svg +4 -0
  71. package/src/browser/assets/breakpoint-conditional-unverified.svg +4 -0
  72. package/src/browser/assets/breakpoint-conditional.svg +4 -0
  73. package/src/browser/assets/breakpoint-disabled.svg +4 -0
  74. package/src/browser/assets/breakpoint-hint.svg +4 -0
  75. package/src/browser/assets/breakpoint-log-disabled.svg +4 -0
  76. package/src/browser/assets/breakpoint-log-unverified.svg +4 -0
  77. package/src/browser/assets/breakpoint-log.svg +4 -0
  78. package/src/browser/assets/breakpoint-unsupported.svg +4 -0
  79. package/src/browser/assets/breakpoint-unverified.svg +4 -0
  80. package/src/browser/assets/breakpoint.svg +4 -0
  81. package/src/browser/assets/breakpoints-activate-inverse.svg +4 -0
  82. package/src/browser/assets/breakpoints-activate.svg +4 -0
  83. package/src/browser/assets/configure-inverse.svg +4 -0
  84. package/src/browser/assets/configure.svg +4 -0
  85. package/src/browser/assets/continue-inverse.svg +4 -0
  86. package/src/browser/assets/current-and-breakpoint.svg +4 -0
  87. package/src/browser/assets/current-arrow.svg +4 -0
  88. package/src/browser/assets/remove-all-inverse.svg +4 -0
  89. package/src/browser/assets/remove-all.svg +4 -0
  90. package/src/browser/assets/repl-inverse.svg +4 -0
  91. package/src/browser/assets/repl.svg +4 -0
  92. package/src/browser/assets/restart-inverse.svg +4 -0
  93. package/src/browser/assets/stackframe-and-breakpoint.svg +4 -0
  94. package/src/browser/assets/stackframe-arrow.svg +4 -0
  95. package/src/browser/assets/start-inverse.svg +4 -0
  96. package/src/browser/breakpoint/breakpoint-decoration.ts +57 -0
  97. package/src/browser/breakpoint/breakpoint-manager.ts +348 -0
  98. package/src/browser/breakpoint/breakpoint-marker.ts +70 -0
  99. package/src/browser/breakpoint/index.ts +3 -0
  100. package/src/browser/components/debug-action/index.module.less +73 -0
  101. package/src/browser/components/debug-action/index.tsx +40 -0
  102. package/src/browser/components/debug-exception-widget.less +42 -0
  103. package/src/browser/components/floating-click-widget/index.module.less +5 -0
  104. package/src/browser/components/floating-click-widget/index.tsx +21 -0
  105. package/src/browser/components/index.ts +1 -0
  106. package/src/browser/contextkeys/debug-call-stack-item-type-key.ts +4 -0
  107. package/src/browser/contextkeys/debug-contextkey.service.ts +54 -0
  108. package/src/browser/contextkeys/index.ts +1 -0
  109. package/src/browser/debug-ansi-handle.ts +521 -0
  110. package/src/browser/debug-configuration-manager.ts +513 -0
  111. package/src/browser/debug-configuration-model.ts +66 -0
  112. package/src/browser/debug-contribution.ts +751 -0
  113. package/src/browser/debug-exception-widget.tsx +89 -0
  114. package/src/browser/debug-link-detector.ts +234 -0
  115. package/src/browser/debug-memory.ts +220 -0
  116. package/src/browser/debug-preferences.ts +70 -0
  117. package/src/browser/debug-progress.service.ts +122 -0
  118. package/src/browser/debug-schema-updater.ts +67 -0
  119. package/src/browser/debug-service.ts +42 -0
  120. package/src/browser/debug-session-connection.ts +333 -0
  121. package/src/browser/debug-session-contribution.ts +57 -0
  122. package/src/browser/debug-session-manager.ts +622 -0
  123. package/src/browser/debug-session.ts +1178 -0
  124. package/src/browser/debug-style.less +124 -0
  125. package/src/browser/debugUtils.ts +110 -0
  126. package/src/browser/editor/debug-breakpoint-widget.ts +99 -0
  127. package/src/browser/editor/debug-breakpoint-zone-widget.tsx +262 -0
  128. package/src/browser/editor/debug-breakpoint.module.less +29 -0
  129. package/src/browser/editor/debug-editor-contribution.ts +589 -0
  130. package/src/browser/editor/debug-expression-provider.ts +101 -0
  131. package/src/browser/editor/debug-hover-model.ts +38 -0
  132. package/src/browser/editor/debug-hover-source.ts +107 -0
  133. package/src/browser/editor/debug-hover-tree.model.service.ts +332 -0
  134. package/src/browser/editor/debug-hover-widget.tsx +200 -0
  135. package/src/browser/editor/debug-hover.module.less +29 -0
  136. package/src/browser/editor/debug-hover.view.tsx +147 -0
  137. package/src/browser/editor/debug-model-manager.ts +219 -0
  138. package/src/browser/editor/debug-model.ts +853 -0
  139. package/src/browser/editor/debug-run-to-cursor.service.ts +180 -0
  140. package/src/browser/editor/debug-styles.ts +66 -0
  141. package/src/browser/editor/evaluatable-expression.ts +47 -0
  142. package/src/browser/editor/index.ts +6 -0
  143. package/src/browser/index.ts +127 -0
  144. package/src/browser/markers/index.ts +2 -0
  145. package/src/browser/markers/marker-manager.ts +201 -0
  146. package/src/browser/markers/marker.ts +20 -0
  147. package/src/browser/model/debug-source.ts +144 -0
  148. package/src/browser/model/debug-stack-frame.ts +111 -0
  149. package/src/browser/model/debug-thread.ts +186 -0
  150. package/src/browser/model/debug-watch.ts +129 -0
  151. package/src/browser/model/index.ts +4 -0
  152. package/src/browser/preferences/launch-folder-preference-provider.ts +23 -0
  153. package/src/browser/preferences/launch-preferences-contribution.ts +9 -0
  154. package/src/browser/preferences/launch-preferences.ts +16 -0
  155. package/src/browser/tree/debug-console-tree-node.define.tsx +76 -0
  156. package/src/browser/tree/debug-tree-node.define.ts +768 -0
  157. package/src/browser/tree/index.ts +2 -0
  158. package/src/browser/view/breakpoints/debug-breakpoints.module.less +72 -0
  159. package/src/browser/view/breakpoints/debug-breakpoints.service.ts +216 -0
  160. package/src/browser/view/breakpoints/debug-breakpoints.view.tsx +174 -0
  161. package/src/browser/view/configuration/debug-configuration.module.less +110 -0
  162. package/src/browser/view/configuration/debug-configuration.service.ts +170 -0
  163. package/src/browser/view/configuration/debug-configuration.view.tsx +253 -0
  164. package/src/browser/view/configuration/debug-toolbar.service.ts +167 -0
  165. package/src/browser/view/configuration/debug-toolbar.view.tsx +335 -0
  166. package/src/browser/view/console/debug-console-filter.model.ts +49 -0
  167. package/src/browser/view/console/debug-console-filter.service.ts +81 -0
  168. package/src/browser/view/console/debug-console-filter.view.tsx +78 -0
  169. package/src/browser/view/console/debug-console-model.ts +48 -0
  170. package/src/browser/view/console/debug-console-session.ts +165 -0
  171. package/src/browser/view/console/debug-console-toolbar.view.tsx +28 -0
  172. package/src/browser/view/console/debug-console-tree.model.service.ts +550 -0
  173. package/src/browser/view/console/debug-console.contribution.ts +179 -0
  174. package/src/browser/view/console/debug-console.module.less +369 -0
  175. package/src/browser/view/console/debug-console.service.ts +433 -0
  176. package/src/browser/view/console/debug-console.view.tsx +500 -0
  177. package/src/browser/view/debug-view-model.ts +182 -0
  178. package/src/browser/view/frames/debug-call-stack-frame.view.tsx +224 -0
  179. package/src/browser/view/frames/debug-call-stack-session.view.tsx +237 -0
  180. package/src/browser/view/frames/debug-call-stack-thread.view.tsx +93 -0
  181. package/src/browser/view/frames/debug-call-stack.contribution.ts +88 -0
  182. package/src/browser/view/frames/debug-call-stack.module.less +193 -0
  183. package/src/browser/view/frames/debug-call-stack.operation.tsx +97 -0
  184. package/src/browser/view/frames/debug-call-stack.service.ts +105 -0
  185. package/src/browser/view/frames/debug-call-stack.view.tsx +43 -0
  186. package/src/browser/view/variables/debug-variables-model.ts +38 -0
  187. package/src/browser/view/variables/debug-variables-tree.model.service.ts +467 -0
  188. package/src/browser/view/variables/debug-variables.contribution.ts +243 -0
  189. package/src/browser/view/variables/debug-variables.module.less +148 -0
  190. package/src/browser/view/variables/debug-variables.view.tsx +303 -0
  191. package/src/browser/view/watch/debug-watch-model.ts +38 -0
  192. package/src/browser/view/watch/debug-watch-tree.model.service.ts +567 -0
  193. package/src/browser/view/watch/debug-watch.contribution.ts +170 -0
  194. package/src/browser/view/watch/debug-watch.module.less +188 -0
  195. package/src/browser/view/watch/debug-watch.view.tsx +337 -0
  196. package/src/common/commands.ts +146 -0
  197. package/src/common/constants.ts +81 -0
  198. package/src/common/debug-breakpoint.ts +43 -0
  199. package/src/common/debug-configuration.ts +68 -0
  200. package/src/common/debug-console.ts +20 -0
  201. package/src/common/debug-editor.ts +4 -0
  202. package/src/common/debug-hover.ts +31 -0
  203. package/src/common/debug-model.ts +272 -0
  204. package/src/common/debug-progress.ts +8 -0
  205. package/src/common/debug-schema-updater.ts +1 -0
  206. package/src/common/debug-service.ts +176 -0
  207. package/src/common/debug-session-options.ts +19 -0
  208. package/src/common/debug-session.ts +200 -0
  209. package/src/common/evaluatable-expression.ts +43 -0
  210. package/src/common/index.ts +16 -0
  211. package/src/common/inline-values.ts +77 -0
  212. package/src/common/terminal.ts +163 -0
  213. package/src/common/types.ts +86 -0
  214. package/src/index.ts +1 -0
@@ -0,0 +1,170 @@
1
+ import { observable, action } from 'mobx';
2
+
3
+ import { Injectable, Autowired } from '@opensumi/di';
4
+ import { URI, PreferenceService, isUndefined } from '@opensumi/ide-core-browser';
5
+ import { IWorkspaceService } from '@opensumi/ide-workspace';
6
+
7
+ import {
8
+ DebugSessionOptions,
9
+ DEFAULT_ADD_CONFIGURATION_KEY,
10
+ DEFAULT_CONFIGURATION_NAME_SEPARATOR,
11
+ DEFAULT_CONFIGURATION_INDEX_SEPARATOR,
12
+ } from '../../../common';
13
+ import { IDebugSessionManager } from '../../../common/debug-session';
14
+ import { DebugConfigurationManager } from '../../debug-configuration-manager';
15
+ import { DebugSessionManager } from '../../debug-session-manager';
16
+ import { DebugConsoleService } from '../console/debug-console.service';
17
+ import { DebugViewModel } from '../debug-view-model';
18
+
19
+ @Injectable()
20
+ export class DebugConfigurationService {
21
+ @Autowired(IWorkspaceService)
22
+ protected workspaceService: IWorkspaceService;
23
+
24
+ @Autowired(DebugConfigurationManager)
25
+ protected debugConfigurationManager: DebugConfigurationManager;
26
+
27
+ @Autowired(IDebugSessionManager)
28
+ protected debugSessionManager: DebugSessionManager;
29
+
30
+ @Autowired(DebugViewModel)
31
+ protected debugViewModel: DebugViewModel;
32
+
33
+ @Autowired(DebugConsoleService)
34
+ protected debugConsoleService: DebugConsoleService;
35
+
36
+ @Autowired(PreferenceService)
37
+ private readonly preferenceService: PreferenceService;
38
+
39
+ private _whenReady: Promise<void>;
40
+
41
+ constructor() {
42
+ this._whenReady = this.init();
43
+ }
44
+
45
+ @observable
46
+ currentValue: string = DEFAULT_ADD_CONFIGURATION_KEY;
47
+
48
+ @observable
49
+ float = true;
50
+
51
+ @observable
52
+ isMultiRootWorkspace: boolean;
53
+
54
+ @observable
55
+ workspaceRoots: string[] = [];
56
+
57
+ @observable.shallow
58
+ configurationOptions: DebugSessionOptions[];
59
+
60
+ get whenReady() {
61
+ return this._whenReady;
62
+ }
63
+
64
+ async init() {
65
+ await this.debugConfigurationManager.whenReady;
66
+ await this.updateConfigurationOptions();
67
+ // await this.initCurrentConfiguration();
68
+ this.debugConfigurationManager.onDidChange(async () => {
69
+ this.updateConfigurationOptions();
70
+ // await this.initCurrentConfiguration();
71
+ });
72
+ this.preferenceService.onPreferenceChanged((event) => {
73
+ const { preferenceName, newValue } = event;
74
+ if (preferenceName === 'debug.toolbar.float') {
75
+ if (this.float !== newValue) {
76
+ this.updateFloat(newValue);
77
+ }
78
+ }
79
+ });
80
+ await this.updateWorkspaceState();
81
+ // onWorkspaceLocationChanged 事件不能满足实时更新workspaceRoots的需求
82
+ // onWorkspaceChanged 能获取到在工作区状态添加文件夹的节点变化
83
+ this.workspaceService.onWorkspaceChanged(async () => {
84
+ await this.updateWorkspaceState();
85
+ });
86
+ this.updateFloat(!!this.preferenceService.get<boolean>('debug.toolbar.float'));
87
+ }
88
+
89
+ @action
90
+ async updateWorkspaceState() {
91
+ this.isMultiRootWorkspace = this.workspaceService.isMultiRootWorkspaceOpened;
92
+ this.workspaceRoots = (await this.workspaceService.tryGetRoots()).map((root) => root.uri);
93
+ }
94
+
95
+ @action
96
+ updateFloat(value: boolean) {
97
+ this.float = value;
98
+ }
99
+
100
+ @action
101
+ updateCurrentValue(value: string) {
102
+ this.currentValue = value;
103
+ }
104
+
105
+ @action
106
+ updateConfigurationOptions() {
107
+ this.configurationOptions = this.debugConfigurationManager.all;
108
+ const { current } = this.debugConfigurationManager;
109
+ if (current) {
110
+ const currentValue = this.toValue(current);
111
+ this.updateCurrentValue(currentValue);
112
+ } else {
113
+ this.updateCurrentValue(DEFAULT_ADD_CONFIGURATION_KEY);
114
+ }
115
+ }
116
+
117
+ start = async () => {
118
+ const configuration = this.debugConfigurationManager.current;
119
+ if (configuration) {
120
+ this.debugSessionManager.start(configuration);
121
+ } else {
122
+ this.debugConfigurationManager.addConfiguration();
123
+ }
124
+ };
125
+
126
+ openConfiguration = () => {
127
+ const { current } = this.debugConfigurationManager;
128
+ const uri = current?.workspaceFolderUri;
129
+ this.debugConfigurationManager.openConfiguration(uri);
130
+ };
131
+
132
+ openDebugConsole = () => {
133
+ this.debugConsoleService.activate();
134
+ };
135
+
136
+ addConfiguration = (eventOrUri?: React.MouseEvent<HTMLElement, MouseEvent> | string) => {
137
+ this.debugConfigurationManager.addConfiguration(typeof eventOrUri === 'string' ? eventOrUri : undefined);
138
+ };
139
+
140
+ updateConfiguration = (name: string, workspaceFolderUri: string, index: number) => {
141
+ this.debugConfigurationManager.current = this.debugConfigurationManager.find(name, workspaceFolderUri, index);
142
+ };
143
+
144
+ toValue({ configuration, workspaceFolderUri, index }: DebugSessionOptions) {
145
+ if (!workspaceFolderUri) {
146
+ return configuration.name;
147
+ }
148
+ if (isUndefined(index)) {
149
+ const options = this.debugConfigurationManager.find(configuration.name, workspaceFolderUri);
150
+ if (options && options.index) {
151
+ return this.toValue(options);
152
+ }
153
+ return this.currentValue;
154
+ }
155
+ return (
156
+ configuration.name +
157
+ DEFAULT_CONFIGURATION_NAME_SEPARATOR +
158
+ workspaceFolderUri +
159
+ DEFAULT_CONFIGURATION_INDEX_SEPARATOR +
160
+ index
161
+ );
162
+ }
163
+
164
+ toName = ({ configuration, workspaceFolderUri }: DebugSessionOptions) => {
165
+ if (!workspaceFolderUri || !this.workspaceService.isMultiRootWorkspaceEnabled) {
166
+ return configuration.name;
167
+ }
168
+ return configuration.name + ' (' + new URI(workspaceFolderUri).path.base + ')';
169
+ };
170
+ }
@@ -0,0 +1,253 @@
1
+ import cls from 'classnames';
2
+ import { observer } from 'mobx-react-lite';
3
+ import React from 'react';
4
+
5
+
6
+ import { Select, Option } from '@opensumi/ide-components';
7
+ import { useInjectable, localize, isElectronRenderer, URI } from '@opensumi/ide-core-browser';
8
+ import { Select as NativeSelect } from '@opensumi/ide-core-browser/lib/components/select';
9
+
10
+ import {
11
+ DEFAULT_ADD_CONFIGURATION_KEY,
12
+ DEFAULT_NO_CONFIGURATION_KEY,
13
+ DEFAULT_CONFIGURATION_INDEX_SEPARATOR,
14
+ DEFAULT_CONFIGURATION_NAME_SEPARATOR,
15
+ DebugSessionOptions,
16
+ } from '../../../common';
17
+ import { DebugAction } from '../../components';
18
+
19
+ import styles from './debug-configuration.module.less';
20
+ import { DebugConfigurationService } from './debug-configuration.service';
21
+ import { DebugToolbarView } from './debug-toolbar.view';
22
+
23
+ interface ConfigurationSelectorProps {
24
+ currentValue: string;
25
+ options: DebugSessionOptions[];
26
+ isMultiRootWorkspace: boolean;
27
+ addConfigurationLabel: string;
28
+ workspaceRoots: string[];
29
+ toValue: (option: DebugSessionOptions) => string;
30
+ onChangeConfiguration(event: React.ChangeEvent<HTMLSelectElement> | string): void;
31
+ }
32
+
33
+ const ConfigurationSelector = React.memo(
34
+ ({
35
+ currentValue,
36
+ options,
37
+ onChangeConfiguration,
38
+ isMultiRootWorkspace,
39
+ addConfigurationLabel,
40
+ toValue,
41
+ workspaceRoots,
42
+ }: ConfigurationSelectorProps) => {
43
+ const renderConfigurationOptions = React.useCallback(
44
+ (options) => {
45
+ if (options && options.length) {
46
+ return options.map((option, index) => {
47
+ const label = isMultiRootWorkspace
48
+ ? `${option.configuration.name} (${new URI(option.workspaceFolderUri).displayName})`
49
+ : option.configuration.name;
50
+ return isElectronRenderer() ? (
51
+ <option key={index} value={toValue(option)} label={label}>
52
+ {label}
53
+ </option>
54
+ ) : (
55
+ <Option key={index} value={toValue(option)} label={label}>
56
+ {label}
57
+ </Option>
58
+ );
59
+ });
60
+ } else {
61
+ return isElectronRenderer()
62
+ ? [
63
+ <option
64
+ value={DEFAULT_NO_CONFIGURATION_KEY}
65
+ key={DEFAULT_NO_CONFIGURATION_KEY}
66
+ label={localize('debug.action.no.configuration')}
67
+ >
68
+ {localize('debug.action.no.configuration')}
69
+ </option>,
70
+ ]
71
+ : [
72
+ <Option
73
+ value={DEFAULT_NO_CONFIGURATION_KEY}
74
+ key={DEFAULT_NO_CONFIGURATION_KEY}
75
+ label={localize('debug.action.no.configuration')}
76
+ >
77
+ {localize('debug.action.no.configuration')}
78
+ </Option>,
79
+ ];
80
+ }
81
+ },
82
+ [isMultiRootWorkspace],
83
+ );
84
+
85
+ const renderAddConfigurationOptions = React.useCallback(() => {
86
+ if (isMultiRootWorkspace) {
87
+ let longName: string = addConfigurationLabel;
88
+ const addonOptions = workspaceRoots.map((root, index) => {
89
+ const label = `${addConfigurationLabel} (${new URI(root).displayName})`;
90
+ if (longName.length < label.length) {
91
+ longName = label;
92
+ }
93
+ return isElectronRenderer() ? (
94
+ <option
95
+ value={`${DEFAULT_ADD_CONFIGURATION_KEY}${index}`}
96
+ key={`${DEFAULT_ADD_CONFIGURATION_KEY}${index}`}
97
+ label={label}
98
+ >
99
+ {label}
100
+ </option>
101
+ ) : (
102
+ <Option
103
+ value={`${DEFAULT_ADD_CONFIGURATION_KEY}${index}`}
104
+ key={`${DEFAULT_ADD_CONFIGURATION_KEY}${index}`}
105
+ label={label}
106
+ >
107
+ {label}
108
+ </Option>
109
+ );
110
+ });
111
+ const disabledOption = isElectronRenderer()
112
+ ? [
113
+ <option disabled key={'--'} value={longName!.replace(/./g, '-')}>
114
+ {longName!.replace(/./g, '-')}
115
+ </option>,
116
+ ]
117
+ : [
118
+ <Option disabled key={'--'} value={longName!.replace(/./g, '-')}>
119
+ {longName!.replace(/./g, '-')}
120
+ </Option>,
121
+ ];
122
+ return disabledOption.concat(addonOptions);
123
+ } else {
124
+ const label = addConfigurationLabel;
125
+ return isElectronRenderer()
126
+ ? [
127
+ <option disabled key={'--'} value={label!.replace(/./g, '-')}>
128
+ {label!.replace(/./g, '-')}
129
+ </option>,
130
+ <option value={DEFAULT_ADD_CONFIGURATION_KEY} key={DEFAULT_ADD_CONFIGURATION_KEY} label={label}>
131
+ {label}
132
+ </option>,
133
+ ]
134
+ : [
135
+ <Option disabled key={'--'} value={label!.replace(/./g, '-')}>
136
+ {label!.replace(/./g, '-')}
137
+ </Option>,
138
+ <Option value={DEFAULT_ADD_CONFIGURATION_KEY} key={DEFAULT_ADD_CONFIGURATION_KEY} label={label}>
139
+ {label}
140
+ </Option>,
141
+ ];
142
+ }
143
+ }, [isMultiRootWorkspace, addConfigurationLabel]);
144
+
145
+ if (isElectronRenderer()) {
146
+ return (
147
+ <NativeSelect
148
+ value={currentValue}
149
+ onChange={onChangeConfiguration}
150
+ className={cls(styles.debug_selection, styles.special_radius)}
151
+ >
152
+ {renderConfigurationOptions(options)}
153
+ {renderAddConfigurationOptions()}
154
+ </NativeSelect>
155
+ );
156
+ }
157
+
158
+ return (
159
+ <Select
160
+ value={currentValue}
161
+ onChange={onChangeConfiguration}
162
+ className={cls(styles.debug_selection, styles.special_radius)}
163
+ >
164
+ {renderConfigurationOptions(options)}
165
+ {renderAddConfigurationOptions()}
166
+ </Select>
167
+ );
168
+ },
169
+ );
170
+
171
+ interface DebugActionBarProps {
172
+ runDebug(): void;
173
+ openConfiguration(): void;
174
+ openDebugConsole(): void;
175
+ }
176
+
177
+ export const DebugActionBar = React.memo(({ runDebug, openConfiguration, openDebugConsole }: DebugActionBarProps) => (
178
+ <div className={styles.kt_debug_actions}>
179
+ <DebugAction
180
+ id='debug.action.start'
181
+ icon={'start'}
182
+ label={localize('debug.action.start')}
183
+ run={runDebug}
184
+ ></DebugAction>
185
+ <DebugAction
186
+ id='debug.action.open.configuration'
187
+ icon={'setting'}
188
+ label={localize('debug.action.open.configuration')}
189
+ run={openConfiguration}
190
+ ></DebugAction>
191
+ <DebugAction
192
+ id='debug.action.debug.console'
193
+ icon={'terminal'}
194
+ label={localize('debug.action.debug.console')}
195
+ run={openDebugConsole}
196
+ ></DebugAction>
197
+ </div>
198
+ ));
199
+
200
+ export const DebugConfigurationView = observer((props) => {
201
+ const {
202
+ configurationOptions,
203
+ toValue,
204
+ currentValue,
205
+ openConfiguration,
206
+ addConfiguration,
207
+ openDebugConsole,
208
+ updateConfiguration,
209
+ start,
210
+ float,
211
+ isMultiRootWorkspace,
212
+ workspaceRoots,
213
+ } = useInjectable<DebugConfigurationService>(DebugConfigurationService);
214
+ const addConfigurationLabel = localize('debug.action.add.configuration');
215
+ const setCurrentConfiguration = React.useCallback((event: React.ChangeEvent<HTMLSelectElement> | string) => {
216
+ let value: React.ChangeEvent<HTMLSelectElement> | string;
217
+ if (typeof event === 'object') {
218
+ value = event.target.value;
219
+ } else {
220
+ value = event;
221
+ }
222
+ if (value.startsWith(DEFAULT_ADD_CONFIGURATION_KEY)) {
223
+ const index = value.slice(DEFAULT_ADD_CONFIGURATION_KEY.length);
224
+ if (index) {
225
+ addConfiguration(workspaceRoots[index]);
226
+ } else {
227
+ addConfiguration(workspaceRoots[0]);
228
+ }
229
+ } else {
230
+ const [name, workspaceAndIndex] = value.split(DEFAULT_CONFIGURATION_NAME_SEPARATOR);
231
+ const [workspaceFolderUri, index] = workspaceAndIndex.split(DEFAULT_CONFIGURATION_INDEX_SEPARATOR);
232
+ updateConfiguration(name, workspaceFolderUri, +index);
233
+ }
234
+ }, []);
235
+
236
+ return (
237
+ <div>
238
+ <div className={styles.debug_configuration_toolbar}>
239
+ <ConfigurationSelector
240
+ currentValue={currentValue}
241
+ options={configurationOptions}
242
+ onChangeConfiguration={setCurrentConfiguration}
243
+ isMultiRootWorkspace={isMultiRootWorkspace}
244
+ addConfigurationLabel={addConfigurationLabel}
245
+ toValue={toValue}
246
+ workspaceRoots={workspaceRoots}
247
+ />
248
+ <DebugActionBar runDebug={start} openConfiguration={openConfiguration} openDebugConsole={openDebugConsole} />
249
+ </div>
250
+ {!float && <DebugToolbarView float={false} />}
251
+ </div>
252
+ );
253
+ });
@@ -0,0 +1,167 @@
1
+ import { observable, action } from 'mobx';
2
+
3
+ import { Injectable, Autowired, INJECTOR_TOKEN, Injector } from '@opensumi/di';
4
+ import { IContextKeyService, IReporterService, memoize } from '@opensumi/ide-core-browser';
5
+ import { AbstractContextMenuService, MenuId } from '@opensumi/ide-core-browser/lib/menu/next';
6
+ import { IContextMenu } from '@opensumi/ide-core-browser/lib/menu/next';
7
+ import { IElectronMainUIService } from '@opensumi/ide-core-common/lib/electron';
8
+
9
+ import { DebugState, DEBUG_REPORT_NAME } from '../../../common';
10
+ import { DebugSession } from '../../debug-session';
11
+ import { DebugViewModel } from '../debug-view-model';
12
+
13
+ @Injectable()
14
+ export class DebugToolbarService {
15
+ @Autowired(IContextKeyService)
16
+ private readonly contextKeyService: IContextKeyService;
17
+
18
+ @Autowired(AbstractContextMenuService)
19
+ private readonly contextMenuService: AbstractContextMenuService;
20
+
21
+ @Autowired(DebugViewModel)
22
+ protected readonly model: DebugViewModel;
23
+
24
+ @Autowired(IReporterService)
25
+ protected readonly reporterService: IReporterService;
26
+
27
+ @Autowired(INJECTOR_TOKEN)
28
+ private readonly injector: Injector;
29
+
30
+ @observable
31
+ state: DebugState;
32
+
33
+ @observable
34
+ sessionCount: number;
35
+
36
+ @observable
37
+ currentSession: DebugSession | undefined;
38
+
39
+ @observable.shallow
40
+ sessions: DebugSession[] = [];
41
+
42
+ public readonly toolBarMenuMap: Map<string, IContextMenu> = new Map();
43
+
44
+ constructor() {
45
+ this.model.onDidChange(() => {
46
+ this.updateToolBarMenu();
47
+ this.updateModel();
48
+ });
49
+ }
50
+
51
+ @memoize
52
+ get mainUIService() {
53
+ return this.injector.get(IElectronMainUIService);
54
+ }
55
+
56
+ @action
57
+ updateModel() {
58
+ this.state = this.model.state;
59
+ this.currentSession = this.model.currentSession;
60
+ this.sessions = Array.from(this.model.sessions).filter(
61
+ (session: DebugSession) => session && session.state > DebugState.Inactive,
62
+ );
63
+ this.sessionCount = this.sessions.length;
64
+ }
65
+
66
+ @action
67
+ updateToolBarMenu() {
68
+ if (this.currentSession && this.currentSession.id && !this.toolBarMenuMap.has(this.currentSession.id)) {
69
+ const contextMenu = this.contextMenuService.createMenu({
70
+ id: MenuId.DebugToolBar,
71
+ contextKeyService: this.contextKeyService.createScoped(),
72
+ });
73
+ this.currentSession.on('terminated', () => {
74
+ this.toolBarMenuMap.delete(this.currentSession?.id!);
75
+ });
76
+
77
+ this.toolBarMenuMap.set(this.currentSession.id, contextMenu);
78
+ }
79
+ }
80
+
81
+ private instrumentReporter(name: string): () => void {
82
+ const session = this.model.currentSession!;
83
+ const languageType = session.configuration?.type;
84
+ const currentThread = this.model.currentThread;
85
+ const threadId = currentThread?.raw?.id;
86
+ this.model.reportAction(session.id, threadId, name);
87
+ const extra = {
88
+ type: languageType,
89
+ request: this.currentSession?.configuration.request,
90
+ sessionId: session.id,
91
+ threadId,
92
+ };
93
+ this.model.report(DEBUG_REPORT_NAME.DEBUG_TOOLBAR_OPERATION, name, extra);
94
+ const reportTime = this.model.reportTime(DEBUG_REPORT_NAME.DEBUG_TOOLBAR_OPERATION_TIME, extra);
95
+ return () => {
96
+ reportTime(name);
97
+ };
98
+ }
99
+
100
+ doStart = () => this.model.start();
101
+
102
+ doRestart = async () => {
103
+ const reportTimeEnd = this.instrumentReporter('restart');
104
+ const terminated = await this.model.restart();
105
+ reportTimeEnd();
106
+ return terminated;
107
+ };
108
+
109
+ doStop = async () => {
110
+ if (!this.model.currentSession) {
111
+ return;
112
+ }
113
+ const reportTimeEnd = this.instrumentReporter('stop');
114
+ const terminated = await this.model.currentSession.terminate();
115
+ reportTimeEnd();
116
+ return terminated;
117
+ };
118
+ doContinue = async () => {
119
+ if (!this.model.currentThread) {
120
+ return;
121
+ }
122
+ const reportTimeEnd = this.instrumentReporter('continue');
123
+ const terminated = await this.model.currentThread.continue();
124
+ reportTimeEnd();
125
+ return terminated;
126
+ };
127
+ doPause = async () => {
128
+ if (!this.model.currentThread) {
129
+ return;
130
+ }
131
+ const reportTimeEnd = this.instrumentReporter('pause');
132
+ const terminated = await this.model.currentThread.pause();
133
+ reportTimeEnd();
134
+ return terminated;
135
+ };
136
+ doStepOver = async () => {
137
+ if (!this.model.currentThread) {
138
+ return;
139
+ }
140
+ const reportTimeEnd = this.instrumentReporter('stepOver');
141
+ const terminated = await this.model.currentThread.stepOver();
142
+ reportTimeEnd();
143
+ return terminated;
144
+ };
145
+ doStepIn = async () => {
146
+ if (!this.model.currentThread) {
147
+ return;
148
+ }
149
+ const reportTimeEnd = this.instrumentReporter('stepIn');
150
+ const terminated = await this.model.currentThread.stepIn();
151
+ reportTimeEnd();
152
+ return terminated;
153
+ };
154
+ doStepOut = async () => {
155
+ if (!this.model.currentThread) {
156
+ return;
157
+ }
158
+ const reportTimeEnd = this.instrumentReporter('stepOut');
159
+ const terminated = await this.model.currentThread.stepOut();
160
+ reportTimeEnd();
161
+ return terminated;
162
+ };
163
+
164
+ updateCurrentSession = (session: DebugSession) => {
165
+ this.model.currentSession = session;
166
+ };
167
+ }