@theia/debug 1.34.2 → 1.34.3

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