@theia/debug 1.45.0 → 1.46.0-next.72

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 (251) hide show
  1. package/README.md +62 -62
  2. package/lib/browser/breakpoint/breakpoint-manager.d.ts +70 -70
  3. package/lib/browser/breakpoint/breakpoint-manager.js +328 -328
  4. package/lib/browser/breakpoint/breakpoint-marker.d.ts +41 -41
  5. package/lib/browser/breakpoint/breakpoint-marker.js +87 -87
  6. package/lib/browser/console/debug-console-contribution.d.ts +40 -40
  7. package/lib/browser/console/debug-console-contribution.js +231 -231
  8. package/lib/browser/console/debug-console-items.d.ts +93 -93
  9. package/lib/browser/console/debug-console-items.js +319 -319
  10. package/lib/browser/console/debug-console-session.d.ts +31 -31
  11. package/lib/browser/console/debug-console-session.js +199 -199
  12. package/lib/browser/debug-call-stack-item-type-key.d.ts +3 -3
  13. package/lib/browser/debug-call-stack-item-type-key.js +19 -19
  14. package/lib/browser/debug-configuration-manager.d.ts +102 -102
  15. package/lib/browser/debug-configuration-manager.js +552 -552
  16. package/lib/browser/debug-configuration-model.d.ts +29 -29
  17. package/lib/browser/debug-configuration-model.js +79 -79
  18. package/lib/browser/debug-contribution.d.ts +22 -22
  19. package/lib/browser/debug-contribution.js +19 -19
  20. package/lib/browser/debug-frontend-application-contribution.d.ts +222 -222
  21. package/lib/browser/debug-frontend-application-contribution.js +1404 -1404
  22. package/lib/browser/debug-frontend-module.d.ts +4 -4
  23. package/lib/browser/debug-frontend-module.d.ts.map +1 -1
  24. package/lib/browser/debug-frontend-module.js +105 -104
  25. package/lib/browser/debug-frontend-module.js.map +1 -1
  26. package/lib/browser/debug-package.spec.js +18 -18
  27. package/lib/browser/debug-preferences.d.ts +17 -17
  28. package/lib/browser/debug-preferences.js +89 -89
  29. package/lib/browser/debug-prefix-configuration.d.ts +51 -51
  30. package/lib/browser/debug-prefix-configuration.js +208 -208
  31. package/lib/browser/debug-resource.d.ts +14 -14
  32. package/lib/browser/debug-resource.js +65 -65
  33. package/lib/browser/debug-schema-updater.d.ts +15 -15
  34. package/lib/browser/debug-schema-updater.js +168 -168
  35. package/lib/browser/debug-session-connection.d.ts +110 -110
  36. package/lib/browser/debug-session-connection.js +258 -258
  37. package/lib/browser/debug-session-contribution.d.ts +73 -73
  38. package/lib/browser/debug-session-contribution.js +145 -145
  39. package/lib/browser/debug-session-manager.d.ts +137 -137
  40. package/lib/browser/debug-session-manager.js +599 -599
  41. package/lib/browser/debug-session-manager.js.map +1 -1
  42. package/lib/browser/debug-session-options.d.ts +48 -48
  43. package/lib/browser/debug-session-options.js +85 -85
  44. package/lib/browser/debug-session.d.ts +178 -178
  45. package/lib/browser/debug-session.js +871 -871
  46. package/lib/browser/debug-tab-bar-decorator.d.ts +16 -16
  47. package/lib/browser/debug-tab-bar-decorator.js +70 -70
  48. package/lib/browser/debug-watch-manager.d.ts +21 -21
  49. package/lib/browser/debug-watch-manager.js +93 -93
  50. package/lib/browser/disassembly-view/disassembly-view-accessibility-provider.d.ts +6 -6
  51. package/lib/browser/disassembly-view/disassembly-view-accessibility-provider.js +38 -38
  52. package/lib/browser/disassembly-view/disassembly-view-breakpoint-renderer.d.ts +19 -19
  53. package/lib/browser/disassembly-view/disassembly-view-breakpoint-renderer.js +110 -110
  54. package/lib/browser/disassembly-view/disassembly-view-contribution.d.ts +24 -24
  55. package/lib/browser/disassembly-view/disassembly-view-contribution.js +131 -131
  56. package/lib/browser/disassembly-view/disassembly-view-instruction-renderer.d.ts +38 -38
  57. package/lib/browser/disassembly-view/disassembly-view-instruction-renderer.js +222 -222
  58. package/lib/browser/disassembly-view/disassembly-view-instruction-renderer.js.map +1 -1
  59. package/lib/browser/disassembly-view/disassembly-view-table-delegate.d.ts +15 -15
  60. package/lib/browser/disassembly-view/disassembly-view-table-delegate.js +38 -38
  61. package/lib/browser/disassembly-view/disassembly-view-utilities.d.ts +37 -37
  62. package/lib/browser/disassembly-view/disassembly-view-utilities.js +17 -17
  63. package/lib/browser/disassembly-view/disassembly-view-widget.d.ts +60 -60
  64. package/lib/browser/disassembly-view/disassembly-view-widget.js +453 -452
  65. package/lib/browser/disassembly-view/disassembly-view-widget.js.map +1 -1
  66. package/lib/browser/editor/debug-breakpoint-widget.d.ts +53 -53
  67. package/lib/browser/editor/debug-breakpoint-widget.js +261 -261
  68. package/lib/browser/editor/debug-editor-model.d.ts +91 -93
  69. package/lib/browser/editor/debug-editor-model.d.ts.map +1 -1
  70. package/lib/browser/editor/debug-editor-model.js +515 -516
  71. package/lib/browser/editor/debug-editor-model.js.map +1 -1
  72. package/lib/browser/editor/debug-editor-service.d.ts +35 -35
  73. package/lib/browser/editor/debug-editor-service.js +202 -202
  74. package/lib/browser/editor/debug-editor.d.ts +3 -3
  75. package/lib/browser/editor/debug-editor.js +19 -19
  76. package/lib/browser/editor/debug-exception-widget.d.ts +29 -29
  77. package/lib/browser/editor/debug-exception-widget.js +114 -114
  78. package/lib/browser/editor/debug-expression-provider.d.ts +11 -11
  79. package/lib/browser/editor/debug-expression-provider.js +81 -81
  80. package/lib/browser/editor/debug-hover-source.d.ts +18 -18
  81. package/lib/browser/editor/debug-hover-source.js +117 -117
  82. package/lib/browser/editor/debug-hover-widget.d.ts +47 -47
  83. package/lib/browser/editor/debug-hover-widget.js +276 -276
  84. package/lib/browser/editor/debug-inline-value-decorator.d.ts +19 -21
  85. package/lib/browser/editor/debug-inline-value-decorator.d.ts.map +1 -1
  86. package/lib/browser/editor/debug-inline-value-decorator.js +333 -337
  87. package/lib/browser/editor/debug-inline-value-decorator.js.map +1 -1
  88. package/lib/browser/model/debug-breakpoint.d.ts +47 -47
  89. package/lib/browser/model/debug-breakpoint.js +109 -109
  90. package/lib/browser/model/debug-function-breakpoint.d.ts +18 -18
  91. package/lib/browser/model/debug-function-breakpoint.js +92 -92
  92. package/lib/browser/model/debug-instruction-breakpoint.d.ts +14 -14
  93. package/lib/browser/model/debug-instruction-breakpoint.js +65 -65
  94. package/lib/browser/model/debug-source-breakpoint.d.ts +37 -37
  95. package/lib/browser/model/debug-source-breakpoint.js +217 -217
  96. package/lib/browser/model/debug-source.d.ts +24 -24
  97. package/lib/browser/model/debug-source.js +80 -80
  98. package/lib/browser/model/debug-stack-frame.d.ts +41 -41
  99. package/lib/browser/model/debug-stack-frame.js +150 -150
  100. package/lib/browser/model/debug-thread.d.ts +62 -62
  101. package/lib/browser/model/debug-thread.js +237 -237
  102. package/lib/browser/preferences/launch-preferences.d.ts +4 -4
  103. package/lib/browser/preferences/launch-preferences.js +38 -38
  104. package/lib/browser/view/debug-action.d.ts +16 -16
  105. package/lib/browser/view/debug-action.js +43 -43
  106. package/lib/browser/view/debug-breakpoints-source.d.ts +9 -9
  107. package/lib/browser/view/debug-breakpoints-source.js +70 -70
  108. package/lib/browser/view/debug-breakpoints-widget.d.ts +22 -22
  109. package/lib/browser/view/debug-breakpoints-widget.js +87 -87
  110. package/lib/browser/view/debug-configuration-select.d.ts +64 -64
  111. package/lib/browser/view/debug-configuration-select.js +216 -216
  112. package/lib/browser/view/debug-configuration-widget.d.ts +30 -30
  113. package/lib/browser/view/debug-configuration-widget.js +135 -135
  114. package/lib/browser/view/debug-exception-breakpoint.d.ts +14 -14
  115. package/lib/browser/view/debug-exception-breakpoint.js +61 -61
  116. package/lib/browser/view/debug-session-widget.d.ts +28 -28
  117. package/lib/browser/view/debug-session-widget.js +134 -134
  118. package/lib/browser/view/debug-stack-frames-source.d.ts +17 -17
  119. package/lib/browser/view/debug-stack-frames-source.js +89 -89
  120. package/lib/browser/view/debug-stack-frames-widget.d.ts +24 -24
  121. package/lib/browser/view/debug-stack-frames-widget.js +154 -154
  122. package/lib/browser/view/debug-threads-source.d.ts +8 -8
  123. package/lib/browser/view/debug-threads-source.js +63 -63
  124. package/lib/browser/view/debug-threads-widget.d.ts +26 -26
  125. package/lib/browser/view/debug-threads-widget.js +145 -145
  126. package/lib/browser/view/debug-toolbar-widget.d.ts +34 -34
  127. package/lib/browser/view/debug-toolbar-widget.js +156 -156
  128. package/lib/browser/view/debug-variables-source.d.ts +9 -9
  129. package/lib/browser/view/debug-variables-source.js +60 -60
  130. package/lib/browser/view/debug-variables-widget.d.ts +16 -16
  131. package/lib/browser/view/debug-variables-widget.js +78 -78
  132. package/lib/browser/view/debug-view-model.d.ts +51 -51
  133. package/lib/browser/view/debug-view-model.js +220 -220
  134. package/lib/browser/view/debug-watch-expression.d.ts +30 -30
  135. package/lib/browser/view/debug-watch-expression.js +73 -73
  136. package/lib/browser/view/debug-watch-source.d.ts +9 -9
  137. package/lib/browser/view/debug-watch-source.js +58 -58
  138. package/lib/browser/view/debug-watch-widget.d.ts +16 -16
  139. package/lib/browser/view/debug-watch-widget.js +78 -78
  140. package/lib/browser/view/debug-widget.d.ts +23 -23
  141. package/lib/browser/view/debug-widget.js +108 -108
  142. package/lib/common/debug-adapter-contribution-registry.d.ts +59 -59
  143. package/lib/common/debug-adapter-contribution-registry.js +212 -212
  144. package/lib/common/debug-adapter-session.d.ts +18 -18
  145. package/lib/common/debug-adapter-session.js +78 -78
  146. package/lib/common/debug-common.d.ts +1 -1
  147. package/lib/common/debug-common.js +29 -29
  148. package/lib/common/debug-compound.d.ts +14 -14
  149. package/lib/common/debug-compound.js +27 -27
  150. package/lib/common/debug-configuration.d.ts +70 -70
  151. package/lib/common/debug-configuration.js +31 -31
  152. package/lib/common/debug-model.d.ts +152 -152
  153. package/lib/common/debug-model.js +35 -35
  154. package/lib/common/debug-service.d.ts +123 -123
  155. package/lib/common/debug-service.js +66 -66
  156. package/lib/common/debug-uri-utils.d.ts +23 -23
  157. package/lib/common/debug-uri-utils.js +26 -26
  158. package/lib/common/inline-debug-adapter.d.ts +18 -18
  159. package/lib/common/inline-debug-adapter.js +44 -44
  160. package/lib/node/debug-adapter-factory.d.ts +19 -19
  161. package/lib/node/debug-adapter-factory.js +96 -96
  162. package/lib/node/debug-adapter-session-manager.d.ts +37 -37
  163. package/lib/node/debug-adapter-session-manager.js +111 -111
  164. package/lib/node/debug-backend-module.d.ts +3 -3
  165. package/lib/node/debug-backend-module.js +41 -41
  166. package/lib/node/debug-service-impl.d.ts +30 -30
  167. package/lib/node/debug-service-impl.js +124 -124
  168. package/lib/node/stream-debug-adapter.d.ts +36 -36
  169. package/lib/node/stream-debug-adapter.js +112 -112
  170. package/package.json +16 -16
  171. package/src/browser/breakpoint/breakpoint-manager.ts +369 -369
  172. package/src/browser/breakpoint/breakpoint-marker.ts +104 -104
  173. package/src/browser/console/debug-console-contribution.tsx +240 -240
  174. package/src/browser/console/debug-console-items.tsx +384 -384
  175. package/src/browser/console/debug-console-session.ts +205 -205
  176. package/src/browser/debug-call-stack-item-type-key.ts +20 -20
  177. package/src/browser/debug-configuration-manager.ts +591 -591
  178. package/src/browser/debug-configuration-model.ts +100 -100
  179. package/src/browser/debug-contribution.ts +43 -43
  180. package/src/browser/debug-frontend-application-contribution.ts +1551 -1551
  181. package/src/browser/debug-frontend-module.ts +133 -132
  182. package/src/browser/debug-package.spec.ts +20 -20
  183. package/src/browser/debug-preferences.ts +98 -98
  184. package/src/browser/debug-prefix-configuration.ts +195 -195
  185. package/src/browser/debug-resource.ts +59 -59
  186. package/src/browser/debug-schema-updater.ts +149 -149
  187. package/src/browser/debug-session-connection.ts +357 -357
  188. package/src/browser/debug-session-contribution.ts +150 -150
  189. package/src/browser/debug-session-manager.ts +682 -682
  190. package/src/browser/debug-session-options.ts +114 -114
  191. package/src/browser/debug-session.tsx +947 -947
  192. package/src/browser/debug-tab-bar-decorator.ts +57 -57
  193. package/src/browser/debug-watch-manager.ts +93 -93
  194. package/src/browser/disassembly-view/disassembly-view-accessibility-provider.ts +43 -43
  195. package/src/browser/disassembly-view/disassembly-view-breakpoint-renderer.ts +119 -119
  196. package/src/browser/disassembly-view/disassembly-view-contribution.ts +109 -109
  197. package/src/browser/disassembly-view/disassembly-view-instruction-renderer.ts +245 -245
  198. package/src/browser/disassembly-view/disassembly-view-table-delegate.ts +39 -39
  199. package/src/browser/disassembly-view/disassembly-view-utilities.ts +55 -55
  200. package/src/browser/disassembly-view/disassembly-view-widget.ts +463 -463
  201. package/src/browser/editor/debug-breakpoint-widget.tsx +293 -293
  202. package/src/browser/editor/debug-editor-model.ts +529 -528
  203. package/src/browser/editor/debug-editor-service.ts +192 -192
  204. package/src/browser/editor/debug-editor.ts +20 -20
  205. package/src/browser/editor/debug-exception-widget.tsx +122 -122
  206. package/src/browser/editor/debug-expression-provider.ts +78 -78
  207. package/src/browser/editor/debug-hover-source.tsx +105 -105
  208. package/src/browser/editor/debug-hover-widget.ts +298 -298
  209. package/src/browser/editor/debug-inline-value-decorator.ts +373 -377
  210. package/src/browser/model/debug-breakpoint.tsx +151 -151
  211. package/src/browser/model/debug-function-breakpoint.tsx +101 -101
  212. package/src/browser/model/debug-instruction-breakpoint.tsx +68 -68
  213. package/src/browser/model/debug-source-breakpoint.tsx +237 -237
  214. package/src/browser/model/debug-source.ts +93 -93
  215. package/src/browser/model/debug-stack-frame.tsx +170 -170
  216. package/src/browser/model/debug-thread.tsx +285 -285
  217. package/src/browser/preferences/launch-preferences.ts +38 -38
  218. package/src/browser/style/index.css +453 -453
  219. package/src/browser/view/debug-action.tsx +57 -57
  220. package/src/browser/view/debug-breakpoints-source.tsx +53 -53
  221. package/src/browser/view/debug-breakpoints-widget.ts +71 -71
  222. package/src/browser/view/debug-configuration-select.tsx +269 -269
  223. package/src/browser/view/debug-configuration-widget.tsx +121 -121
  224. package/src/browser/view/debug-exception-breakpoint.tsx +68 -68
  225. package/src/browser/view/debug-session-widget.ts +124 -124
  226. package/src/browser/view/debug-stack-frames-source.tsx +75 -75
  227. package/src/browser/view/debug-stack-frames-widget.ts +135 -135
  228. package/src/browser/view/debug-threads-source.tsx +48 -48
  229. package/src/browser/view/debug-threads-widget.ts +125 -125
  230. package/src/browser/view/debug-toolbar-widget.tsx +145 -145
  231. package/src/browser/view/debug-variables-source.ts +43 -43
  232. package/src/browser/view/debug-variables-widget.ts +61 -61
  233. package/src/browser/view/debug-view-model.ts +230 -230
  234. package/src/browser/view/debug-watch-expression.tsx +88 -88
  235. package/src/browser/view/debug-watch-source.ts +41 -41
  236. package/src/browser/view/debug-watch-widget.ts +61 -61
  237. package/src/browser/view/debug-widget.ts +97 -97
  238. package/src/common/debug-adapter-contribution-registry.ts +206 -206
  239. package/src/common/debug-adapter-session.ts +102 -102
  240. package/src/common/debug-common.ts +19 -19
  241. package/src/common/debug-compound.ts +33 -33
  242. package/src/common/debug-configuration.ts +108 -108
  243. package/src/common/debug-model.ts +200 -200
  244. package/src/common/debug-service.ts +184 -184
  245. package/src/common/debug-uri-utils.ts +24 -24
  246. package/src/common/inline-debug-adapter.ts +47 -47
  247. package/src/node/debug-adapter-factory.ts +107 -107
  248. package/src/node/debug-adapter-session-manager.ts +106 -106
  249. package/src/node/debug-backend-module.ts +57 -57
  250. package/src/node/debug-service-impl.ts +119 -119
  251. package/src/node/stream-debug-adapter.ts +126 -126
