@opensumi/ide-debug 2.21.5-rc-1669016550.0 → 2.21.5

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 (159) hide show
  1. package/lib/browser/view/configuration/debug-configuration.module.less +5 -5
  2. package/lib/browser/view/configuration/debug-configuration.view.d.ts.map +1 -1
  3. package/lib/browser/view/configuration/debug-configuration.view.js +1 -1
  4. package/lib/browser/view/configuration/debug-configuration.view.js.map +1 -1
  5. package/lib/browser/view/configuration/debug-toolbar.view.js +2 -2
  6. package/lib/browser/view/configuration/debug-toolbar.view.js.map +1 -1
  7. package/lib/browser/view/console/debug-console.module.less +1 -1
  8. package/lib/browser/view/console/debug-console.view.js +2 -2
  9. package/lib/browser/view/console/debug-console.view.js.map +1 -1
  10. package/lib/browser/view/variables/debug-variables.module.less +1 -1
  11. package/lib/browser/view/variables/debug-variables.view.js +1 -1
  12. package/lib/browser/view/variables/debug-variables.view.js.map +1 -1
  13. package/lib/browser/view/watch/debug-watch.module.less +1 -1
  14. package/lib/browser/view/watch/debug-watch.view.js +1 -1
  15. package/lib/browser/view/watch/debug-watch.view.js.map +1 -1
  16. package/package.json +25 -26
  17. package/src/browser/assets/breakpoint-conditional-disabled.svg +0 -4
  18. package/src/browser/assets/breakpoint-conditional-unverified.svg +0 -4
  19. package/src/browser/assets/breakpoint-conditional.svg +0 -4
  20. package/src/browser/assets/breakpoint-disabled.svg +0 -4
  21. package/src/browser/assets/breakpoint-hint.svg +0 -4
  22. package/src/browser/assets/breakpoint-log-disabled.svg +0 -4
  23. package/src/browser/assets/breakpoint-log-unverified.svg +0 -4
  24. package/src/browser/assets/breakpoint-log.svg +0 -4
  25. package/src/browser/assets/breakpoint-unsupported.svg +0 -4
  26. package/src/browser/assets/breakpoint-unverified.svg +0 -4
  27. package/src/browser/assets/breakpoint.svg +0 -4
  28. package/src/browser/assets/breakpoints-activate-inverse.svg +0 -4
  29. package/src/browser/assets/breakpoints-activate.svg +0 -4
  30. package/src/browser/assets/configure-inverse.svg +0 -4
  31. package/src/browser/assets/configure.svg +0 -4
  32. package/src/browser/assets/continue-inverse.svg +0 -4
  33. package/src/browser/assets/current-and-breakpoint.svg +0 -4
  34. package/src/browser/assets/current-arrow.svg +0 -4
  35. package/src/browser/assets/remove-all-inverse.svg +0 -4
  36. package/src/browser/assets/remove-all.svg +0 -4
  37. package/src/browser/assets/repl-inverse.svg +0 -4
  38. package/src/browser/assets/repl.svg +0 -4
  39. package/src/browser/assets/restart-inverse.svg +0 -4
  40. package/src/browser/assets/stackframe-and-breakpoint.svg +0 -4
  41. package/src/browser/assets/stackframe-arrow.svg +0 -4
  42. package/src/browser/assets/start-inverse.svg +0 -4
  43. package/src/browser/breakpoint/breakpoint-decoration.ts +0 -57
  44. package/src/browser/breakpoint/breakpoint-manager.ts +0 -348
  45. package/src/browser/breakpoint/breakpoint-marker.ts +0 -70
  46. package/src/browser/breakpoint/index.ts +0 -3
  47. package/src/browser/components/debug-action/index.module.less +0 -73
  48. package/src/browser/components/debug-action/index.tsx +0 -40
  49. package/src/browser/components/debug-exception-widget.less +0 -42
  50. package/src/browser/components/floating-click-widget/index.module.less +0 -5
  51. package/src/browser/components/floating-click-widget/index.tsx +0 -21
  52. package/src/browser/components/index.ts +0 -1
  53. package/src/browser/contextkeys/debug-call-stack-item-type-key.ts +0 -4
  54. package/src/browser/contextkeys/debug-contextkey.service.ts +0 -54
  55. package/src/browser/contextkeys/index.ts +0 -1
  56. package/src/browser/debug-ansi-handle.ts +0 -521
  57. package/src/browser/debug-configuration-manager.ts +0 -513
  58. package/src/browser/debug-configuration-model.ts +0 -66
  59. package/src/browser/debug-contribution.ts +0 -904
  60. package/src/browser/debug-exception-widget.tsx +0 -89
  61. package/src/browser/debug-link-detector.ts +0 -234
  62. package/src/browser/debug-memory.ts +0 -220
  63. package/src/browser/debug-preferences.ts +0 -70
  64. package/src/browser/debug-progress.service.ts +0 -122
  65. package/src/browser/debug-schema-updater.ts +0 -67
  66. package/src/browser/debug-service.ts +0 -42
  67. package/src/browser/debug-session-connection.ts +0 -333
  68. package/src/browser/debug-session-contribution.ts +0 -57
  69. package/src/browser/debug-session-manager.ts +0 -622
  70. package/src/browser/debug-session.ts +0 -1179
  71. package/src/browser/debug-style.less +0 -128
  72. package/src/browser/debugUtils.ts +0 -110
  73. package/src/browser/editor/debug-breakpoint-widget.ts +0 -99
  74. package/src/browser/editor/debug-breakpoint-zone-widget.tsx +0 -262
  75. package/src/browser/editor/debug-breakpoint.module.less +0 -31
  76. package/src/browser/editor/debug-editor-contribution.ts +0 -590
  77. package/src/browser/editor/debug-expression-provider.ts +0 -101
  78. package/src/browser/editor/debug-hover-model.ts +0 -38
  79. package/src/browser/editor/debug-hover-source.ts +0 -107
  80. package/src/browser/editor/debug-hover-tree.model.service.ts +0 -332
  81. package/src/browser/editor/debug-hover-widget.tsx +0 -200
  82. package/src/browser/editor/debug-hover.module.less +0 -29
  83. package/src/browser/editor/debug-hover.view.tsx +0 -147
  84. package/src/browser/editor/debug-model-manager.ts +0 -220
  85. package/src/browser/editor/debug-model.ts +0 -853
  86. package/src/browser/editor/debug-run-to-cursor.service.ts +0 -180
  87. package/src/browser/editor/debug-styles.ts +0 -66
  88. package/src/browser/editor/evaluatable-expression.ts +0 -47
  89. package/src/browser/editor/index.ts +0 -6
  90. package/src/browser/index.ts +0 -135
  91. package/src/browser/markers/index.ts +0 -2
  92. package/src/browser/markers/marker-manager.ts +0 -201
  93. package/src/browser/markers/marker.ts +0 -20
  94. package/src/browser/model/debug-source.ts +0 -144
  95. package/src/browser/model/debug-stack-frame.ts +0 -111
  96. package/src/browser/model/debug-thread.ts +0 -186
  97. package/src/browser/model/debug-watch.ts +0 -130
  98. package/src/browser/model/index.ts +0 -4
  99. package/src/browser/preferences/launch-folder-preference-provider.ts +0 -23
  100. package/src/browser/preferences/launch-preferences-contribution.ts +0 -9
  101. package/src/browser/preferences/launch-preferences.ts +0 -16
  102. package/src/browser/tree/debug-console-tree-node.define.tsx +0 -76
  103. package/src/browser/tree/debug-tree-node.define.ts +0 -768
  104. package/src/browser/tree/index.ts +0 -2
  105. package/src/browser/view/breakpoints/debug-breakpoints.module.less +0 -72
  106. package/src/browser/view/breakpoints/debug-breakpoints.service.ts +0 -217
  107. package/src/browser/view/breakpoints/debug-breakpoints.view.tsx +0 -174
  108. package/src/browser/view/configuration/debug-configuration.module.less +0 -110
  109. package/src/browser/view/configuration/debug-configuration.service.ts +0 -170
  110. package/src/browser/view/configuration/debug-configuration.view.tsx +0 -252
  111. package/src/browser/view/configuration/debug-toolbar.service.ts +0 -167
  112. package/src/browser/view/configuration/debug-toolbar.view.tsx +0 -335
  113. package/src/browser/view/console/debug-console-filter.model.ts +0 -49
  114. package/src/browser/view/console/debug-console-filter.service.ts +0 -81
  115. package/src/browser/view/console/debug-console-filter.view.tsx +0 -78
  116. package/src/browser/view/console/debug-console-model.ts +0 -48
  117. package/src/browser/view/console/debug-console-session.ts +0 -164
  118. package/src/browser/view/console/debug-console-toolbar.view.tsx +0 -28
  119. package/src/browser/view/console/debug-console-tree.model.service.ts +0 -550
  120. package/src/browser/view/console/debug-console.contribution.ts +0 -181
  121. package/src/browser/view/console/debug-console.module.less +0 -372
  122. package/src/browser/view/console/debug-console.service.ts +0 -433
  123. package/src/browser/view/console/debug-console.view.tsx +0 -500
  124. package/src/browser/view/debug-view-model.ts +0 -182
  125. package/src/browser/view/frames/debug-call-stack-frame.view.tsx +0 -224
  126. package/src/browser/view/frames/debug-call-stack-session.view.tsx +0 -237
  127. package/src/browser/view/frames/debug-call-stack-thread.view.tsx +0 -93
  128. package/src/browser/view/frames/debug-call-stack.contribution.ts +0 -88
  129. package/src/browser/view/frames/debug-call-stack.module.less +0 -193
  130. package/src/browser/view/frames/debug-call-stack.operation.tsx +0 -97
  131. package/src/browser/view/frames/debug-call-stack.service.ts +0 -105
  132. package/src/browser/view/frames/debug-call-stack.view.tsx +0 -43
  133. package/src/browser/view/variables/debug-variables-model.ts +0 -38
  134. package/src/browser/view/variables/debug-variables-tree.model.service.ts +0 -467
  135. package/src/browser/view/variables/debug-variables.contribution.ts +0 -244
  136. package/src/browser/view/variables/debug-variables.module.less +0 -148
  137. package/src/browser/view/variables/debug-variables.view.tsx +0 -303
  138. package/src/browser/view/watch/debug-watch-model.ts +0 -38
  139. package/src/browser/view/watch/debug-watch-tree.model.service.ts +0 -567
  140. package/src/browser/view/watch/debug-watch.contribution.ts +0 -167
  141. package/src/browser/view/watch/debug-watch.module.less +0 -188
  142. package/src/browser/view/watch/debug-watch.view.tsx +0 -337
  143. package/src/common/constants.ts +0 -81
  144. package/src/common/debug-breakpoint.ts +0 -43
  145. package/src/common/debug-configuration.ts +0 -68
  146. package/src/common/debug-editor.ts +0 -4
  147. package/src/common/debug-hover.ts +0 -31
  148. package/src/common/debug-model.ts +0 -247
  149. package/src/common/debug-progress.ts +0 -8
  150. package/src/common/debug-schema-updater.ts +0 -1
  151. package/src/common/debug-service.ts +0 -176
  152. package/src/common/debug-session-options.ts +0 -19
  153. package/src/common/debug-session.ts +0 -200
  154. package/src/common/evaluatable-expression.ts +0 -43
  155. package/src/common/index.ts +0 -14
  156. package/src/common/inline-values.ts +0 -77
  157. package/src/common/terminal.ts +0 -163
  158. package/src/common/types.ts +0 -86
  159. package/src/index.ts +0 -1