@@ -1,682 +1,682 @@
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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { DisposableCollection, Emitter, Event, MessageService, nls, ProgressService, WaitUntilEvent } from '@theia/core';
18
- import { LabelProvider, ApplicationShell } from '@theia/core/lib/browser';
19
- import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-key-service';
20
- import URI from '@theia/core/lib/common/uri';
21
- import { EditorManager } from '@theia/editor/lib/browser';
22
- import { QuickOpenTask } from '@theia/task/lib/browser/quick-open-task';
23
- import { TaskService, TaskEndedInfo, TaskEndedTypes } from '@theia/task/lib/browser/task-service';
24
- import { VariableResolverService } from '@theia/variable-resolver/lib/browser';
25
- import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
26
- import { DebugConfiguration } from '../common/debug-common';
27
- import { DebugError, DebugService } from '../common/debug-service';
28
- import { BreakpointManager } from './breakpoint/breakpoint-manager';
29
- import { DebugConfigurationManager } from './debug-configuration-manager';
30
- import { DebugSession, DebugState, debugStateContextValue } from './debug-session';
31
- import { DebugSessionContributionRegistry, DebugSessionFactory } from './debug-session-contribution';
32
- import { DebugCompoundRoot, DebugCompoundSessionOptions, DebugConfigurationSessionOptions, DebugSessionOptions, InternalDebugSessionOptions } from './debug-session-options';
33
- import { DebugStackFrame } from './model/debug-stack-frame';
34
- import { DebugThread } from './model/debug-thread';
35
- import { TaskIdentifier } from '@theia/task/lib/common';
36
- import { DebugSourceBreakpoint } from './model/debug-source-breakpoint';
37
- import { DebugFunctionBreakpoint } from './model/debug-function-breakpoint';
38
- import * as monaco from '@theia/monaco-editor-core';
39
- import { DebugInstructionBreakpoint } from './model/debug-instruction-breakpoint';
40
-
41
- export interface WillStartDebugSession extends WaitUntilEvent {
42
- }
43
-
44
- export interface WillResolveDebugConfiguration extends WaitUntilEvent {
45
- debugType: string
46
- }
47
-
48
- export interface DidChangeActiveDebugSession {
49
- previous: DebugSession | undefined
50
- current: DebugSession | undefined
51
- }
52
-
53
- export interface DidChangeBreakpointsEvent {
54
- session?: DebugSession
55
- uri: URI
56
- }
57
-
58
- export interface DidFocusStackFrameEvent {
59
- session: DebugSession;
60
- frame: DebugStackFrame | undefined;
61
- }
62
-
63
- export interface DebugSessionCustomEvent {
64
- readonly body?: any // eslint-disable-line @typescript-eslint/no-explicit-any
65
- readonly event: string
66
- readonly session: DebugSession
67
- }
68
-
69
- @injectable()
70
- export class DebugSessionManager {
71
- protected readonly _sessions = new Map<string, DebugSession>();
72
-
73
- protected readonly onWillStartDebugSessionEmitter = new Emitter<WillStartDebugSession>();
74
- readonly onWillStartDebugSession: Event<WillStartDebugSession> = this.onWillStartDebugSessionEmitter.event;
75
-
76
- protected readonly onWillResolveDebugConfigurationEmitter = new Emitter<WillResolveDebugConfiguration>();
77
- readonly onWillResolveDebugConfiguration: Event<WillResolveDebugConfiguration> = this.onWillResolveDebugConfigurationEmitter.event;
78
-
79
- protected readonly onDidCreateDebugSessionEmitter = new Emitter<DebugSession>();
80
- readonly onDidCreateDebugSession: Event<DebugSession> = this.onDidCreateDebugSessionEmitter.event;
81
-
82
- protected readonly onDidStartDebugSessionEmitter = new Emitter<DebugSession>();
83
- readonly onDidStartDebugSession: Event<DebugSession> = this.onDidStartDebugSessionEmitter.event;
84
-
85
- protected readonly onDidStopDebugSessionEmitter = new Emitter<DebugSession>();
86
- readonly onDidStopDebugSession: Event<DebugSession> = this.onDidStopDebugSessionEmitter.event;
87
-
88
- protected readonly onDidChangeActiveDebugSessionEmitter = new Emitter<DidChangeActiveDebugSession>();
89
- readonly onDidChangeActiveDebugSession: Event<DidChangeActiveDebugSession> = this.onDidChangeActiveDebugSessionEmitter.event;
90
-
91
- protected readonly onDidDestroyDebugSessionEmitter = new Emitter<DebugSession>();
92
- readonly onDidDestroyDebugSession: Event<DebugSession> = this.onDidDestroyDebugSessionEmitter.event;
93
-
94
- protected readonly onDidReceiveDebugSessionCustomEventEmitter = new Emitter<DebugSessionCustomEvent>();
95
- readonly onDidReceiveDebugSessionCustomEvent: Event<DebugSessionCustomEvent> = this.onDidReceiveDebugSessionCustomEventEmitter.event;
96
-
97
- protected readonly onDidFocusStackFrameEmitter = new Emitter<DidFocusStackFrameEvent>();
98
- readonly onDidFocusStackFrame = this.onDidFocusStackFrameEmitter.event;
99
-
100
- protected readonly onDidChangeBreakpointsEmitter = new Emitter<DidChangeBreakpointsEvent>();
101
- readonly onDidChangeBreakpoints = this.onDidChangeBreakpointsEmitter.event;
102
- protected fireDidChangeBreakpoints(event: DidChangeBreakpointsEvent): void {
103
- this.onDidChangeBreakpointsEmitter.fire(event);
104
- }
105
-
106
- protected readonly onDidChangeEmitter = new Emitter<DebugSession | undefined>();
107
- readonly onDidChange: Event<DebugSession | undefined> = this.onDidChangeEmitter.event;
108
- protected fireDidChange(current: DebugSession | undefined): void {
109
- this.debugTypeKey.set(current?.configuration.type);
110
- this.inDebugModeKey.set(this.inDebugMode);
111
- this.debugStateKey.set(debugStateContextValue(this.state));
112
- this.onDidChangeEmitter.fire(current);
113
- }
114
-
115
- @inject(DebugSessionFactory)
116
- protected readonly debugSessionFactory: DebugSessionFactory;
117
-
118
- @inject(DebugService)
119
- protected readonly debug: DebugService;
120
-
121
- @inject(LabelProvider)
122
- protected readonly labelProvider: LabelProvider;
123
-
124
- @inject(EditorManager)
125
- protected readonly editorManager: EditorManager;
126
-
127
- @inject(BreakpointManager)
128
- protected readonly breakpoints: BreakpointManager;
129
-
130
- @inject(VariableResolverService)
131
- protected readonly variableResolver: VariableResolverService;
132
-
133
- @inject(DebugSessionContributionRegistry)
134
- protected readonly sessionContributionRegistry: DebugSessionContributionRegistry;
135
-
136
- @inject(MessageService)
137
- protected readonly messageService: MessageService;
138
-
139
- @inject(ProgressService)
140
- protected readonly progressService: ProgressService;
141
-
142
- @inject(ContextKeyService)
143
- protected readonly contextKeyService: ContextKeyService;
144
-
145
- @inject(TaskService)
146
- protected readonly taskService: TaskService;
147
-
148
- @inject(DebugConfigurationManager)
149
- protected readonly debugConfigurationManager: DebugConfigurationManager;
150
-
151
- @inject(QuickOpenTask)
152
- protected readonly quickOpenTask: QuickOpenTask;
153
-
154
- @inject(ApplicationShell)
155
- protected readonly shell: ApplicationShell;
156
-
157
- protected debugTypeKey: ContextKey<string>;
158
- protected inDebugModeKey: ContextKey<boolean>;
159
- protected debugStateKey: ContextKey<string>;
160
-
161
- @postConstruct()
162
- protected init(): void {
163
- this.debugTypeKey = this.contextKeyService.createKey<string>('debugType', undefined);
164
- this.inDebugModeKey = this.contextKeyService.createKey<boolean>('inDebugMode', this.inDebugMode);
165
- this.debugStateKey = this.contextKeyService.createKey<string>('debugState', debugStateContextValue(this.state));
166
- this.breakpoints.onDidChangeMarkers(uri => this.fireDidChangeBreakpoints({ uri }));
167
- this.labelProvider.onDidChange(event => {
168
- for (const uriString of this.breakpoints.getUris()) {
169
- const uri = new URI(uriString);
170
- if (event.affects(uri)) {
171
- this.fireDidChangeBreakpoints({ uri });
172
- }
173
- }
174
- });
175
- }
176
-
177
- get inDebugMode(): boolean {
178
- return this.state > DebugState.Inactive;
179
- }
180
-
181
- isCurrentEditorFrame(uri: URI | string | monaco.Uri): boolean {
182
- return this.currentFrame?.source?.uri.toString() === (uri instanceof URI ? uri : new URI(uri)).toString();
183
- }
184
-
185
- protected async saveAll(): Promise<boolean> {
186
- if (!this.shell.canSaveAll()) {
187
- return true; // Nothing to save.
188
- }
189
- try {
190
- await this.shell.saveAll();
191
- return true;
192
- } catch (error) {
193
- console.error('saveAll failed:', error);
194
- return false;
195
- }
196
- }
197
-
198
- async start(options: DebugCompoundSessionOptions): Promise<boolean | undefined>;
199
- async start(options: DebugConfigurationSessionOptions): Promise<DebugSession | undefined>;
200
- async start(options: DebugSessionOptions): Promise<DebugSession | boolean | undefined>;
201
- async start(name: string): Promise<DebugSession | boolean | undefined>;
202
- async start(optionsOrName: DebugSessionOptions | string): Promise<DebugSession | boolean | undefined> {
203
- if (typeof optionsOrName === 'string') {
204
- const options = this.debugConfigurationManager.find(optionsOrName);
205
- return !!options && this.start(options);
206
- }
207
- return optionsOrName.configuration ? this.startConfiguration(optionsOrName) : this.startCompound(optionsOrName);
208
- }
209
-
210
- protected async startConfiguration(options: DebugConfigurationSessionOptions): Promise<DebugSession | undefined> {
211
- return this.progressService.withProgress('Start...', 'debug', async () => {
212
- try {
213
- // If a parent session is available saving should be handled by the parent
214
- if (!options.configuration.parentSessionId && !options.configuration.suppressSaveBeforeStart && !await this.saveAll()) {
215
- return undefined;
216
- }
217
- await this.fireWillStartDebugSession();
218
- const resolved = await this.resolveConfiguration(options);
219
-
220
- if (!resolved || !resolved.configuration) {
221
- // As per vscode API: https://code.visualstudio.com/api/references/vscode-api#DebugConfigurationProvider
222
- // "Returning the value 'undefined' prevents the debug session from starting.
223
- // Returning the value 'null' prevents the debug session from starting and opens the
224
- // underlying debug configuration instead."
225
-
226
- // eslint-disable-next-line no-null/no-null
227
- if (resolved === null) {
228
- this.debugConfigurationManager.openConfiguration();
229
- }
230
- return undefined;
231
- }
232
-
233
- // preLaunchTask isn't run in case of auto restart as well as postDebugTask
234
- if (!options.configuration.__restart) {
235
- const taskRun = await this.runTask(options.workspaceFolderUri, resolved.configuration.preLaunchTask, true);
236
- if (!taskRun) {
237
- return undefined;
238
- }
239
- }
240
-
241
- const sessionId = await this.debug.createDebugSession(resolved.configuration, options.workspaceFolderUri);
242
- return this.doStart(sessionId, resolved);
243
- } catch (e) {
244
- if (DebugError.NotFound.is(e)) {
245
- this.messageService.error(`The debug session type "${e.data.type}" is not supported.`);
246
- return undefined;
247
- }
248
-
249
- this.messageService.error('There was an error starting the debug session, check the logs for more details.');
250
- console.error('Error starting the debug session', e);
251
- throw e;
252
- }
253
- });
254
- }
255
-
256
- protected async startCompound(options: DebugCompoundSessionOptions): Promise<boolean | undefined> {
257
- let configurations: DebugConfigurationSessionOptions[] = [];
258
- const compoundRoot = options.compound.stopAll ? new DebugCompoundRoot() : undefined;
259
- try {
260
- configurations = this.getCompoundConfigurations(options, compoundRoot);
261
- } catch (error) {
262
- this.messageService.error(error.message);
263
- return;
264
- }
265
-
266
- if (options.compound.preLaunchTask) {
267
- const taskRun = await this.runTask(options.workspaceFolderUri, options.compound.preLaunchTask, true);
268
- if (!taskRun) {
269
- return undefined;
270
- }
271
- }
272
-
273
- // Compound launch is a success only if each configuration launched successfully
274
- const values = await Promise.all(configurations.map(async configuration => {
275
- const newSession = await this.startConfiguration(configuration);
276
- if (newSession) {
277
- compoundRoot?.onDidSessionStop(() => newSession.stop(false, () => this.debug.terminateDebugSession(newSession.id)));
278
- }
279
- return newSession;
280
- }));
281
- const result = values.every(success => !!success);
282
- return result;
283
- }
284
-
285
- protected getCompoundConfigurations(options: DebugCompoundSessionOptions, compoundRoot: DebugCompoundRoot | undefined): DebugConfigurationSessionOptions[] {
286
- const compound = options.compound;
287
- if (!compound.configurations) {
288
- throw new Error(nls.localizeByDefault('Compound must have "configurations" attribute set in order to start multiple configurations.'));
289
- }
290
-
291
- const configurations: DebugConfigurationSessionOptions[] = [];
292
-
293
- for (const configData of compound.configurations) {
294
- const name = typeof configData === 'string' ? configData : configData.name;
295
- if (name === compound.name) {
296
- throw new Error(nls.localize('theia/debug/compound-cycle', "Launch configuration '{0}' contains a cycle with itself", name));
297
- }
298
-
299
- const workspaceFolderUri = typeof configData === 'string' ? options.workspaceFolderUri : configData.folder;
300
- const matchingOptions = [...this.debugConfigurationManager.all]
301
- .filter(option => option.name === name && !!option.configuration && option.workspaceFolderUri === workspaceFolderUri);
302
- if (matchingOptions.length === 1) {
303
- const match = matchingOptions[0];
304
- if (DebugSessionOptions.isConfiguration(match)) {
305
- configurations.push({ ...match, compoundRoot, configuration: { ...match.configuration, noDebug: options.noDebug } });
306
- } else {
307
- throw new Error(nls.localizeByDefault("Could not find launch configuration '{0}' in the workspace.", name));
308
- }
309
- } else {
310
- throw new Error(matchingOptions.length === 0
311
- ? workspaceFolderUri
312
- ? nls.localizeByDefault("Can not find folder with name '{0}' for configuration '{1}' in compound '{2}'.", workspaceFolderUri, name, compound.name)
313
- : nls.localizeByDefault("Could not find launch configuration '{0}' in the workspace.", name)
314
- : nls.localizeByDefault("There are multiple launch configurations '{0}' in the workspace. Use folder name to qualify the configuration.", name));
315
- }
316
- }
317
- return configurations;
318
- }
319
-
320
- protected async fireWillStartDebugSession(): Promise<void> {
321
- await WaitUntilEvent.fire(this.onWillStartDebugSessionEmitter, {});
322
- }
323
-
324
- protected configurationIds = new Map<string, number>();
325
- protected async resolveConfiguration(
326
- options: Readonly<DebugConfigurationSessionOptions>
327
- ): Promise<InternalDebugSessionOptions | undefined | null> {
328
- if (InternalDebugSessionOptions.is(options)) {
329
- return options;
330
- }
331
- const { workspaceFolderUri } = options;
332
- let configuration = await this.resolveDebugConfiguration(options.configuration, workspaceFolderUri);
333
-
334
- if (configuration) {
335
- // Resolve command variables provided by the debugger
336
- const commandIdVariables = await this.debug.provideDebuggerVariables(configuration.type);
337
- configuration = await this.variableResolver.resolve(configuration, {
338
- context: options.workspaceFolderUri ? new URI(options.workspaceFolderUri) : undefined,
339
- configurationSection: 'launch',
340
- commandIdVariables,
341
- configuration
342
- });
343
-
344
- if (configuration) {
345
- configuration = await this.resolveDebugConfigurationWithSubstitutedVariables(
346
- configuration,
347
- workspaceFolderUri
348
- );
349
- }
350
- }
351
-
352
- if (!configuration) {
353
- return configuration;
354
- }
355
-
356
- const key = configuration.name + workspaceFolderUri;
357
- const id = this.configurationIds.has(key) ? this.configurationIds.get(key)! + 1 : 0;
358
- this.configurationIds.set(key, id);
359
-
360
- return {
361
- id,
362
- ...options,
363
- name: configuration.name,
364
- configuration
365
- };
366
- }
367
-
368
- protected async resolveDebugConfiguration(
369
- configuration: DebugConfiguration,
370
- workspaceFolderUri: string | undefined
371
- ): Promise<DebugConfiguration | undefined | null> {
372
- await this.fireWillResolveDebugConfiguration(configuration.type);
373
- return this.debug.resolveDebugConfiguration(configuration, workspaceFolderUri);
374
- }
375
-
376
- protected async fireWillResolveDebugConfiguration(debugType: string): Promise<void> {
377
- await WaitUntilEvent.fire(this.onWillResolveDebugConfigurationEmitter, { debugType });
378
- }
379
-
380
- protected async resolveDebugConfigurationWithSubstitutedVariables(
381
- configuration: DebugConfiguration,
382
- workspaceFolderUri: string | undefined
383
- ): Promise<DebugConfiguration | undefined | null> {
384
- return this.debug.resolveDebugConfigurationWithSubstitutedVariables(configuration, workspaceFolderUri);
385
- }
386
-
387
- protected async doStart(sessionId: string, options: DebugConfigurationSessionOptions): Promise<DebugSession> {
388
- const parentSession = options.configuration.parentSessionId ? this._sessions.get(options.configuration.parentSessionId) : undefined;
389
- const contrib = this.sessionContributionRegistry.get(options.configuration.type);
390
- const sessionFactory = contrib ? contrib.debugSessionFactory() : this.debugSessionFactory;
391
- const session = sessionFactory.get(sessionId, options, parentSession);
392
- this._sessions.set(sessionId, session);
393
-
394
- this.debugTypeKey.set(session.configuration.type);
395
- this.onDidCreateDebugSessionEmitter.fire(session);
396
-
397
- let state = DebugState.Inactive;
398
- session.onDidChange(() => {
399
- if (state !== session.state) {
400
- state = session.state;
401
- if (state === DebugState.Stopped) {
402
- this.onDidStopDebugSessionEmitter.fire(session);
403
- }
404
- }
405
- this.updateCurrentSession(session);
406
- });
407
- session.onDidChangeBreakpoints(uri => this.fireDidChangeBreakpoints({ session, uri }));
408
- session.on('terminated', async event => {
409
- const restart = event.body && event.body.restart;
410
- if (restart) {
411
- // postDebugTask isn't run in case of auto restart as well as preLaunchTask
412
- this.doRestart(session, !!restart);
413
- } else {
414
- await session.disconnect(false, () => this.debug.terminateDebugSession(session.id));
415
- await this.runTask(session.options.workspaceFolderUri, session.configuration.postDebugTask);
416
- }
417
- });
418
-
419
- session.on('exited', async event => {
420
- await session.disconnect(false, () => this.debug.terminateDebugSession(session.id));
421
- });
422
-
423
- session.onDispose(() => this.cleanup(session));
424
- session.start().then(() => this.onDidStartDebugSessionEmitter.fire(session)).catch(e => {
425
- session.stop(false, () => {
426
- this.debug.terminateDebugSession(session.id);
427
- });
428
- });
429
- session.onDidCustomEvent(({ event, body }) =>
430
- this.onDidReceiveDebugSessionCustomEventEmitter.fire({ event, body, session })
431
- );
432
- return session;
433
- }
434
-
435
- protected cleanup(session: DebugSession): void {
436
- if (this.remove(session.id)) {
437
- this.onDidDestroyDebugSessionEmitter.fire(session);
438
- }
439
- }
440
-
441
- protected async doRestart(session: DebugSession, isRestart: boolean): Promise<DebugSession | undefined> {
442
- if (session.canRestart()) {
443
- await session.restart();
444
- return session;
445
- }
446
-
447
- const { options, configuration } = session;
448
- session.stop(isRestart, () => this.debug.terminateDebugSession(session.id));
449
- configuration.__restart = isRestart;
450
- return this.start(options);
451
- }
452
-
453
- async terminateSession(session?: DebugSession): Promise<void> {
454
- if (!session) {
455
- this.updateCurrentSession(this._currentSession);
456
- session = this._currentSession;
457
- }
458
- if (session) {
459
- if (session.options.compoundRoot) {
460
- session.options.compoundRoot.stopSession();
461
- } else if (session.parentSession && session.configuration.lifecycleManagedByParent) {
462
- this.terminateSession(session.parentSession);
463
- } else {
464
- session.stop(false, () => this.debug.terminateDebugSession(session!.id));
465
- }
466
- }
467
- }
468
-
469
- async restartSession(session?: DebugSession): Promise<DebugSession | undefined> {
470
- if (!session) {
471
- this.updateCurrentSession(this._currentSession);
472
- session = this._currentSession;
473
- }
474
-
475
- if (session) {
476
- if (session.parentSession && session.configuration.lifecycleManagedByParent) {
477
- return this.restartSession(session.parentSession);
478
- } else {
479
- return this.doRestart(session, true);
480
- }
481
- }
482
- }
483
-
484
- protected remove(sessionId: string): boolean {
485
- const existed = this._sessions.delete(sessionId);
486
- const { currentSession } = this;
487
- if (currentSession && currentSession.id === sessionId) {
488
- this.updateCurrentSession(undefined);
489
- }
490
- return existed;
491
- }
492
-
493
- getSession(sessionId: string): DebugSession | undefined {
494
- return this._sessions.get(sessionId);
495
- }
496
-
497
- get sessions(): DebugSession[] {
498
- return Array.from(this._sessions.values()).filter(session => session.state > DebugState.Inactive);
499
- }
500
-
501
- protected _currentSession: DebugSession | undefined;
502
- protected readonly disposeOnCurrentSessionChanged = new DisposableCollection();
503
- get currentSession(): DebugSession | undefined {
504
- return this._currentSession;
505
- }
506
- set currentSession(current: DebugSession | undefined) {
507
- if (this._currentSession === current) {
508
- return;
509
- }
510
- this.disposeOnCurrentSessionChanged.dispose();
511
- const previous = this.currentSession;
512
- this._currentSession = current;
513
- this.onDidChangeActiveDebugSessionEmitter.fire({ previous, current });
514
- if (current) {
515
- this.disposeOnCurrentSessionChanged.push(current.onDidChange(() => {
516
- if (this.currentFrame === this.topFrame) {
517
- this.open();
518
- }
519
- this.fireDidChange(current);
520
- }));
521
- this.disposeOnCurrentSessionChanged.push(current.onDidFocusStackFrame(frame => this.onDidFocusStackFrameEmitter.fire({ session: current, frame })));
522
- }
523
- this.updateBreakpoints(previous, current);
524
- this.open();
525
- this.fireDidChange(current);
526
- }
527
- open(): void {
528
- const { currentFrame } = this;
529
- if (currentFrame) {
530
- currentFrame.open();
531
- }
532
- }
533
- protected updateBreakpoints(previous: DebugSession | undefined, current: DebugSession | undefined): void {
534
- const affectedUri = new Set();
535
- for (const session of [previous, current]) {
536
- if (session) {
537
- for (const uriString of session.breakpointUris) {
538
- if (!affectedUri.has(uriString)) {
539
- affectedUri.add(uriString);
540
- this.fireDidChangeBreakpoints({
541
- session: current,
542
- uri: new URI(uriString)
543
- });
544
- }
545
- }
546
- }
547
- }
548
- }
549
- protected updateCurrentSession(session: DebugSession | undefined): void {
550
- this.currentSession = session || this.sessions[0];
551
- }
552
-
553
- get currentThread(): DebugThread | undefined {
554
- const session = this.currentSession;
555
- return session && session.currentThread;
556
- }
557
-
558
- get state(): DebugState {
559
- const session = this.currentSession;
560
- return session ? session.state : DebugState.Inactive;
561
- }
562
-
563
- get currentFrame(): DebugStackFrame | undefined {
564
- const { currentThread } = this;
565
- return currentThread && currentThread.currentFrame;
566
- }
567
- get topFrame(): DebugStackFrame | undefined {
568
- const { currentThread } = this;
569
- return currentThread && currentThread.topFrame;
570
- }
571
-
572
- getFunctionBreakpoints(session: DebugSession | undefined = this.currentSession): DebugFunctionBreakpoint[] {
573
- if (session && session.state > DebugState.Initializing) {
574
- return session.getFunctionBreakpoints();
575
- }
576
- const { labelProvider, breakpoints, editorManager } = this;
577
- return this.breakpoints.getFunctionBreakpoints().map(origin => new DebugFunctionBreakpoint(origin, { labelProvider, breakpoints, editorManager }));
578
- }
579
-
580
- getInstructionBreakpoints(session = this.currentSession): DebugInstructionBreakpoint[] {
581
- if (session && session.state > DebugState.Initializing) {
582
- return session.getInstructionBreakpoints();
583
- }
584
- const { labelProvider, breakpoints, editorManager } = this;
585
- return this.breakpoints.getInstructionBreakpoints().map(origin => new DebugInstructionBreakpoint(origin, { labelProvider, breakpoints, editorManager }));
586
- }
587
-
588
- getBreakpoints(session?: DebugSession): DebugSourceBreakpoint[];
589
- getBreakpoints(uri: URI, session?: DebugSession): DebugSourceBreakpoint[];
590
- getBreakpoints(arg?: URI | DebugSession, arg2?: DebugSession): DebugSourceBreakpoint[] {
591
- const uri = arg instanceof URI ? arg : undefined;
592
- const session = arg instanceof DebugSession ? arg : arg2 instanceof DebugSession ? arg2 : this.currentSession;
593
- if (session && session.state > DebugState.Initializing) {
594
- return session.getSourceBreakpoints(uri);
595
- }
596
- const { labelProvider, breakpoints, editorManager } = this;
597
- return this.breakpoints.findMarkers({ uri }).map(({ data }) => new DebugSourceBreakpoint(data, { labelProvider, breakpoints, editorManager }));
598
- }
599
-
600
- getLineBreakpoints(uri: URI, line: number): DebugSourceBreakpoint[] {
601
- const session = this.currentSession;
602
- if (session && session.state > DebugState.Initializing) {
603
- return session.getSourceBreakpoints(uri).filter(breakpoint => breakpoint.line === line);
604
- }
605
- const { labelProvider, breakpoints, editorManager } = this;
606
- return this.breakpoints.getLineBreakpoints(uri, line).map(origin =>
607
- new DebugSourceBreakpoint(origin, { labelProvider, breakpoints, editorManager })
608
- );
609
- }
610
-
611
- getInlineBreakpoint(uri: URI, line: number, column: number): DebugSourceBreakpoint | undefined {
612
- const session = this.currentSession;
613
- if (session && session.state > DebugState.Initializing) {
614
- return session.getSourceBreakpoints(uri).filter(breakpoint => breakpoint.line === line && breakpoint.column === column)[0];
615
- }
616
- const origin = this.breakpoints.getInlineBreakpoint(uri, line, column);
617
- const { labelProvider, breakpoints, editorManager } = this;
618
- return origin && new DebugSourceBreakpoint(origin, { labelProvider, breakpoints, editorManager });
619
- }
620
-
621
- /**
622
- * Runs the given tasks.
623
- * @param taskName the task name to run, see [TaskNameResolver](#TaskNameResolver)
624
- * @return true if it allowed to continue debugging otherwise it returns false
625
- */
626
- protected async runTask(workspaceFolderUri: string | undefined, taskName: string | TaskIdentifier | undefined, checkErrors?: boolean): Promise<boolean> {
627
- if (!taskName) {
628
- return true;
629
- }
630
-
631
- const taskInfo = await this.taskService.runWorkspaceTask(this.taskService.startUserAction(), workspaceFolderUri, taskName);
632
- if (!checkErrors) {
633
- return true;
634
- }
635
-
636
- if (!taskInfo) {
637
- return this.doPostTaskAction(`Could not run the task '${taskName}'.`);
638
- }
639
-
640
- const getExitCodePromise: Promise<TaskEndedInfo> = this.taskService.getExitCode(taskInfo.taskId).then(result =>
641
- ({ taskEndedType: TaskEndedTypes.TaskExited, value: result }));
642
- const isBackgroundTaskEndedPromise: Promise<TaskEndedInfo> = this.taskService.isBackgroundTaskEnded(taskInfo.taskId).then(result =>
643
- ({ taskEndedType: TaskEndedTypes.BackgroundTaskEnded, value: result }));
644
-
645
- // After start running the task, we wait for the task process to exit and if it is a background task, we also wait for a feedback
646
- // that a background task is active, as soon as one of the promises fulfills, we can continue and analyze the results.
647
- const taskEndedInfo: TaskEndedInfo = await Promise.race([getExitCodePromise, isBackgroundTaskEndedPromise]);
648
-
649
- if (taskEndedInfo.taskEndedType === TaskEndedTypes.BackgroundTaskEnded && taskEndedInfo.value) {
650
- return true;
651
- }
652
- if (taskEndedInfo.taskEndedType === TaskEndedTypes.TaskExited && taskEndedInfo.value === 0) {
653
- return true;
654
- } else if (taskEndedInfo.taskEndedType === TaskEndedTypes.TaskExited && taskEndedInfo.value !== undefined) {
655
- return this.doPostTaskAction(`Task '${taskName}' terminated with exit code ${taskEndedInfo.value}.`);
656
- } else {
657
- const signal = await this.taskService.getTerminateSignal(taskInfo.taskId);
658
- if (signal !== undefined) {
659
- return this.doPostTaskAction(`Task '${taskName}' terminated by signal ${signal}.`);
660
- } else {
661
- return this.doPostTaskAction(`Task '${taskName}' terminated for unknown reason.`);
662
- }
663
- }
664
- }
665
-
666
- protected async doPostTaskAction(errorMessage: string): Promise<boolean> {
667
- const actions = ['Open launch.json', 'Cancel', 'Configure Task', 'Debug Anyway'];
668
- const result = await this.messageService.error(errorMessage, ...actions);
669
- switch (result) {
670
- case actions[0]: // open launch.json
671
- this.debugConfigurationManager.openConfiguration();
672
- return false;
673
- case actions[1]: // cancel
674
- return false;
675
- case actions[2]: // configure tasks
676
- this.quickOpenTask.configure();
677
- return false;
678
- default: // continue debugging
679
- return true;
680
- }
681
- }
682
- }
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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { DisposableCollection, Emitter, Event, MessageService, nls, ProgressService, WaitUntilEvent } from '@theia/core';
18
+ import { LabelProvider, ApplicationShell } from '@theia/core/lib/browser';
19
+ import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-key-service';
20
+ import URI from '@theia/core/lib/common/uri';
21
+ import { EditorManager } from '@theia/editor/lib/browser';
22
+ import { QuickOpenTask } from '@theia/task/lib/browser/quick-open-task';
23
+ import { TaskService, TaskEndedInfo, TaskEndedTypes } from '@theia/task/lib/browser/task-service';
24
+ import { VariableResolverService } from '@theia/variable-resolver/lib/browser';
25
+ import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
26
+ import { DebugConfiguration } from '../common/debug-common';
27
+ import { DebugError, DebugService } from '../common/debug-service';
28
+ import { BreakpointManager } from './breakpoint/breakpoint-manager';
29
+ import { DebugConfigurationManager } from './debug-configuration-manager';
30
+ import { DebugSession, DebugState, debugStateContextValue } from './debug-session';
31
+ import { DebugSessionContributionRegistry, DebugSessionFactory } from './debug-session-contribution';
32
+ import { DebugCompoundRoot, DebugCompoundSessionOptions, DebugConfigurationSessionOptions, DebugSessionOptions, InternalDebugSessionOptions } from './debug-session-options';
33
+ import { DebugStackFrame } from './model/debug-stack-frame';
34
+ import { DebugThread } from './model/debug-thread';
35
+ import { TaskIdentifier } from '@theia/task/lib/common';
36
+ import { DebugSourceBreakpoint } from './model/debug-source-breakpoint';
37
+ import { DebugFunctionBreakpoint } from './model/debug-function-breakpoint';
38
+ import * as monaco from '@theia/monaco-editor-core';
39
+ import { DebugInstructionBreakpoint } from './model/debug-instruction-breakpoint';
40
+
41
+ export interface WillStartDebugSession extends WaitUntilEvent {
42
+ }
43
+
44
+ export interface WillResolveDebugConfiguration extends WaitUntilEvent {
45
+ debugType: string
46
+ }
47
+
48
+ export interface DidChangeActiveDebugSession {
49
+ previous: DebugSession | undefined
50
+ current: DebugSession | undefined
51
+ }
52
+
53
+ export interface DidChangeBreakpointsEvent {
54
+ session?: DebugSession
55
+ uri: URI
56
+ }
57
+
58
+ export interface DidFocusStackFrameEvent {
59
+ session: DebugSession;
60
+ frame: DebugStackFrame | undefined;
61
+ }
62
+
63
+ export interface DebugSessionCustomEvent {
64
+ readonly body?: any // eslint-disable-line @typescript-eslint/no-explicit-any
65
+ readonly event: string
66
+ readonly session: DebugSession
67
+ }
68
+
69
+ @injectable()
70
+ export class DebugSessionManager {
71
+ protected readonly _sessions = new Map<string, DebugSession>();
72
+
73
+ protected readonly onWillStartDebugSessionEmitter = new Emitter<WillStartDebugSession>();
74
+ readonly onWillStartDebugSession: Event<WillStartDebugSession> = this.onWillStartDebugSessionEmitter.event;
75
+
76
+ protected readonly onWillResolveDebugConfigurationEmitter = new Emitter<WillResolveDebugConfiguration>();
77
+ readonly onWillResolveDebugConfiguration: Event<WillResolveDebugConfiguration> = this.onWillResolveDebugConfigurationEmitter.event;
78
+
79
+ protected readonly onDidCreateDebugSessionEmitter = new Emitter<DebugSession>();
80
+ readonly onDidCreateDebugSession: Event<DebugSession> = this.onDidCreateDebugSessionEmitter.event;
81
+
82
+ protected readonly onDidStartDebugSessionEmitter = new Emitter<DebugSession>();
83
+ readonly onDidStartDebugSession: Event<DebugSession> = this.onDidStartDebugSessionEmitter.event;
84
+
85
+ protected readonly onDidStopDebugSessionEmitter = new Emitter<DebugSession>();
86
+ readonly onDidStopDebugSession: Event<DebugSession> = this.onDidStopDebugSessionEmitter.event;
87
+
88
+ protected readonly onDidChangeActiveDebugSessionEmitter = new Emitter<DidChangeActiveDebugSession>();
89
+ readonly onDidChangeActiveDebugSession: Event<DidChangeActiveDebugSession> = this.onDidChangeActiveDebugSessionEmitter.event;
90
+
91
+ protected readonly onDidDestroyDebugSessionEmitter = new Emitter<DebugSession>();
92
+ readonly onDidDestroyDebugSession: Event<DebugSession> = this.onDidDestroyDebugSessionEmitter.event;
93
+
94
+ protected readonly onDidReceiveDebugSessionCustomEventEmitter = new Emitter<DebugSessionCustomEvent>();
95
+ readonly onDidReceiveDebugSessionCustomEvent: Event<DebugSessionCustomEvent> = this.onDidReceiveDebugSessionCustomEventEmitter.event;
96
+
97
+ protected readonly onDidFocusStackFrameEmitter = new Emitter<DidFocusStackFrameEvent>();
98
+ readonly onDidFocusStackFrame = this.onDidFocusStackFrameEmitter.event;
99
+
100
+ protected readonly onDidChangeBreakpointsEmitter = new Emitter<DidChangeBreakpointsEvent>();
101
+ readonly onDidChangeBreakpoints = this.onDidChangeBreakpointsEmitter.event;
102
+ protected fireDidChangeBreakpoints(event: DidChangeBreakpointsEvent): void {
103
+ this.onDidChangeBreakpointsEmitter.fire(event);
104
+ }
105
+
106
+ protected readonly onDidChangeEmitter = new Emitter<DebugSession | undefined>();
107
+ readonly onDidChange: Event<DebugSession | undefined> = this.onDidChangeEmitter.event;
108
+ protected fireDidChange(current: DebugSession | undefined): void {
109
+ this.debugTypeKey.set(current?.configuration.type);
110
+ this.inDebugModeKey.set(this.inDebugMode);
111
+ this.debugStateKey.set(debugStateContextValue(this.state));
112
+ this.onDidChangeEmitter.fire(current);
113
+ }
114
+
115
+ @inject(DebugSessionFactory)
116
+ protected readonly debugSessionFactory: DebugSessionFactory;
117
+
118
+ @inject(DebugService)
119
+ protected readonly debug: DebugService;
120
+
121
+ @inject(LabelProvider)
122
+ protected readonly labelProvider: LabelProvider;
123
+
124
+ @inject(EditorManager)
125
+ protected readonly editorManager: EditorManager;
126
+
127
+ @inject(BreakpointManager)
128
+ protected readonly breakpoints: BreakpointManager;
129
+
130
+ @inject(VariableResolverService)
131
+ protected readonly variableResolver: VariableResolverService;
132
+
133
+ @inject(DebugSessionContributionRegistry)
134
+ protected readonly sessionContributionRegistry: DebugSessionContributionRegistry;
135
+
136
+ @inject(MessageService)
137
+ protected readonly messageService: MessageService;
138
+
139
+ @inject(ProgressService)
140
+ protected readonly progressService: ProgressService;
141
+
142
+ @inject(ContextKeyService)
143
+ protected readonly contextKeyService: ContextKeyService;
144
+
145
+ @inject(TaskService)
146
+ protected readonly taskService: TaskService;
147
+
148
+ @inject(DebugConfigurationManager)
149
+ protected readonly debugConfigurationManager: DebugConfigurationManager;
150
+
151
+ @inject(QuickOpenTask)
152
+ protected readonly quickOpenTask: QuickOpenTask;
153
+
154
+ @inject(ApplicationShell)
155
+ protected readonly shell: ApplicationShell;
156
+
157
+ protected debugTypeKey: ContextKey<string>;
158
+ protected inDebugModeKey: ContextKey<boolean>;
159
+ protected debugStateKey: ContextKey<string>;
160
+
161
+ @postConstruct()
162
+ protected init(): void {
163
+ this.debugTypeKey = this.contextKeyService.createKey<string>('debugType', undefined);
164
+ this.inDebugModeKey = this.contextKeyService.createKey<boolean>('inDebugMode', this.inDebugMode);
165
+ this.debugStateKey = this.contextKeyService.createKey<string>('debugState', debugStateContextValue(this.state));
166
+ this.breakpoints.onDidChangeMarkers(uri => this.fireDidChangeBreakpoints({ uri }));
167
+ this.labelProvider.onDidChange(event => {
168
+ for (const uriString of this.breakpoints.getUris()) {
169
+ const uri = new URI(uriString);
170
+ if (event.affects(uri)) {
171
+ this.fireDidChangeBreakpoints({ uri });
172
+ }
173
+ }
174
+ });
175
+ }
176
+
177
+ get inDebugMode(): boolean {
178
+ return this.state > DebugState.Inactive;
179
+ }
180
+
181
+ isCurrentEditorFrame(uri: URI | string | monaco.Uri): boolean {
182
+ return this.currentFrame?.source?.uri.toString() === (uri instanceof URI ? uri : new URI(uri.toString())).toString();
183
+ }
184
+
185
+ protected async saveAll(): Promise<boolean> {
186
+ if (!this.shell.canSaveAll()) {
187
+ return true; // Nothing to save.
188
+ }
189
+ try {
190
+ await this.shell.saveAll();
191
+ return true;
192
+ } catch (error) {
193
+ console.error('saveAll failed:', error);
194
+ return false;
195
+ }
196
+ }
197
+
198
+ async start(options: DebugCompoundSessionOptions): Promise<boolean | undefined>;
199
+ async start(options: DebugConfigurationSessionOptions): Promise<DebugSession | undefined>;
200
+ async start(options: DebugSessionOptions): Promise<DebugSession | boolean | undefined>;
201
+ async start(name: string): Promise<DebugSession | boolean | undefined>;
202
+ async start(optionsOrName: DebugSessionOptions | string): Promise<DebugSession | boolean | undefined> {
203
+ if (typeof optionsOrName === 'string') {
204
+ const options = this.debugConfigurationManager.find(optionsOrName);
205
+ return !!options && this.start(options);
206
+ }
207
+ return optionsOrName.configuration ? this.startConfiguration(optionsOrName) : this.startCompound(optionsOrName);
208
+ }
209
+
210
+ protected async startConfiguration(options: DebugConfigurationSessionOptions): Promise<DebugSession | undefined> {
211
+ return this.progressService.withProgress('Start...', 'debug', async () => {
212
+ try {
213
+ // If a parent session is available saving should be handled by the parent
214
+ if (!options.configuration.parentSessionId && !options.configuration.suppressSaveBeforeStart && !await this.saveAll()) {
215
+ return undefined;
216
+ }
217
+ await this.fireWillStartDebugSession();
218
+ const resolved = await this.resolveConfiguration(options);
219
+
220
+ if (!resolved || !resolved.configuration) {
221
+ // As per vscode API: https://code.visualstudio.com/api/references/vscode-api#DebugConfigurationProvider
222
+ // "Returning the value 'undefined' prevents the debug session from starting.
223
+ // Returning the value 'null' prevents the debug session from starting and opens the
224
+ // underlying debug configuration instead."
225
+
226
+ // eslint-disable-next-line no-null/no-null
227
+ if (resolved === null) {
228
+ this.debugConfigurationManager.openConfiguration();
229
+ }
230
+ return undefined;
231
+ }
232
+
233
+ // preLaunchTask isn't run in case of auto restart as well as postDebugTask
234
+ if (!options.configuration.__restart) {
235
+ const taskRun = await this.runTask(options.workspaceFolderUri, resolved.configuration.preLaunchTask, true);
236
+ if (!taskRun) {
237
+ return undefined;
238
+ }
239
+ }
240
+
241
+ const sessionId = await this.debug.createDebugSession(resolved.configuration, options.workspaceFolderUri);
242
+ return this.doStart(sessionId, resolved);
243
+ } catch (e) {
244
+ if (DebugError.NotFound.is(e)) {
245
+ this.messageService.error(`The debug session type "${e.data.type}" is not supported.`);
246
+ return undefined;
247
+ }
248
+
249
+ this.messageService.error('There was an error starting the debug session, check the logs for more details.');
250
+ console.error('Error starting the debug session', e);
251
+ throw e;
252
+ }
253
+ });
254
+ }
255
+
256
+ protected async startCompound(options: DebugCompoundSessionOptions): Promise<boolean | undefined> {
257
+ let configurations: DebugConfigurationSessionOptions[] = [];
258
+ const compoundRoot = options.compound.stopAll ? new DebugCompoundRoot() : undefined;
259
+ try {
260
+ configurations = this.getCompoundConfigurations(options, compoundRoot);
261
+ } catch (error) {
262
+ this.messageService.error(error.message);
263
+ return;
264
+ }
265
+
266
+ if (options.compound.preLaunchTask) {
267
+ const taskRun = await this.runTask(options.workspaceFolderUri, options.compound.preLaunchTask, true);
268
+ if (!taskRun) {
269
+ return undefined;
270
+ }
271
+ }
272
+
273
+ // Compound launch is a success only if each configuration launched successfully
274
+ const values = await Promise.all(configurations.map(async configuration => {
275
+ const newSession = await this.startConfiguration(configuration);
276
+ if (newSession) {
277
+ compoundRoot?.onDidSessionStop(() => newSession.stop(false, () => this.debug.terminateDebugSession(newSession.id)));
278
+ }
279
+ return newSession;
280
+ }));
281
+ const result = values.every(success => !!success);
282
+ return result;
283
+ }
284
+
285
+ protected getCompoundConfigurations(options: DebugCompoundSessionOptions, compoundRoot: DebugCompoundRoot | undefined): DebugConfigurationSessionOptions[] {
286
+ const compound = options.compound;
287
+ if (!compound.configurations) {
288
+ throw new Error(nls.localizeByDefault('Compound must have "configurations" attribute set in order to start multiple configurations.'));
289
+ }
290
+
291
+ const configurations: DebugConfigurationSessionOptions[] = [];
292
+
293
+ for (const configData of compound.configurations) {
294
+ const name = typeof configData === 'string' ? configData : configData.name;
295
+ if (name === compound.name) {
296
+ throw new Error(nls.localize('theia/debug/compound-cycle', "Launch configuration '{0}' contains a cycle with itself", name));
297
+ }
298
+
299
+ const workspaceFolderUri = typeof configData === 'string' ? options.workspaceFolderUri : configData.folder;
300
+ const matchingOptions = [...this.debugConfigurationManager.all]
301
+ .filter(option => option.name === name && !!option.configuration && option.workspaceFolderUri === workspaceFolderUri);
302
+ if (matchingOptions.length === 1) {
303
+ const match = matchingOptions[0];
304
+ if (DebugSessionOptions.isConfiguration(match)) {
305
+ configurations.push({ ...match, compoundRoot, configuration: { ...match.configuration, noDebug: options.noDebug } });
306
+ } else {
307
+ throw new Error(nls.localizeByDefault("Could not find launch configuration '{0}' in the workspace.", name));
308
+ }
309
+ } else {
310
+ throw new Error(matchingOptions.length === 0
311
+ ? workspaceFolderUri
312
+ ? nls.localizeByDefault("Can not find folder with name '{0}' for configuration '{1}' in compound '{2}'.", workspaceFolderUri, name, compound.name)
313
+ : nls.localizeByDefault("Could not find launch configuration '{0}' in the workspace.", name)
314
+ : nls.localizeByDefault("There are multiple launch configurations '{0}' in the workspace. Use folder name to qualify the configuration.", name));
315
+ }
316
+ }
317
+ return configurations;
318
+ }
319
+
320
+ protected async fireWillStartDebugSession(): Promise<void> {
321
+ await WaitUntilEvent.fire(this.onWillStartDebugSessionEmitter, {});
322
+ }
323
+
324
+ protected configurationIds = new Map<string, number>();
325
+ protected async resolveConfiguration(
326
+ options: Readonly<DebugConfigurationSessionOptions>
327
+ ): Promise<InternalDebugSessionOptions | undefined | null> {
328
+ if (InternalDebugSessionOptions.is(options)) {
329
+ return options;
330
+ }
331
+ const { workspaceFolderUri } = options;
332
+ let configuration = await this.resolveDebugConfiguration(options.configuration, workspaceFolderUri);
333
+
334
+ if (configuration) {
335
+ // Resolve command variables provided by the debugger
336
+ const commandIdVariables = await this.debug.provideDebuggerVariables(configuration.type);
337
+ configuration = await this.variableResolver.resolve(configuration, {
338
+ context: options.workspaceFolderUri ? new URI(options.workspaceFolderUri) : undefined,
339
+ configurationSection: 'launch',
340
+ commandIdVariables,
341
+ configuration
342
+ });
343
+
344
+ if (configuration) {
345
+ configuration = await this.resolveDebugConfigurationWithSubstitutedVariables(
346
+ configuration,
347
+ workspaceFolderUri
348
+ );
349
+ }
350
+ }
351
+
352
+ if (!configuration) {
353
+ return configuration;
354
+ }
355
+
356
+ const key = configuration.name + workspaceFolderUri;
357
+ const id = this.configurationIds.has(key) ? this.configurationIds.get(key)! + 1 : 0;
358
+ this.configurationIds.set(key, id);
359
+
360
+ return {
361
+ id,
362
+ ...options,
363
+ name: configuration.name,
364
+ configuration
365
+ };
366
+ }
367
+
368
+ protected async resolveDebugConfiguration(
369
+ configuration: DebugConfiguration,
370
+ workspaceFolderUri: string | undefined
371
+ ): Promise<DebugConfiguration | undefined | null> {
372
+ await this.fireWillResolveDebugConfiguration(configuration.type);
373
+ return this.debug.resolveDebugConfiguration(configuration, workspaceFolderUri);
374
+ }
375
+
376
+ protected async fireWillResolveDebugConfiguration(debugType: string): Promise<void> {
377
+ await WaitUntilEvent.fire(this.onWillResolveDebugConfigurationEmitter, { debugType });
378
+ }
379
+
380
+ protected async resolveDebugConfigurationWithSubstitutedVariables(
381
+ configuration: DebugConfiguration,
382
+ workspaceFolderUri: string | undefined
383
+ ): Promise<DebugConfiguration | undefined | null> {
384
+ return this.debug.resolveDebugConfigurationWithSubstitutedVariables(configuration, workspaceFolderUri);
385
+ }
386
+
387
+ protected async doStart(sessionId: string, options: DebugConfigurationSessionOptions): Promise<DebugSession> {
388
+ const parentSession = options.configuration.parentSessionId ? this._sessions.get(options.configuration.parentSessionId) : undefined;
389
+ const contrib = this.sessionContributionRegistry.get(options.configuration.type);
390
+ const sessionFactory = contrib ? contrib.debugSessionFactory() : this.debugSessionFactory;
391
+ const session = sessionFactory.get(sessionId, options, parentSession);
392
+ this._sessions.set(sessionId, session);
393
+
394
+ this.debugTypeKey.set(session.configuration.type);
395
+ this.onDidCreateDebugSessionEmitter.fire(session);
396
+
397
+ let state = DebugState.Inactive;
398
+ session.onDidChange(() => {
399
+ if (state !== session.state) {
400
+ state = session.state;
401
+ if (state === DebugState.Stopped) {
402
+ this.onDidStopDebugSessionEmitter.fire(session);
403
+ }
404
+ }
405
+ this.updateCurrentSession(session);
406
+ });
407
+ session.onDidChangeBreakpoints(uri => this.fireDidChangeBreakpoints({ session, uri }));
408
+ session.on('terminated', async event => {
409
+ const restart = event.body && event.body.restart;
410
+ if (restart) {
411
+ // postDebugTask isn't run in case of auto restart as well as preLaunchTask
412
+ this.doRestart(session, !!restart);
413
+ } else {
414
+ await session.disconnect(false, () => this.debug.terminateDebugSession(session.id));
415
+ await this.runTask(session.options.workspaceFolderUri, session.configuration.postDebugTask);
416
+ }
417
+ });
418
+
419
+ session.on('exited', async event => {
420
+ await session.disconnect(false, () => this.debug.terminateDebugSession(session.id));
421
+ });
422
+
423
+ session.onDispose(() => this.cleanup(session));
424
+ session.start().then(() => this.onDidStartDebugSessionEmitter.fire(session)).catch(e => {
425
+ session.stop(false, () => {
426
+ this.debug.terminateDebugSession(session.id);
427
+ });
428
+ });
429
+ session.onDidCustomEvent(({ event, body }) =>
430
+ this.onDidReceiveDebugSessionCustomEventEmitter.fire({ event, body, session })
431
+ );
432
+ return session;
433
+ }
434
+
435
+ protected cleanup(session: DebugSession): void {
436
+ if (this.remove(session.id)) {
437
+ this.onDidDestroyDebugSessionEmitter.fire(session);
438
+ }
439
+ }
440
+
441
+ protected async doRestart(session: DebugSession, isRestart: boolean): Promise<DebugSession | undefined> {
442
+ if (session.canRestart()) {
443
+ await session.restart();
444
+ return session;
445
+ }
446
+
447
+ const { options, configuration } = session;
448
+ session.stop(isRestart, () => this.debug.terminateDebugSession(session.id));
449
+ configuration.__restart = isRestart;
450
+ return this.start(options);
451
+ }
452
+
453
+ async terminateSession(session?: DebugSession): Promise<void> {
454
+ if (!session) {
455
+ this.updateCurrentSession(this._currentSession);
456
+ session = this._currentSession;
457
+ }
458
+ if (session) {
459
+ if (session.options.compoundRoot) {
460
+ session.options.compoundRoot.stopSession();
461
+ } else if (session.parentSession && session.configuration.lifecycleManagedByParent) {
462
+ this.terminateSession(session.parentSession);
463
+ } else {
464
+ session.stop(false, () => this.debug.terminateDebugSession(session!.id));
465
+ }
466
+ }
467
+ }
468
+
469
+ async restartSession(session?: DebugSession): Promise<DebugSession | undefined> {
470
+ if (!session) {
471
+ this.updateCurrentSession(this._currentSession);
472
+ session = this._currentSession;
473
+ }
474
+
475
+ if (session) {
476
+ if (session.parentSession && session.configuration.lifecycleManagedByParent) {
477
+ return this.restartSession(session.parentSession);
478
+ } else {
479
+ return this.doRestart(session, true);
480
+ }
481
+ }
482
+ }
483
+
484
+ protected remove(sessionId: string): boolean {
485
+ const existed = this._sessions.delete(sessionId);
486
+ const { currentSession } = this;
487
+ if (currentSession && currentSession.id === sessionId) {
488
+ this.updateCurrentSession(undefined);
489
+ }
490
+ return existed;
491
+ }
492
+
493
+ getSession(sessionId: string): DebugSession | undefined {
494
+ return this._sessions.get(sessionId);
495
+ }
496
+
497
+ get sessions(): DebugSession[] {
498
+ return Array.from(this._sessions.values()).filter(session => session.state > DebugState.Inactive);
499
+ }
500
+
501
+ protected _currentSession: DebugSession | undefined;
502
+ protected readonly disposeOnCurrentSessionChanged = new DisposableCollection();
503
+ get currentSession(): DebugSession | undefined {
504
+ return this._currentSession;
505
+ }
506
+ set currentSession(current: DebugSession | undefined) {
507
+ if (this._currentSession === current) {
508
+ return;
509
+ }
510
+ this.disposeOnCurrentSessionChanged.dispose();
511
+ const previous = this.currentSession;
512
+ this._currentSession = current;
513
+ this.onDidChangeActiveDebugSessionEmitter.fire({ previous, current });
514
+ if (current) {
515
+ this.disposeOnCurrentSessionChanged.push(current.onDidChange(() => {
516
+ if (this.currentFrame === this.topFrame) {
517
+ this.open();
518
+ }
519
+ this.fireDidChange(current);
520
+ }));
521
+ this.disposeOnCurrentSessionChanged.push(current.onDidFocusStackFrame(frame => this.onDidFocusStackFrameEmitter.fire({ session: current, frame })));
522
+ }
523
+ this.updateBreakpoints(previous, current);
524
+ this.open();
525
+ this.fireDidChange(current);
526
+ }
527
+ open(): void {
528
+ const { currentFrame } = this;
529
+ if (currentFrame && currentFrame.thread.stopped) {
530
+ currentFrame.open();
531
+ }
532
+ }
533
+ protected updateBreakpoints(previous: DebugSession | undefined, current: DebugSession | undefined): void {
534
+ const affectedUri = new Set();
535
+ for (const session of [previous, current]) {
536
+ if (session) {
537
+ for (const uriString of session.breakpointUris) {
538
+ if (!affectedUri.has(uriString)) {
539
+ affectedUri.add(uriString);
540
+ this.fireDidChangeBreakpoints({
541
+ session: current,
542
+ uri: new URI(uriString)
543
+ });
544
+ }
545
+ }
546
+ }
547
+ }
548
+ }
549
+ protected updateCurrentSession(session: DebugSession | undefined): void {
550
+ this.currentSession = session || this.sessions[0];
551
+ }
552
+
553
+ get currentThread(): DebugThread | undefined {
554
+ const session = this.currentSession;
555
+ return session && session.currentThread;
556
+ }
557
+
558
+ get state(): DebugState {
559
+ const session = this.currentSession;
560
+ return session ? session.state : DebugState.Inactive;
561
+ }
562
+
563
+ get currentFrame(): DebugStackFrame | undefined {
564
+ const { currentThread } = this;
565
+ return currentThread && currentThread.currentFrame;
566
+ }
567
+ get topFrame(): DebugStackFrame | undefined {
568
+ const { currentThread } = this;
569
+ return currentThread && currentThread.topFrame;
570
+ }
571
+
572
+ getFunctionBreakpoints(session: DebugSession | undefined = this.currentSession): DebugFunctionBreakpoint[] {
573
+ if (session && session.state > DebugState.Initializing) {
574
+ return session.getFunctionBreakpoints();
575
+ }
576
+ const { labelProvider, breakpoints, editorManager } = this;
577
+ return this.breakpoints.getFunctionBreakpoints().map(origin => new DebugFunctionBreakpoint(origin, { labelProvider, breakpoints, editorManager }));
578
+ }
579
+
580
+ getInstructionBreakpoints(session = this.currentSession): DebugInstructionBreakpoint[] {
581
+ if (session && session.state > DebugState.Initializing) {
582
+ return session.getInstructionBreakpoints();
583
+ }
584
+ const { labelProvider, breakpoints, editorManager } = this;
585
+ return this.breakpoints.getInstructionBreakpoints().map(origin => new DebugInstructionBreakpoint(origin, { labelProvider, breakpoints, editorManager }));
586
+ }
587
+
588
+ getBreakpoints(session?: DebugSession): DebugSourceBreakpoint[];
589
+ getBreakpoints(uri: URI, session?: DebugSession): DebugSourceBreakpoint[];
590
+ getBreakpoints(arg?: URI | DebugSession, arg2?: DebugSession): DebugSourceBreakpoint[] {
591
+ const uri = arg instanceof URI ? arg : undefined;
592
+ const session = arg instanceof DebugSession ? arg : arg2 instanceof DebugSession ? arg2 : this.currentSession;
593
+ if (session && session.state > DebugState.Initializing) {
594
+ return session.getSourceBreakpoints(uri);
595
+ }
596
+ const { labelProvider, breakpoints, editorManager } = this;
597
+ return this.breakpoints.findMarkers({ uri }).map(({ data }) => new DebugSourceBreakpoint(data, { labelProvider, breakpoints, editorManager }));
598
+ }
599
+
600
+ getLineBreakpoints(uri: URI, line: number): DebugSourceBreakpoint[] {
601
+ const session = this.currentSession;
602
+ if (session && session.state > DebugState.Initializing) {
603
+ return session.getSourceBreakpoints(uri).filter(breakpoint => breakpoint.line === line);
604
+ }
605
+ const { labelProvider, breakpoints, editorManager } = this;
606
+ return this.breakpoints.getLineBreakpoints(uri, line).map(origin =>
607
+ new DebugSourceBreakpoint(origin, { labelProvider, breakpoints, editorManager })
608
+ );
609
+ }
610
+
611
+ getInlineBreakpoint(uri: URI, line: number, column: number): DebugSourceBreakpoint | undefined {
612
+ const session = this.currentSession;
613
+ if (session && session.state > DebugState.Initializing) {
614
+ return session.getSourceBreakpoints(uri).filter(breakpoint => breakpoint.line === line && breakpoint.column === column)[0];
615
+ }
616
+ const origin = this.breakpoints.getInlineBreakpoint(uri, line, column);
617
+ const { labelProvider, breakpoints, editorManager } = this;
618
+ return origin && new DebugSourceBreakpoint(origin, { labelProvider, breakpoints, editorManager });
619
+ }
620
+
621
+ /**
622
+ * Runs the given tasks.
623
+ * @param taskName the task name to run, see [TaskNameResolver](#TaskNameResolver)
624
+ * @return true if it allowed to continue debugging otherwise it returns false
625
+ */
626
+ protected async runTask(workspaceFolderUri: string | undefined, taskName: string | TaskIdentifier | undefined, checkErrors?: boolean): Promise<boolean> {
627
+ if (!taskName) {
628
+ return true;
629
+ }
630
+
631
+ const taskInfo = await this.taskService.runWorkspaceTask(this.taskService.startUserAction(), workspaceFolderUri, taskName);
632
+ if (!checkErrors) {
633
+ return true;
634
+ }
635
+
636
+ if (!taskInfo) {
637
+ return this.doPostTaskAction(`Could not run the task '${taskName}'.`);
638
+ }
639
+
640
+ const getExitCodePromise: Promise<TaskEndedInfo> = this.taskService.getExitCode(taskInfo.taskId).then(result =>
641
+ ({ taskEndedType: TaskEndedTypes.TaskExited, value: result }));
642
+ const isBackgroundTaskEndedPromise: Promise<TaskEndedInfo> = this.taskService.isBackgroundTaskEnded(taskInfo.taskId).then(result =>
643
+ ({ taskEndedType: TaskEndedTypes.BackgroundTaskEnded, value: result }));
644
+
645
+ // After start running the task, we wait for the task process to exit and if it is a background task, we also wait for a feedback
646
+ // that a background task is active, as soon as one of the promises fulfills, we can continue and analyze the results.
647
+ const taskEndedInfo: TaskEndedInfo = await Promise.race([getExitCodePromise, isBackgroundTaskEndedPromise]);
648
+
649
+ if (taskEndedInfo.taskEndedType === TaskEndedTypes.BackgroundTaskEnded && taskEndedInfo.value) {
650
+ return true;
651
+ }
652
+ if (taskEndedInfo.taskEndedType === TaskEndedTypes.TaskExited && taskEndedInfo.value === 0) {
653
+ return true;
654
+ } else if (taskEndedInfo.taskEndedType === TaskEndedTypes.TaskExited && taskEndedInfo.value !== undefined) {
655
+ return this.doPostTaskAction(`Task '${taskName}' terminated with exit code ${taskEndedInfo.value}.`);
656
+ } else {
657
+ const signal = await this.taskService.getTerminateSignal(taskInfo.taskId);
658
+ if (signal !== undefined) {
659
+ return this.doPostTaskAction(`Task '${taskName}' terminated by signal ${signal}.`);
660
+ } else {
661
+ return this.doPostTaskAction(`Task '${taskName}' terminated for unknown reason.`);
662
+ }
663
+ }
664
+ }
665
+
666
+ protected async doPostTaskAction(errorMessage: string): Promise<boolean> {
667
+ const actions = ['Open launch.json', 'Cancel', 'Configure Task', 'Debug Anyway'];
668
+ const result = await this.messageService.error(errorMessage, ...actions);
669
+ switch (result) {
670
+ case actions[0]: // open launch.json
671
+ this.debugConfigurationManager.openConfiguration();
672
+ return false;
673
+ case actions[1]: // cancel
674
+ return false;
675
+ case actions[2]: // configure tasks
676
+ this.quickOpenTask.configure();
677
+ return false;
678
+ default: // continue debugging
679
+ return true;
680
+ }
681
+ }
682
+ }