@@ -1,622 +0,0 @@
1
- /** ******************************************************************************
2
- * Copyright (C) 2018 Red Hat, Inc. and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License v. 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0.
7
- *
8
- * This Source Code may also be made available under the following Secondary
9
- * Licenses when the conditions for such availability set forth in the Eclipse
10
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- * with the GNU Classpath Exception which is available at
12
- * https://www.gnu.org/software/classpath/license.html.
13
- *
14
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
- // Some code copied and modified from https://github.com/eclipse-theia/theia/tree/v1.14.0/packages/debug/src/browser/debug-session-manager.ts
17
-
18
- import { Injectable, Autowired } from '@opensumi/di';
19
- import {
20
- WaitUntilEvent,
21
- Emitter,
22
- Event,
23
- URI,
24
- IContextKey,
25
- DisposableCollection,
26
- IContextKeyService,
27
- formatLocalize,
28
- Uri,
29
- IReporterService,
30
- uuid,
31
- localize,
32
- COMMON_COMMANDS,
33
- CommandService,
34
- } from '@opensumi/ide-core-browser';
35
- import { LabelService } from '@opensumi/ide-core-browser/lib/services';
36
- import { WorkbenchEditorService } from '@opensumi/ide-editor';
37
- import { IMessageService } from '@opensumi/ide-overlay';
38
- import { ITaskService } from '@opensumi/ide-task/lib/common';
39
- import { IVariableResolverService } from '@opensumi/ide-variable';
40
-
41
- import {
42
- DebugConfiguration,
43
- DebugError,
44
- IDebugServer,
45
- DebugServer,
46
- DebugSessionOptions,
47
- IDebugSessionDTO,
48
- DEBUG_REPORT_NAME,
49
- IDebugSessionManager,
50
- DebugSessionExtra,
51
- DebugThreadExtra,
52
- CONTEXT_DEBUG_STOPPED_KEY,
53
- CONTEXT_IN_DEBUG_MODE_KEY,
54
- CONTEXT_DEBUG_TYPE_KEY,
55
- DebugState,
56
- } from '../common';
57
- import { IDebugProgress } from '../common/debug-progress';
58
-
59
- import { BreakpointManager } from './breakpoint/breakpoint-manager';
60
- import { DebugContextKey } from './contextkeys/debug-contextkey.service';
61
- import { DebugSession } from './debug-session';
62
- import { DebugSessionContributionRegistry } from './debug-session-contribution';
63
- import { isRemoteAttach } from './debugUtils';
64
- import { DebugModelManager } from './editor/debug-model-manager';
65
- import { DebugStackFrame } from './model/debug-stack-frame';
66
- import { DebugThread } from './model/debug-thread';
67
-
68
- export type WillStartDebugSession = WaitUntilEvent;
69
-
70
- export interface WillResolveDebugConfiguration extends WaitUntilEvent {
71
- debugType: string;
72
- }
73
-
74
- export interface DidChangeActiveDebugSession {
75
- previous: DebugSession | undefined;
76
- current: DebugSession | undefined;
77
- }
78
-
79
- export interface DebugSessionCustomEvent {
80
- readonly body?: any;
81
- readonly event: string;
82
- readonly session: DebugSession;
83
- }
84
-
85
- @Injectable()
86
- export class DebugSessionManager implements IDebugSessionManager {
87
- protected readonly _uid = uuid();
88
- protected readonly _sessions = new Map<string, DebugSession>();
89
- protected readonly _extraMap = new Map<string, DebugSessionExtra>();
90
- protected _actionIndex = 0;
91
-
92
- protected readonly onWillStartDebugSessionEmitter = new Emitter<WillStartDebugSession>();
93
- readonly onWillStartDebugSession: Event<WillStartDebugSession> = this.onWillStartDebugSessionEmitter.event;
94
-
95
- protected readonly onWillResolveDebugConfigurationEmitter = new Emitter<WillResolveDebugConfiguration>();
96
- readonly onWillResolveDebugConfiguration: Event<WillResolveDebugConfiguration> =
97
- this.onWillResolveDebugConfigurationEmitter.event;
98
-
99
- protected readonly onDidCreateDebugSessionEmitter = new Emitter<DebugSession>();
100
- readonly onDidCreateDebugSession: Event<DebugSession> = this.onDidCreateDebugSessionEmitter.event;
101
-
102
- protected readonly onDidStartDebugSessionEmitter = new Emitter<DebugSession>();
103
- readonly onDidStartDebugSession: Event<DebugSession> = this.onDidStartDebugSessionEmitter.event;
104
-
105
- protected readonly onDidStopDebugSessionEmitter = new Emitter<DebugSession>();
106
- readonly onDidStopDebugSession: Event<DebugSession> = this.onDidStopDebugSessionEmitter.event;
107
-
108
- protected readonly onDidChangeActiveDebugSessionEmitter = new Emitter<DidChangeActiveDebugSession>();
109
- readonly onDidChangeActiveDebugSession: Event<DidChangeActiveDebugSession> =
110
- this.onDidChangeActiveDebugSessionEmitter.event;
111
-
112
- protected readonly onDidDestroyDebugSessionEmitter = new Emitter<DebugSession>();
113
- readonly onDidDestroyDebugSession: Event<DebugSession> = this.onDidDestroyDebugSessionEmitter.event;
114
-
115
- protected readonly onDidReceiveDebugSessionCustomEventEmitter = new Emitter<DebugSessionCustomEvent>();
116
- readonly onDidReceiveDebugSessionCustomEvent: Event<DebugSessionCustomEvent> =
117
- this.onDidReceiveDebugSessionCustomEventEmitter.event;
118
-
119
- protected readonly onDidChangeEmitter = new Emitter<DebugSession | undefined>();
120
- readonly onDidChange: Event<DebugSession | undefined> = this.onDidChangeEmitter.event;
121
- protected fireDidChange(current: DebugSession | undefined): void {
122
- this.inDebugModeKey.set(this.inDebugMode);
123
- this.onDidChangeEmitter.fire(current);
124
- }
125
-
126
- protected debugTypeKey: IContextKey<string>;
127
- protected inDebugModeKey: IContextKey<boolean>;
128
- protected debugStopped: IContextKey<boolean>;
129
-
130
- @Autowired(LabelService)
131
- protected readonly labelProvider: LabelService;
132
-
133
- @Autowired(IContextKeyService)
134
- protected readonly contextKeyService: IContextKeyService;
135
-
136
- @Autowired(DebugSessionContributionRegistry)
137
- protected readonly sessionContributionRegistry: DebugSessionContributionRegistry;
138
-
139
- @Autowired(IDebugServer)
140
- protected readonly debug: DebugServer;
141
-
142
- @Autowired(WorkbenchEditorService)
143
- protected readonly workbenchEditorService: WorkbenchEditorService;
144
-
145
- @Autowired(IMessageService)
146
- protected readonly messageService: IMessageService;
147
-
148
- @Autowired(IVariableResolverService)
149
- protected readonly variableResolver: IVariableResolverService;
150
-
151
- @Autowired(BreakpointManager)
152
- protected readonly breakpoints: BreakpointManager;
153
-
154
- @Autowired(DebugModelManager)
155
- protected readonly modelManager: DebugModelManager;
156
-
157
- @Autowired(ITaskService)
158
- protected readonly taskService: ITaskService;
159
-
160
- @Autowired(IReporterService)
161
- protected readonly reporterService: IReporterService;
162
-
163
- @Autowired(IDebugProgress)
164
- protected readonly debugProgressService: IDebugProgress;
165
-
166
- @Autowired(DebugContextKey)
167
- protected readonly debugContextKey: DebugContextKey;
168
-
169
- @Autowired(CommandService)
170
- protected readonly commandService: CommandService;
171
-
172
- constructor() {
173
- this.init();
174
- }
175
-
176
- protected init(): void {
177
- this.debugTypeKey = this.contextKeyService.createKey<string>(CONTEXT_DEBUG_TYPE_KEY, undefined);
178
- this.inDebugModeKey = this.contextKeyService.createKey<boolean>(CONTEXT_IN_DEBUG_MODE_KEY, this.inDebugMode);
179
- this.debugStopped = this.contextKeyService.createKey<boolean>(CONTEXT_DEBUG_STOPPED_KEY, false);
180
-
181
- this.modelManager.onModelChanged((event) => {
182
- const { newModelUrl } = event;
183
- if (newModelUrl) {
184
- const uri = URI.parse(newModelUrl.toString());
185
- const model = this.modelManager.model;
186
- if (this.currentSession && this.currentThread && model) {
187
- const frame = this.currentThread.frames.find((f) => f.source?.uri.toString() === uri.toString());
188
- if (frame && frame !== this.currentFrame) {
189
- this.currentThread.currentFrame = frame;
190
- setTimeout(() => {
191
- if (this.workbenchEditorService.currentEditor) {
192
- this.workbenchEditorService.currentEditor.monacoEditor.revealLineInCenter(frame.raw.line);
193
- }
194
- }, 0);
195
- }
196
- }
197
- }
198
- });
199
- }
200
-
201
- private _getExtra(
202
- sessionId: string | undefined,
203
- threadId: number | string | undefined,
204
- ): DebugThreadExtra | undefined {
205
- if (sessionId == null) {
206
- return;
207
- }
208
- const data = this._extraMap.get(sessionId);
209
- if (data) {
210
- return {
211
- traceId: data.traceId,
212
- remote: data.remote,
213
- adapterID: data.adapterID,
214
- request: data.request,
215
- ...(threadId && data.threads.get(`${threadId}`)),
216
- };
217
- }
218
- }
219
-
220
- public getExtra(sessionId: string | undefined, threadId: number | string | undefined): DebugThreadExtra | undefined {
221
- return this._getExtra(sessionId, threadId);
222
- }
223
-
224
- private _setExtra(sessionId: string, threadId: string, extra?: DebugThreadExtra) {
225
- const data = this._extraMap.get(sessionId);
226
- if (!data) {
227
- return;
228
- }
229
- if (extra) {
230
- data.threads.set(threadId, extra);
231
- } else {
232
- data.threads.delete(threadId);
233
- }
234
- }
235
-
236
- public setExtra(sessionId: string, threadId: string, extra?: DebugThreadExtra) {
237
- return this._setExtra(sessionId, threadId, extra);
238
- }
239
-
240
- report(name: string, msg: string | undefined, extra?: any) {
241
- extra = {
242
- traceId: this._uid,
243
- ...this._getExtra(extra?.sessionId, extra?.threadId),
244
- ...extra,
245
- };
246
- return this.reporterService.point(name, msg, extra);
247
- }
248
-
249
- reportTime(name: string, defaults?: any) {
250
- const timer = this.reporterService.time(name);
251
- return (msg: string | undefined, extra?: any) => {
252
- extra = {
253
- ...defaults,
254
- ...extra,
255
- };
256
- extra = {
257
- traceId: this._uid,
258
- ...this._getExtra(extra?.sessionId, extra?.threadId),
259
- ...extra,
260
- };
261
- return timer.timeEnd(msg, extra);
262
- };
263
- }
264
-
265
- reportAction(sessionId: string, threadId: number | string | undefined, action: string) {
266
- let extra = this._getExtra(sessionId, threadId);
267
- if (!extra) {
268
- // session 不存在,忽略
269
- return;
270
- }
271
- if (threadId && !extra.threadId) {
272
- extra = {
273
- ...extra,
274
- };
275
- }
276
- this._actionIndex += 1;
277
- extra.action = `${action}-${this._actionIndex}`;
278
-
279
- // 记录被暂停的文件路径和行号
280
- extra.filePath = this.currentFrame?.raw.source?.path;
281
- extra.fileLineNumber = this.currentFrame?.raw.line;
282
- this._setExtra(sessionId, `${threadId ?? ''}`, extra);
283
- }
284
-
285
- async start(options: DebugSessionOptions): Promise<DebugSession | undefined> {
286
- const { configuration } = options;
287
- const extra: DebugSessionExtra = {
288
- adapterID: configuration.type,
289
- request: configuration.request === 'launch' ? 'launch' : 'attach',
290
- traceId: this._uid,
291
- remote: 0,
292
- threads: new Map(),
293
- };
294
- if (isRemoteAttach(configuration)) {
295
- extra.remote = 1;
296
- }
297
- this.report(DEBUG_REPORT_NAME.DEBUG_BREAKPOINT, 'number', {
298
- count: this.breakpoints.getBreakpoints().length,
299
- ...extra,
300
- });
301
- if (!options.configuration.__restart) {
302
- if (this.isExistedDebugSession(options)) {
303
- this.messageService.error(formatLocalize('debug.launch.existed', options.configuration.name));
304
- return;
305
- }
306
- }
307
- try {
308
- const timeStart = this.reportTime(DEBUG_REPORT_NAME.DEBUG_SESSION_START_TIME, extra);
309
- await this.fireWillStartDebugSession();
310
- const resolved = await this.resolveConfiguration(options);
311
- if (!resolved) {
312
- if (options.configuration.type) {
313
- this.messageService.error(formatLocalize('debug.notSupported.type', options.configuration.type));
314
- } else {
315
- this.messageService.error(localize('debug.notSupported.any'));
316
- }
317
- return;
318
- } else if (resolved.configuration.preLaunchTask) {
319
- this.debugProgressService.onDebugServiceStateChange(DebugState.Initializing);
320
- const workspaceFolderUri = Uri.parse(resolved.workspaceFolderUri!);
321
- const task = await this.taskService.getTask(workspaceFolderUri, resolved.configuration.preLaunchTask);
322
- if (task) {
323
- const timeTask = this.reportTime(DEBUG_REPORT_NAME.DEBUG_PRE_LAUNCH_TASK_TIME, extra);
324
- const result = await this.taskService.run(task);
325
- if (result.exitCode !== 0) {
326
- this.messageService.error(
327
- `The preLaunchTask ${resolved.configuration.preLaunchTask} exitCode is ${result.exitCode}`,
328
- );
329
- }
330
- timeTask(workspaceFolderUri.toString(), {
331
- exitCode: result.exitCode,
332
- });
333
- }
334
- this.debugProgressService.onDebugServiceStateChange(DebugState.Running);
335
- }
336
- const sessionId = await this.debug.createDebugSession(resolved);
337
- timeStart(resolved.configuration.type, {
338
- adapterID: resolved.configuration.type,
339
- request: resolved.configuration.request,
340
- sessionId,
341
- });
342
- if (!sessionId) {
343
- this.messageService.error(formatLocalize('debug.launch.typeNotSupported', resolved.configuration.type));
344
- return;
345
- }
346
- return this.doStart(sessionId, resolved, extra);
347
- } catch (e) {
348
- if (DebugError.NotFound.is(e)) {
349
- this.messageService.error(formatLocalize('debug.launch.typeNotSupported', e.data.type));
350
- return;
351
- }
352
-
353
- this.messageService.error(localize('debug.launch.catchError'));
354
- throw e;
355
- }
356
- }
357
-
358
- async fireWillStartDebugSession(): Promise<void> {
359
- await WaitUntilEvent.fire(this.onWillStartDebugSessionEmitter, {});
360
- }
361
-
362
- protected configurationIds = new Map<string, number>();
363
- async resolveConfiguration(options: Readonly<DebugSessionOptions>): Promise<IDebugSessionDTO | undefined> {
364
- if (IDebugSessionDTO.is(options)) {
365
- return options;
366
- }
367
- const { workspaceFolderUri, index, noDebug, parentSession, repl, compact, lifecycleManagedByParent } = options;
368
-
369
- const resolvedConfiguration = await this.resolveDebugConfiguration(options.configuration, workspaceFolderUri);
370
- if (resolvedConfiguration && !('cwd' in resolvedConfiguration)) {
371
- // 当调试配置不存在配置项时,提供默认的 `cwd` 选项
372
- resolvedConfiguration['cwd'] = '${workspaceFolder}';
373
- }
374
- let configuration = await this.variableResolver.resolve(resolvedConfiguration, {});
375
- if (!configuration) {
376
- // 当返回值为 `undefined` 或 `null` 时,中断调试
377
- if (configuration === null) {
378
- // 当返回值为 `null` 时,打开配置文件
379
- this.commandService.executeCommand(COMMON_COMMANDS.OPEN_LAUNCH_CONFIGURATION.id);
380
- }
381
- return;
382
- }
383
- configuration = await this.resolveDebugConfigurationWithSubstitutedVariables(configuration, workspaceFolderUri);
384
- if (!configuration) {
385
- // 当返回值为 `undefined` 或 `null` 时,中断调试
386
- if (configuration === null) {
387
- // 当返回值为 `null` 时,打开配置文件
388
- this.commandService.executeCommand(COMMON_COMMANDS.OPEN_LAUNCH_CONFIGURATION.id);
389
- }
390
- return;
391
- }
392
- const key = configuration.name + workspaceFolderUri;
393
- const id = this.configurationIds.has(key) ? this.configurationIds.get(key)! + 1 : 0;
394
- this.configurationIds.set(key, id);
395
- return {
396
- id,
397
- configuration,
398
- workspaceFolderUri,
399
- index,
400
- noDebug,
401
- parentSession,
402
- repl,
403
- compact,
404
- lifecycleManagedByParent,
405
- };
406
- }
407
-
408
- async resolveDebugConfiguration(
409
- configuration: DebugConfiguration,
410
- workspaceFolderUri: string | undefined,
411
- ): Promise<DebugConfiguration | undefined | null> {
412
- await this.fireWillResolveDebugConfiguration(configuration.type);
413
- return this.debug.resolveDebugConfiguration(configuration, workspaceFolderUri);
414
- }
415
-
416
- protected async resolveDebugConfigurationWithSubstitutedVariables(
417
- configuration: DebugConfiguration,
418
- workspaceFolderUri: string | undefined,
419
- ): Promise<DebugConfiguration | undefined | null> {
420
- return this.debug.resolveDebugConfigurationWithSubstitutedVariables(configuration, workspaceFolderUri);
421
- }
422
-
423
- async fireWillResolveDebugConfiguration(debugType: string): Promise<void> {
424
- await WaitUntilEvent.fire(this.onWillResolveDebugConfigurationEmitter, { debugType });
425
- }
426
-
427
- protected async doStart(
428
- sessionId: string,
429
- options: DebugSessionOptions,
430
- extra: DebugSessionExtra,
431
- ): Promise<DebugSession | undefined> {
432
- const contrib = this.sessionContributionRegistry.get(options.configuration.type);
433
- if (!contrib) {
434
- return;
435
- }
436
- const sessionFactory = contrib.debugSessionFactory();
437
- const session = sessionFactory.get(sessionId, options);
438
- this._sessions.set(sessionId, session);
439
- this._extraMap.set(sessionId, extra);
440
-
441
- this.debugTypeKey.set(session.configuration.type);
442
- this.onDidCreateDebugSessionEmitter.fire(session);
443
-
444
- let state = DebugState.Inactive;
445
- session.onDidChange(() => {
446
- if (state !== session.state) {
447
- state = session.state;
448
- if (state === DebugState.Stopped) {
449
- this.onDidStopDebugSessionEmitter.fire(session);
450
- this.debugStopped.set(true);
451
- } else {
452
- this.debugStopped.set(false);
453
- }
454
- }
455
- this.debugContextKey.contextSetVariableSupported.set(session.capabilities.supportsSetVariable ?? false);
456
- this.debugContextKey.contextRestartFrameSupported.set(session.capabilities.supportsRestartFrame ?? false);
457
- this.debugContextKey.contextDebugState.set(DebugState[session.state] as keyof typeof DebugState);
458
- this.debugContextKey.contextInDdebugMode.set(state !== DebugState.Inactive);
459
- });
460
- session.on('terminated', (event) => {
461
- const restart = event.body && event.body.restart;
462
- if (restart) {
463
- this.doRestart(session, restart);
464
- } else {
465
- this.destroy(session.id);
466
- }
467
- });
468
- session.on('exited', () => this.destroy(session.id));
469
- session.start().then(() => this.onDidStartDebugSessionEmitter.fire(session));
470
- session.onDidCustomEvent(({ event, body }) =>
471
- this.onDidReceiveDebugSessionCustomEventEmitter.fire({ event, body, session }),
472
- );
473
-
474
- this.updateCurrentSession(session);
475
- return session;
476
- }
477
-
478
- protected isExistedDebugSession(options: DebugSessionOptions): boolean {
479
- const { name } = options.configuration;
480
- for (const [, session] of this._sessions) {
481
- if (session.configuration.name === name && !session.terminated) {
482
- return true;
483
- }
484
- }
485
- return false;
486
- }
487
-
488
- restart(): Promise<DebugSession | undefined>;
489
- restart(session: DebugSession): Promise<DebugSession>;
490
- async restart(session: DebugSession | undefined = this.currentSession): Promise<DebugSession | undefined> {
491
- return session && this.doRestart(session);
492
- }
493
- protected async doRestart(session: DebugSession, restart?: any): Promise<DebugSession | undefined> {
494
- if (await session.restart()) {
495
- return session;
496
- }
497
- await session.terminate(true);
498
- const { options, configuration } = session;
499
- configuration.__restart = restart;
500
- return this.start(options);
501
- }
502
- public updateCurrentSession(session: DebugSession | undefined) {
503
- this.currentSession = session || this.sessions[0];
504
- }
505
-
506
- get inDebugMode(): boolean {
507
- return this.state > DebugState.Inactive;
508
- }
509
-
510
- get currentThread(): DebugThread | undefined {
511
- const session = this.currentSession;
512
- return session && session.currentThread;
513
- }
514
-
515
- get state(): DebugState {
516
- const session = this.currentSession;
517
- return session ? session.state : DebugState.Inactive;
518
- }
519
-
520
- get currentFrame(): DebugStackFrame | undefined {
521
- const { currentThread } = this;
522
- return currentThread && currentThread.currentFrame;
523
- }
524
- get topFrame(): DebugStackFrame | undefined {
525
- const { currentThread } = this;
526
- return currentThread && currentThread.topFrame;
527
- }
528
-
529
- getSession(sessionId: string | undefined): DebugSession | undefined {
530
- if (sessionId) {
531
- return this._sessions.get(sessionId);
532
- }
533
- return undefined;
534
- }
535
-
536
- get sessions(): DebugSession[] {
537
- return Array.from(this._sessions.values()).filter((session) => session.state > DebugState.Inactive);
538
- }
539
-
540
- protected _currentSession: DebugSession | undefined;
541
- protected readonly toDisposeOnCurrentSession = new DisposableCollection();
542
- get currentSession(): DebugSession | undefined {
543
- return this._currentSession;
544
- }
545
- set currentSession(current: DebugSession | undefined) {
546
- if (this._currentSession === current) {
547
- return;
548
- }
549
- this.toDisposeOnCurrentSession.dispose();
550
- const previous = this._currentSession;
551
- this._currentSession = current;
552
- this.onDidChangeActiveDebugSessionEmitter.fire({ previous, current });
553
- if (current) {
554
- this.toDisposeOnCurrentSession.push(
555
- current.onDidChange(() => {
556
- if (this.currentFrame === this.topFrame) {
557
- this.open();
558
- }
559
- this.fireDidChange(current);
560
- }),
561
- );
562
- this.toDisposeOnCurrentSession.push(
563
- current.onCurrentThreadChange(() => {
564
- this.fireDidChange(current);
565
- }),
566
- );
567
- }
568
- this.open();
569
- this.fireDidChange(current);
570
- }
571
-
572
- open(): void {
573
- const { currentFrame } = this;
574
- if (currentFrame) {
575
- currentFrame.open();
576
- }
577
- }
578
-
579
- async stopSession(session: DebugSession | undefined, disconnect = false): Promise<any> {
580
- if (session) {
581
- return disconnect ? session.disconnect() : session.terminate();
582
- }
583
-
584
- return Promise.all(this.sessions.map((s) => (disconnect ? s.disconnect() : s.terminate())));
585
- }
586
-
587
- /**
588
- * 根据sessionId销毁进程
589
- * @param sessionId
590
- */
591
- destroy(sessionId?: string): void {
592
- if (sessionId) {
593
- const session = this._sessions.get(sessionId);
594
- if (session) {
595
- this.doDestroy(session);
596
- }
597
- } else {
598
- this._sessions.forEach((session) => this.doDestroy(session));
599
- }
600
- }
601
-
602
- private doDestroy(session: DebugSession): void {
603
- this.debug.terminateDebugSession(session.id);
604
-
605
- this.remove(session.id);
606
- session.dispose();
607
- this.onDidDestroyDebugSessionEmitter.fire(session);
608
- }
609
-
610
- protected remove(sessionId: string): void {
611
- this._sessions.delete(sessionId);
612
- const { currentSession } = this;
613
- if (currentSession && currentSession.id === sessionId) {
614
- this.updateCurrentSession(undefined);
615
- }
616
- // server 有可能会先返回一个 exited 事件,导致 destroy 先触发
617
- // 包一个 setTimeout 等埋点上报后再清理
618
- setTimeout(() => {
619
- this._extraMap.delete(sessionId);
620
- });
621
- }
622
- }