@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,872 +1,872 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2018 Red Hat, Inc. and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.DebugSession = exports.debugStateContextValue = exports.DebugState = void 0;
19
- /* eslint-disable @typescript-eslint/no-explicit-any */
20
- const React = require("@theia/core/shared/react");
21
- const common_1 = require("@theia/core/lib/common");
22
- const debug_thread_1 = require("./model/debug-thread");
23
- const debug_source_1 = require("./model/debug-source");
24
- const debug_source_breakpoint_1 = require("./model/debug-source-breakpoint");
25
- const debounce = require("p-debounce");
26
- const uri_1 = require("@theia/core/lib/common/uri");
27
- const breakpoint_manager_1 = require("./breakpoint/breakpoint-manager");
28
- const debug_session_options_1 = require("./debug-session-options");
29
- const debug_common_1 = require("../common/debug-common");
30
- const breakpoint_marker_1 = require("./breakpoint/breakpoint-marker");
31
- const debug_function_breakpoint_1 = require("./model/debug-function-breakpoint");
32
- const promise_util_1 = require("@theia/core/lib/common/promise-util");
33
- const debug_instruction_breakpoint_1 = require("./model/debug-instruction-breakpoint");
34
- const core_1 = require("@theia/core");
35
- var DebugState;
36
- (function (DebugState) {
37
- DebugState[DebugState["Inactive"] = 0] = "Inactive";
38
- DebugState[DebugState["Initializing"] = 1] = "Initializing";
39
- DebugState[DebugState["Running"] = 2] = "Running";
40
- DebugState[DebugState["Stopped"] = 3] = "Stopped";
41
- })(DebugState = exports.DebugState || (exports.DebugState = {}));
42
- /**
43
- * The mapped string values must not change as they are used for the `debugState` when context closure.
44
- * For more details see the `Debugger contexts` section of the [official doc](https://code.visualstudio.com/api/references/when-clause-contexts#available-contexts).
45
- */
46
- function debugStateContextValue(state) {
47
- switch (state) {
48
- case DebugState.Initializing: return 'initializing';
49
- case DebugState.Stopped: return 'stopped';
50
- case DebugState.Running: return 'running';
51
- default: return 'inactive';
52
- }
53
- }
54
- exports.debugStateContextValue = debugStateContextValue;
55
- // FIXME: make injectable to allow easily inject services
56
- class DebugSession {
57
- constructor(id, options, parentSession, connection, terminalServer, editorManager, breakpoints, labelProvider, messages, fileService, debugContributionProvider, workspaceService,
58
- /**
59
- * Number of millis after a `stop` request times out. It's 5 seconds by default.
60
- */
61
- stopTimeout = 5000) {
62
- this.id = id;
63
- this.options = options;
64
- this.parentSession = parentSession;
65
- this.connection = connection;
66
- this.terminalServer = terminalServer;
67
- this.editorManager = editorManager;
68
- this.breakpoints = breakpoints;
69
- this.labelProvider = labelProvider;
70
- this.messages = messages;
71
- this.fileService = fileService;
72
- this.debugContributionProvider = debugContributionProvider;
73
- this.workspaceService = workspaceService;
74
- this.stopTimeout = stopTimeout;
75
- this.deferredOnDidConfigureCapabilities = new promise_util_1.Deferred();
76
- this.onDidChangeEmitter = new common_1.Emitter();
77
- this.onDidChange = this.onDidChangeEmitter.event;
78
- this.onDidFocusStackFrameEmitter = new common_1.Emitter();
79
- this.onDidChangeBreakpointsEmitter = new common_1.Emitter();
80
- this.onDidChangeBreakpoints = this.onDidChangeBreakpointsEmitter.event;
81
- this.childSessions = new Map();
82
- this.toDispose = new common_1.DisposableCollection();
83
- this.isStopping = false;
84
- this._capabilities = {};
85
- this.sources = new Map();
86
- this._threads = new Map();
87
- this.toDisposeOnCurrentThread = new common_1.DisposableCollection();
88
- /**
89
- * The `send('initialize')` request could resolve later than `on('initialized')` emits the event.
90
- * Hence, the `configure` would use the empty object `capabilities`.
91
- * Using the empty `capabilities` could result in missing exception breakpoint filters, as
92
- * always `capabilities.exceptionBreakpointFilters` is falsy. This deferred promise works
93
- * around this timing issue. https://github.com/eclipse-theia/theia/issues/11886
94
- */
95
- this.didReceiveCapabilities = new promise_util_1.Deferred();
96
- this.initialized = false;
97
- this.scheduleUpdateThreads = debounce(() => this.updateThreads(undefined), 100);
98
- this.pendingThreads = Promise.resolve();
99
- this._breakpoints = new Map();
100
- this.updatingBreakpoints = false;
101
- this.connection.onRequest('runInTerminal', (request) => this.runInTerminal(request));
102
- this.connection.onDidClose(() => {
103
- this.toDispose.dispose();
104
- });
105
- this.registerDebugContributions(options.configuration.type, this.connection);
106
- if (parentSession) {
107
- parentSession.childSessions.set(id, this);
108
- this.toDispose.push(common_1.Disposable.create(() => {
109
- var _a, _b;
110
- (_b = (_a = this.parentSession) === null || _a === void 0 ? void 0 : _a.childSessions) === null || _b === void 0 ? void 0 : _b.delete(id);
111
- }));
112
- }
113
- this.connection.onDidClose(() => this.toDispose.dispose());
114
- this.toDispose.pushAll([
115
- this.onDidChangeEmitter,
116
- this.onDidChangeBreakpointsEmitter,
117
- common_1.Disposable.create(() => {
118
- this.clearBreakpoints();
119
- this.doUpdateThreads([]);
120
- }),
121
- this.connection,
122
- this.connection.on('initialized', () => this.configure()),
123
- this.connection.on('breakpoint', ({ body }) => this.updateBreakpoint(body)),
124
- this.connection.on('continued', e => this.handleContinued(e)),
125
- this.connection.on('stopped', e => this.handleStopped(e)),
126
- this.connection.on('thread', e => this.handleThread(e)),
127
- this.connection.on('capabilities', event => this.updateCapabilities(event.body.capabilities)),
128
- this.breakpoints.onDidChangeMarkers(uri => this.updateBreakpoints({ uri, sourceModified: true }))
129
- ]);
130
- }
131
- fireDidChange() {
132
- this.onDidChangeEmitter.fire(undefined);
133
- }
134
- get onDidFocusStackFrame() {
135
- return this.onDidFocusStackFrameEmitter.event;
136
- }
137
- fireDidChangeBreakpoints(uri) {
138
- this.onDidChangeBreakpointsEmitter.fire(uri);
139
- }
140
- get onDispose() {
141
- return this.toDispose.onDispose;
142
- }
143
- get configuration() {
144
- return this.options.configuration;
145
- }
146
- get capabilities() {
147
- return this._capabilities;
148
- }
149
- getSource(raw) {
150
- const uri = debug_source_1.DebugSource.toUri(raw).toString();
151
- const source = this.sources.get(uri) || new debug_source_1.DebugSource(this, this.editorManager, this.labelProvider);
152
- source.update({ raw });
153
- this.sources.set(uri, source);
154
- return source;
155
- }
156
- getSourceForUri(uri) {
157
- return this.sources.get(uri.toString());
158
- }
159
- async toSource(uri) {
160
- const source = this.getSourceForUri(uri);
161
- if (source) {
162
- return source;
163
- }
164
- return this.getSource(await this.toDebugSource(uri));
165
- }
166
- async toDebugSource(uri) {
167
- if (uri.scheme === debug_source_1.DebugSource.SCHEME) {
168
- return {
169
- name: uri.path.toString(),
170
- sourceReference: Number(uri.query)
171
- };
172
- }
173
- const name = uri.displayName;
174
- let path;
175
- const underlying = await this.fileService.toUnderlyingResource(uri);
176
- if (underlying.scheme === 'file') {
177
- path = await this.fileService.fsPath(underlying);
178
- }
179
- else {
180
- path = uri.toString();
181
- }
182
- return { name, path };
183
- }
184
- get threads() {
185
- return this._threads.values();
186
- }
187
- get threadCount() {
188
- return this._threads.size;
189
- }
190
- *getThreads(filter) {
191
- for (const thread of this.threads) {
192
- if (filter(thread)) {
193
- yield thread;
194
- }
195
- }
196
- }
197
- get runningThreads() {
198
- return this.getThreads(thread => !thread.stopped);
199
- }
200
- get stoppedThreads() {
201
- return this.getThreads(thread => thread.stopped);
202
- }
203
- async pauseAll() {
204
- const promises = [];
205
- for (const thread of this.runningThreads) {
206
- promises.push((async () => {
207
- try {
208
- await thread.pause();
209
- }
210
- catch (e) {
211
- console.error('pauseAll failed:', e);
212
- }
213
- })());
214
- }
215
- await Promise.all(promises);
216
- }
217
- async continueAll() {
218
- const promises = [];
219
- for (const thread of this.stoppedThreads) {
220
- promises.push((async () => {
221
- try {
222
- await thread.continue();
223
- }
224
- catch (e) {
225
- console.error('continueAll failed:', e);
226
- }
227
- })());
228
- }
229
- await Promise.all(promises);
230
- }
231
- get currentFrame() {
232
- return this.currentThread && this.currentThread.currentFrame;
233
- }
234
- get currentThread() {
235
- return this._currentThread;
236
- }
237
- set currentThread(thread) {
238
- this.toDisposeOnCurrentThread.dispose();
239
- this._currentThread = thread;
240
- this.fireDidChange();
241
- if (thread) {
242
- this.toDisposeOnCurrentThread.push(thread.onDidChanged(() => this.fireDidChange()));
243
- this.toDisposeOnCurrentThread.push(thread.onDidFocusStackFrame(frame => this.onDidFocusStackFrameEmitter.fire(frame)));
244
- // If this thread is missing stack frame information, then load that.
245
- this.updateFrames();
246
- }
247
- }
248
- get state() {
249
- if (this.connection.disposed) {
250
- return DebugState.Inactive;
251
- }
252
- if (!this.initialized) {
253
- return DebugState.Initializing;
254
- }
255
- const thread = this.currentThread;
256
- if (thread) {
257
- return thread.stopped ? DebugState.Stopped : DebugState.Running;
258
- }
259
- return !!this.stoppedThreads.next().value ? DebugState.Stopped : DebugState.Running;
260
- }
261
- async getScopes() {
262
- const { currentFrame } = this;
263
- return currentFrame ? currentFrame.getScopes() : [];
264
- }
265
- async start() {
266
- await this.initialize();
267
- await this.launchOrAttach();
268
- }
269
- async initialize() {
270
- try {
271
- const response = await this.connection.sendRequest('initialize', {
272
- clientID: 'Theia',
273
- clientName: 'Theia IDE',
274
- adapterID: this.configuration.type,
275
- locale: 'en-US',
276
- linesStartAt1: true,
277
- columnsStartAt1: true,
278
- pathFormat: 'path',
279
- supportsVariableType: false,
280
- supportsVariablePaging: false,
281
- supportsRunInTerminalRequest: true
282
- });
283
- this.updateCapabilities((response === null || response === void 0 ? void 0 : response.body) || {});
284
- this.didReceiveCapabilities.resolve();
285
- }
286
- catch (err) {
287
- this.didReceiveCapabilities.reject(err);
288
- throw err;
289
- }
290
- }
291
- async launchOrAttach() {
292
- try {
293
- await this.sendRequest(this.configuration.request, this.configuration);
294
- }
295
- catch (reason) {
296
- this.messages.showMessage({
297
- type: common_1.MessageType.Error,
298
- text: reason.message || 'Debug session initialization failed. See console for details.',
299
- options: {
300
- timeout: 10000
301
- }
302
- });
303
- throw reason;
304
- }
305
- }
306
- async configure() {
307
- await this.didReceiveCapabilities.promise;
308
- if (this.capabilities.exceptionBreakpointFilters) {
309
- const exceptionBreakpoints = [];
310
- for (const filter of this.capabilities.exceptionBreakpointFilters) {
311
- const origin = this.breakpoints.getExceptionBreakpoint(filter.filter);
312
- exceptionBreakpoints.push(breakpoint_marker_1.ExceptionBreakpoint.create(filter, origin));
313
- }
314
- this.breakpoints.setExceptionBreakpoints(exceptionBreakpoints);
315
- }
316
- await this.updateBreakpoints({ sourceModified: false });
317
- if (this.capabilities.supportsConfigurationDoneRequest) {
318
- await this.sendRequest('configurationDone', {});
319
- }
320
- this.initialized = true;
321
- await this.updateThreads(undefined);
322
- }
323
- canTerminate() {
324
- return !!this.capabilities.supportsTerminateRequest;
325
- }
326
- canRestart() {
327
- return !!this.capabilities.supportsRestartRequest;
328
- }
329
- async restart() {
330
- if (this.canRestart()) {
331
- await this.sendRequest('restart', {});
332
- }
333
- }
334
- async stop(isRestart, callback) {
335
- if (!this.isStopping) {
336
- this.isStopping = true;
337
- if (this.canTerminate()) {
338
- const terminated = this.waitFor('terminated', this.stopTimeout);
339
- try {
340
- await this.connection.sendRequest('terminate', { restart: isRestart }, this.stopTimeout);
341
- await terminated;
342
- }
343
- catch (e) {
344
- this.handleTerminateError(e);
345
- }
346
- }
347
- else {
348
- const terminateDebuggee = this.initialized && this.capabilities.supportTerminateDebuggee;
349
- try {
350
- await this.sendRequest('disconnect', { restart: isRestart, terminateDebuggee }, this.stopTimeout);
351
- }
352
- catch (e) {
353
- this.handleDisconnectError(e);
354
- }
355
- }
356
- callback();
357
- }
358
- }
359
- /**
360
- * Invoked when sending the `terminate` request to the debugger is rejected or timed out.
361
- */
362
- handleTerminateError(err) {
363
- console.error('Did not receive terminated event in time', err);
364
- }
365
- /**
366
- * Invoked when sending the `disconnect` request to the debugger is rejected or timed out.
367
- */
368
- handleDisconnectError(err) {
369
- console.error('Error on disconnect', err);
370
- }
371
- async disconnect(isRestart, callback) {
372
- if (!this.isStopping) {
373
- this.isStopping = true;
374
- await this.sendRequest('disconnect', { restart: isRestart });
375
- callback();
376
- }
377
- }
378
- async completions(text, column, line) {
379
- const frameId = this.currentFrame && this.currentFrame.raw.id;
380
- const response = await this.sendRequest('completions', { frameId, text, column, line });
381
- return response.body.targets;
382
- }
383
- async evaluate(expression, context) {
384
- const frameId = this.currentFrame && this.currentFrame.raw.id;
385
- const response = await this.sendRequest('evaluate', { expression, frameId, context });
386
- return response.body;
387
- }
388
- sendRequest(command, args, timeout) {
389
- return this.connection.sendRequest(command, args, timeout);
390
- }
391
- sendCustomRequest(command, args) {
392
- return this.connection.sendCustomRequest(command, args);
393
- }
394
- on(kind, listener) {
395
- return this.connection.on(kind, listener);
396
- }
397
- waitFor(kind, ms) {
398
- return (0, promise_util_1.waitForEvent)(this.connection.onEvent(kind), ms).then();
399
- }
400
- get onDidCustomEvent() {
401
- return this.connection.onDidCustomEvent;
402
- }
403
- async runInTerminal({ arguments: { title, cwd, args, env } }) {
404
- const terminal = await this.doCreateTerminal({ title, cwd, env, useServerTitle: false });
405
- const { processId } = terminal;
406
- await terminal.executeCommand({ cwd, args, env });
407
- return { processId: await processId };
408
- }
409
- async doCreateTerminal(options) {
410
- let terminal = undefined;
411
- for (const t of this.terminalServer.all) {
412
- if ((t.title.label === options.title || t.title.caption === options.title) && (await t.hasChildProcesses()) === false) {
413
- terminal = t;
414
- break;
415
- }
416
- }
417
- if (!terminal) {
418
- terminal = await this.terminalServer.newTerminal(options);
419
- await terminal.start();
420
- }
421
- this.terminalServer.open(terminal);
422
- return terminal;
423
- }
424
- clearThreads() {
425
- for (const thread of this.threads) {
426
- thread.clear();
427
- }
428
- this.updateCurrentThread();
429
- }
430
- clearThread(threadId) {
431
- const thread = this._threads.get(threadId);
432
- if (thread) {
433
- thread.clear();
434
- }
435
- this.updateCurrentThread();
436
- }
437
- updateThreads(stoppedDetails) {
438
- return this.pendingThreads = this.pendingThreads.then(async () => {
439
- try {
440
- const response = await this.sendRequest('threads', {});
441
- // java debugger returns an empty body sometimes
442
- const threads = response && response.body && response.body.threads || [];
443
- this.doUpdateThreads(threads, stoppedDetails);
444
- }
445
- catch (e) {
446
- console.error('updateThreads failed:', e);
447
- }
448
- });
449
- }
450
- doUpdateThreads(threads, stoppedDetails) {
451
- const existing = this._threads;
452
- this._threads = new Map();
453
- for (const raw of threads) {
454
- const id = raw.id;
455
- const thread = existing.get(id) || new debug_thread_1.DebugThread(this);
456
- this._threads.set(id, thread);
457
- const data = { raw };
458
- if (stoppedDetails) {
459
- if (stoppedDetails.threadId === id) {
460
- data.stoppedDetails = stoppedDetails;
461
- }
462
- else if (stoppedDetails.allThreadsStopped) {
463
- data.stoppedDetails = {
464
- // When a debug adapter notifies us that all threads are stopped,
465
- // we do not know why the others are stopped, so we should default
466
- // to something generic.
467
- reason: '',
468
- };
469
- }
470
- }
471
- thread.update(data);
472
- }
473
- this.updateCurrentThread(stoppedDetails);
474
- }
475
- updateCurrentThread(stoppedDetails) {
476
- const { currentThread } = this;
477
- let threadId = currentThread && currentThread.raw.id;
478
- if (stoppedDetails && !stoppedDetails.preserveFocusHint && !!stoppedDetails.threadId) {
479
- threadId = stoppedDetails.threadId;
480
- }
481
- this.currentThread = typeof threadId === 'number' && this._threads.get(threadId)
482
- || this._threads.values().next().value;
483
- }
484
- async updateFrames() {
485
- const thread = this._currentThread;
486
- if (!thread || thread.pendingFrameCount || thread.frameCount) {
487
- return;
488
- }
489
- if (this.capabilities.supportsDelayedStackTraceLoading) {
490
- await thread.fetchFrames(1);
491
- await thread.fetchFrames(19);
492
- }
493
- else {
494
- await thread.fetchFrames();
495
- }
496
- }
497
- updateCapabilities(capabilities) {
498
- Object.assign(this._capabilities, capabilities);
499
- this.deferredOnDidConfigureCapabilities.resolve();
500
- }
501
- get breakpointUris() {
502
- return this._breakpoints.keys();
503
- }
504
- getSourceBreakpoints(uri) {
505
- const breakpoints = [];
506
- for (const breakpoint of this.getBreakpoints(uri)) {
507
- if (breakpoint instanceof debug_source_breakpoint_1.DebugSourceBreakpoint) {
508
- breakpoints.push(breakpoint);
509
- }
510
- }
511
- return breakpoints;
512
- }
513
- getFunctionBreakpoints() {
514
- return this.getBreakpoints(breakpoint_manager_1.BreakpointManager.FUNCTION_URI).filter((breakpoint) => breakpoint instanceof debug_function_breakpoint_1.DebugFunctionBreakpoint);
515
- }
516
- getInstructionBreakpoints() {
517
- if (this.capabilities.supportsInstructionBreakpoints) {
518
- return this.getBreakpoints(breakpoint_manager_1.BreakpointManager.INSTRUCTION_URI)
519
- .filter((breakpoint) => breakpoint instanceof debug_instruction_breakpoint_1.DebugInstructionBreakpoint);
520
- }
521
- return this.breakpoints.getInstructionBreakpoints().map(origin => new debug_instruction_breakpoint_1.DebugInstructionBreakpoint(origin, this.asDebugBreakpointOptions()));
522
- }
523
- getBreakpoints(uri) {
524
- if (uri) {
525
- return this._breakpoints.get(uri.toString()) || [];
526
- }
527
- const result = [];
528
- for (const breakpoints of this._breakpoints.values()) {
529
- result.push(...breakpoints);
530
- }
531
- return result;
532
- }
533
- getBreakpoint(id) {
534
- for (const breakpoints of this._breakpoints.values()) {
535
- const breakpoint = breakpoints.find(b => b.id === id);
536
- if (breakpoint) {
537
- return breakpoint;
538
- }
539
- }
540
- return undefined;
541
- }
542
- clearBreakpoints() {
543
- const uris = [...this._breakpoints.keys()];
544
- this._breakpoints.clear();
545
- for (const uri of uris) {
546
- this.fireDidChangeBreakpoints(new uri_1.default(uri));
547
- }
548
- }
549
- updateBreakpoint(body) {
550
- this.updatingBreakpoints = true;
551
- try {
552
- const raw = body.breakpoint;
553
- if (body.reason === 'new') {
554
- if (raw.source && typeof raw.line === 'number') {
555
- const uri = debug_source_1.DebugSource.toUri(raw.source);
556
- const origin = breakpoint_marker_1.SourceBreakpoint.create(uri, { line: raw.line, column: raw.column });
557
- if (this.breakpoints.addBreakpoint(origin)) {
558
- const breakpoints = this.getSourceBreakpoints(uri);
559
- const breakpoint = new debug_source_breakpoint_1.DebugSourceBreakpoint(origin, this.asDebugBreakpointOptions());
560
- breakpoint.update({ raw });
561
- breakpoints.push(breakpoint);
562
- this.setSourceBreakpoints(uri, breakpoints);
563
- }
564
- }
565
- }
566
- if (body.reason === 'removed' && raw.id) {
567
- const toRemove = this.findBreakpoint(b => b.idFromAdapter === raw.id);
568
- if (toRemove) {
569
- toRemove.remove();
570
- const breakpoints = this.getBreakpoints(toRemove.uri);
571
- const index = breakpoints.indexOf(toRemove);
572
- if (index !== -1) {
573
- breakpoints.splice(index, 1);
574
- this.setBreakpoints(toRemove.uri, breakpoints);
575
- }
576
- }
577
- }
578
- if (body.reason === 'changed' && raw.id) {
579
- const toUpdate = this.findBreakpoint(b => b.idFromAdapter === raw.id);
580
- if (toUpdate) {
581
- toUpdate.update({ raw });
582
- if (toUpdate instanceof debug_source_breakpoint_1.DebugSourceBreakpoint) {
583
- const sourceBreakpoints = this.getSourceBreakpoints(toUpdate.uri);
584
- // in order to dedup again if a debugger converted line breakpoint to inline breakpoint
585
- // i.e. assigned a column to a line breakpoint
586
- this.setSourceBreakpoints(toUpdate.uri, sourceBreakpoints);
587
- }
588
- else {
589
- this.fireDidChangeBreakpoints(toUpdate.uri);
590
- }
591
- }
592
- }
593
- }
594
- finally {
595
- this.updatingBreakpoints = false;
596
- }
597
- }
598
- findBreakpoint(match) {
599
- for (const [, breakpoints] of this._breakpoints) {
600
- for (const breakpoint of breakpoints) {
601
- if (match(breakpoint)) {
602
- return breakpoint;
603
- }
604
- }
605
- }
606
- return undefined;
607
- }
608
- async updateBreakpoints(options) {
609
- if (this.updatingBreakpoints) {
610
- return;
611
- }
612
- const { uri, sourceModified } = options;
613
- await this.deferredOnDidConfigureCapabilities.promise;
614
- for (const affectedUri of this.getAffectedUris(uri)) {
615
- if (affectedUri.toString() === breakpoint_manager_1.BreakpointManager.EXCEPTION_URI.toString()) {
616
- await this.sendExceptionBreakpoints();
617
- }
618
- else if (affectedUri.toString() === breakpoint_manager_1.BreakpointManager.FUNCTION_URI.toString()) {
619
- await this.sendFunctionBreakpoints(affectedUri);
620
- }
621
- else if (affectedUri.toString() === breakpoint_manager_1.BreakpointManager.INSTRUCTION_URI.toString()) {
622
- await this.sendInstructionBreakpoints();
623
- }
624
- else {
625
- await this.sendSourceBreakpoints(affectedUri, sourceModified);
626
- }
627
- }
628
- }
629
- async sendExceptionBreakpoints() {
630
- const filters = [];
631
- const filterOptions = this.capabilities.supportsExceptionFilterOptions ? [] : undefined;
632
- for (const breakpoint of this.breakpoints.getExceptionBreakpoints()) {
633
- if (breakpoint.enabled) {
634
- if (filterOptions) {
635
- filterOptions.push({
636
- filterId: breakpoint.raw.filter,
637
- condition: breakpoint.condition
638
- });
639
- }
640
- else {
641
- filters.push(breakpoint.raw.filter);
642
- }
643
- }
644
- }
645
- await this.sendRequest('setExceptionBreakpoints', { filters, filterOptions });
646
- }
647
- async sendFunctionBreakpoints(affectedUri) {
648
- const all = this.breakpoints.getFunctionBreakpoints().map(origin => new debug_function_breakpoint_1.DebugFunctionBreakpoint(origin, this.asDebugBreakpointOptions()));
649
- const enabled = all.filter(b => b.enabled);
650
- if (this.capabilities.supportsFunctionBreakpoints) {
651
- try {
652
- const response = await this.sendRequest('setFunctionBreakpoints', {
653
- breakpoints: enabled.map(b => b.origin.raw)
654
- });
655
- // Apparently, `body` and `breakpoints` can be missing.
656
- // https://github.com/eclipse-theia/theia/issues/11885
657
- // https://github.com/microsoft/vscode/blob/80004351ccf0884b58359f7c8c801c91bb827d83/src/vs/workbench/contrib/debug/browser/debugSession.ts#L448-L449
658
- if (response && response.body) {
659
- response.body.breakpoints.forEach((raw, index) => {
660
- // node debug adapter returns more breakpoints sometimes
661
- if (enabled[index]) {
662
- enabled[index].update({ raw });
663
- }
664
- });
665
- }
666
- }
667
- catch (error) {
668
- // could be error or promise rejection of DebugProtocol.SetFunctionBreakpoints
669
- if (error instanceof Error) {
670
- console.error(`Error setting breakpoints: ${error.message}`);
671
- }
672
- else {
673
- // handle adapters that send failed DebugProtocol.SetFunctionBreakpoints for invalid breakpoints
674
- const genericMessage = 'Function breakpoint not valid for current debug session';
675
- const message = error.message ? `${error.message}` : genericMessage;
676
- console.warn(`Could not handle function breakpoints: ${message}, disabling...`);
677
- enabled.forEach(b => b.update({
678
- raw: {
679
- verified: false,
680
- message
681
- }
682
- }));
683
- }
684
- }
685
- }
686
- this.setBreakpoints(affectedUri, all);
687
- }
688
- async sendSourceBreakpoints(affectedUri, sourceModified) {
689
- const source = await this.toSource(affectedUri);
690
- const all = this.breakpoints.findMarkers({ uri: affectedUri }).map(({ data }) => new debug_source_breakpoint_1.DebugSourceBreakpoint(data, this.asDebugBreakpointOptions()));
691
- const enabled = all.filter(b => b.enabled);
692
- try {
693
- const breakpoints = enabled.map(({ origin }) => origin.raw);
694
- const response = await this.sendRequest('setBreakpoints', {
695
- source: source.raw,
696
- sourceModified,
697
- breakpoints,
698
- lines: breakpoints.map(({ line }) => line)
699
- });
700
- response.body.breakpoints.forEach((raw, index) => {
701
- // node debug adapter returns more breakpoints sometimes
702
- if (enabled[index]) {
703
- enabled[index].update({ raw });
704
- }
705
- });
706
- }
707
- catch (error) {
708
- // could be error or promise rejection of DebugProtocol.SetBreakpointsResponse
709
- if (error instanceof Error) {
710
- console.error(`Error setting breakpoints: ${error.message}`);
711
- }
712
- else {
713
- // handle adapters that send failed DebugProtocol.SetBreakpointsResponse for invalid breakpoints
714
- const genericMessage = 'Breakpoint not valid for current debug session';
715
- const message = error.message ? `${error.message}` : genericMessage;
716
- console.warn(`Could not handle breakpoints for ${affectedUri}: ${message}, disabling...`);
717
- enabled.forEach(b => b.update({
718
- raw: {
719
- verified: false,
720
- message
721
- }
722
- }));
723
- }
724
- }
725
- this.setSourceBreakpoints(affectedUri, all);
726
- }
727
- async sendInstructionBreakpoints() {
728
- if (!this.capabilities.supportsInstructionBreakpoints) {
729
- return;
730
- }
731
- const all = this.breakpoints.getInstructionBreakpoints().map(breakpoint => new debug_instruction_breakpoint_1.DebugInstructionBreakpoint(breakpoint, this.asDebugBreakpointOptions()));
732
- const enabled = all.filter(breakpoint => breakpoint.enabled);
733
- try {
734
- const response = await this.sendRequest('setInstructionBreakpoints', {
735
- breakpoints: enabled.map(renderable => renderable.origin),
736
- });
737
- response.body.breakpoints.forEach((raw, index) => { var _a; return (_a = enabled[index]) === null || _a === void 0 ? void 0 : _a.update({ raw }); });
738
- }
739
- catch {
740
- enabled.forEach(breakpoint => breakpoint.update({ raw: { verified: false } }));
741
- }
742
- this.setBreakpoints(breakpoint_manager_1.BreakpointManager.INSTRUCTION_URI, all);
743
- }
744
- setBreakpoints(uri, breakpoints) {
745
- this._breakpoints.set(uri.toString(), breakpoints);
746
- this.fireDidChangeBreakpoints(uri);
747
- }
748
- setSourceBreakpoints(uri, breakpoints) {
749
- const distinct = this.dedupSourceBreakpoints(breakpoints);
750
- this.setBreakpoints(uri, distinct);
751
- }
752
- dedupSourceBreakpoints(all) {
753
- const positions = new Map();
754
- for (const breakpoint of all) {
755
- let primary = positions.get(breakpoint.renderPosition()) || breakpoint;
756
- if (primary !== breakpoint) {
757
- let secondary = breakpoint;
758
- if (secondary.raw && secondary.raw.line === secondary.origin.raw.line && secondary.raw.column === secondary.origin.raw.column) {
759
- [primary, secondary] = [breakpoint, primary];
760
- }
761
- primary.origins.push(...secondary.origins);
762
- }
763
- positions.set(primary.renderPosition(), primary);
764
- }
765
- return [...positions.values()];
766
- }
767
- *getAffectedUris(uri) {
768
- if (uri) {
769
- yield uri;
770
- }
771
- else {
772
- for (const uriString of this.breakpoints.getUris()) {
773
- yield new uri_1.default(uriString);
774
- }
775
- yield breakpoint_manager_1.BreakpointManager.FUNCTION_URI;
776
- yield breakpoint_manager_1.BreakpointManager.EXCEPTION_URI;
777
- }
778
- }
779
- asDebugBreakpointOptions() {
780
- const { labelProvider, breakpoints, editorManager } = this;
781
- return { labelProvider, breakpoints, editorManager, session: this };
782
- }
783
- get label() {
784
- const suffixes = [];
785
- if (debug_session_options_1.InternalDebugSessionOptions.is(this.options) && this.options.id) {
786
- suffixes.push(String(this.options.id + 1));
787
- }
788
- if (this.workspaceService.isMultiRootWorkspaceOpened && this.options.workspaceFolderUri) {
789
- suffixes.push(this.labelProvider.getName(new uri_1.default(this.options.workspaceFolderUri)));
790
- }
791
- return suffixes.length === 0 ? this.configuration.name : this.configuration.name + ` (${suffixes.join(' - ')})`;
792
- }
793
- get visible() {
794
- return this.state > DebugState.Inactive;
795
- }
796
- render() {
797
- let label = '';
798
- const state = this.state === DebugState.Stopped ? core_1.nls.localizeByDefault('Paused') : core_1.nls.localizeByDefault('Running');
799
- const child = this.getSingleChildSession();
800
- if (child && child.configuration.compact) {
801
- // Inlines the name of the child debug session
802
- label = `: ${child.label}`;
803
- }
804
- return React.createElement("div", { className: 'theia-debug-session', title: 'Session' },
805
- React.createElement("span", { className: 'label' }, this.label + label),
806
- React.createElement("span", { className: 'status' }, state));
807
- }
808
- *getElements() {
809
- const child = this.getSingleChildSession();
810
- if (child && child.configuration.compact) {
811
- // Inlines the elements of the child debug session
812
- return yield* child.getElements();
813
- }
814
- yield* this.threads;
815
- yield* this.childSessions.values();
816
- }
817
- getSingleChildSession() {
818
- if (this._threads.size === 0 && this.childSessions.size === 1) {
819
- const child = this.childSessions.values().next().value;
820
- return child;
821
- }
822
- return undefined;
823
- }
824
- async handleContinued({ body: { allThreadsContinued, threadId } }) {
825
- if (allThreadsContinued !== false) {
826
- this.clearThreads();
827
- }
828
- else {
829
- this.clearThread(threadId);
830
- }
831
- }
832
- ;
833
- async handleStopped({ body }) {
834
- // Update thread list
835
- await this.updateThreads(body);
836
- // Update current thread's frames immediately
837
- await this.updateFrames();
838
- }
839
- ;
840
- async handleThread({ body: { reason, threadId } }) {
841
- if (reason === 'started') {
842
- this.scheduleUpdateThreads();
843
- }
844
- else if (reason === 'exited') {
845
- this._threads.delete(threadId);
846
- this.updateCurrentThread();
847
- }
848
- }
849
- ;
850
- registerDebugContributions(configType, connection) {
851
- for (const contrib of this.debugContributionProvider.getContributions()) {
852
- contrib.register(configType, connection);
853
- }
854
- }
855
- ;
856
- /**
857
- * Returns the top-most parent session that is responsible for the console. If this session uses a {@link DebugConsoleMode.Separate separate console}
858
- * or does not have any parent session, undefined is returned.
859
- */
860
- findConsoleParent() {
861
- if (this.configuration.consoleMode !== debug_common_1.DebugConsoleMode.MergeWithParent) {
862
- return undefined;
863
- }
864
- let debugSession = this;
865
- do {
866
- debugSession = debugSession.parentSession;
867
- } while ((debugSession === null || debugSession === void 0 ? void 0 : debugSession.parentSession) && debugSession.configuration.consoleMode === debug_common_1.DebugConsoleMode.MergeWithParent);
868
- return debugSession;
869
- }
870
- }
871
- exports.DebugSession = DebugSession;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2018 Red Hat, Inc. and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.DebugSession = exports.debugStateContextValue = exports.DebugState = void 0;
19
+ /* eslint-disable @typescript-eslint/no-explicit-any */
20
+ const React = require("@theia/core/shared/react");
21
+ const common_1 = require("@theia/core/lib/common");
22
+ const debug_thread_1 = require("./model/debug-thread");
23
+ const debug_source_1 = require("./model/debug-source");
24
+ const debug_source_breakpoint_1 = require("./model/debug-source-breakpoint");
25
+ const debounce = require("p-debounce");
26
+ const uri_1 = require("@theia/core/lib/common/uri");
27
+ const breakpoint_manager_1 = require("./breakpoint/breakpoint-manager");
28
+ const debug_session_options_1 = require("./debug-session-options");
29
+ const debug_common_1 = require("../common/debug-common");
30
+ const breakpoint_marker_1 = require("./breakpoint/breakpoint-marker");
31
+ const debug_function_breakpoint_1 = require("./model/debug-function-breakpoint");
32
+ const promise_util_1 = require("@theia/core/lib/common/promise-util");
33
+ const debug_instruction_breakpoint_1 = require("./model/debug-instruction-breakpoint");
34
+ const core_1 = require("@theia/core");
35
+ var DebugState;
36
+ (function (DebugState) {
37
+ DebugState[DebugState["Inactive"] = 0] = "Inactive";
38
+ DebugState[DebugState["Initializing"] = 1] = "Initializing";
39
+ DebugState[DebugState["Running"] = 2] = "Running";
40
+ DebugState[DebugState["Stopped"] = 3] = "Stopped";
41
+ })(DebugState = exports.DebugState || (exports.DebugState = {}));
42
+ /**
43
+ * The mapped string values must not change as they are used for the `debugState` when context closure.
44
+ * For more details see the `Debugger contexts` section of the [official doc](https://code.visualstudio.com/api/references/when-clause-contexts#available-contexts).
45
+ */
46
+ function debugStateContextValue(state) {
47
+ switch (state) {
48
+ case DebugState.Initializing: return 'initializing';
49
+ case DebugState.Stopped: return 'stopped';
50
+ case DebugState.Running: return 'running';
51
+ default: return 'inactive';
52
+ }
53
+ }
54
+ exports.debugStateContextValue = debugStateContextValue;
55
+ // FIXME: make injectable to allow easily inject services
56
+ class DebugSession {
57
+ constructor(id, options, parentSession, connection, terminalServer, editorManager, breakpoints, labelProvider, messages, fileService, debugContributionProvider, workspaceService,
58
+ /**
59
+ * Number of millis after a `stop` request times out. It's 5 seconds by default.
60
+ */
61
+ stopTimeout = 5000) {
62
+ this.id = id;
63
+ this.options = options;
64
+ this.parentSession = parentSession;
65
+ this.connection = connection;
66
+ this.terminalServer = terminalServer;
67
+ this.editorManager = editorManager;
68
+ this.breakpoints = breakpoints;
69
+ this.labelProvider = labelProvider;
70
+ this.messages = messages;
71
+ this.fileService = fileService;
72
+ this.debugContributionProvider = debugContributionProvider;
73
+ this.workspaceService = workspaceService;
74
+ this.stopTimeout = stopTimeout;
75
+ this.deferredOnDidConfigureCapabilities = new promise_util_1.Deferred();
76
+ this.onDidChangeEmitter = new common_1.Emitter();
77
+ this.onDidChange = this.onDidChangeEmitter.event;
78
+ this.onDidFocusStackFrameEmitter = new common_1.Emitter();
79
+ this.onDidChangeBreakpointsEmitter = new common_1.Emitter();
80
+ this.onDidChangeBreakpoints = this.onDidChangeBreakpointsEmitter.event;
81
+ this.childSessions = new Map();
82
+ this.toDispose = new common_1.DisposableCollection();
83
+ this.isStopping = false;
84
+ this._capabilities = {};
85
+ this.sources = new Map();
86
+ this._threads = new Map();
87
+ this.toDisposeOnCurrentThread = new common_1.DisposableCollection();
88
+ /**
89
+ * The `send('initialize')` request could resolve later than `on('initialized')` emits the event.
90
+ * Hence, the `configure` would use the empty object `capabilities`.
91
+ * Using the empty `capabilities` could result in missing exception breakpoint filters, as
92
+ * always `capabilities.exceptionBreakpointFilters` is falsy. This deferred promise works
93
+ * around this timing issue. https://github.com/eclipse-theia/theia/issues/11886
94
+ */
95
+ this.didReceiveCapabilities = new promise_util_1.Deferred();
96
+ this.initialized = false;
97
+ this.scheduleUpdateThreads = debounce(() => this.updateThreads(undefined), 100);
98
+ this.pendingThreads = Promise.resolve();
99
+ this._breakpoints = new Map();
100
+ this.updatingBreakpoints = false;
101
+ this.connection.onRequest('runInTerminal', (request) => this.runInTerminal(request));
102
+ this.connection.onDidClose(() => {
103
+ this.toDispose.dispose();
104
+ });
105
+ this.registerDebugContributions(options.configuration.type, this.connection);
106
+ if (parentSession) {
107
+ parentSession.childSessions.set(id, this);
108
+ this.toDispose.push(common_1.Disposable.create(() => {
109
+ var _a, _b;
110
+ (_b = (_a = this.parentSession) === null || _a === void 0 ? void 0 : _a.childSessions) === null || _b === void 0 ? void 0 : _b.delete(id);
111
+ }));
112
+ }
113
+ this.connection.onDidClose(() => this.toDispose.dispose());
114
+ this.toDispose.pushAll([
115
+ this.onDidChangeEmitter,
116
+ this.onDidChangeBreakpointsEmitter,
117
+ common_1.Disposable.create(() => {
118
+ this.clearBreakpoints();
119
+ this.doUpdateThreads([]);
120
+ }),
121
+ this.connection,
122
+ this.connection.on('initialized', () => this.configure()),
123
+ this.connection.on('breakpoint', ({ body }) => this.updateBreakpoint(body)),
124
+ this.connection.on('continued', e => this.handleContinued(e)),
125
+ this.connection.on('stopped', e => this.handleStopped(e)),
126
+ this.connection.on('thread', e => this.handleThread(e)),
127
+ this.connection.on('capabilities', event => this.updateCapabilities(event.body.capabilities)),
128
+ this.breakpoints.onDidChangeMarkers(uri => this.updateBreakpoints({ uri, sourceModified: true }))
129
+ ]);
130
+ }
131
+ fireDidChange() {
132
+ this.onDidChangeEmitter.fire(undefined);
133
+ }
134
+ get onDidFocusStackFrame() {
135
+ return this.onDidFocusStackFrameEmitter.event;
136
+ }
137
+ fireDidChangeBreakpoints(uri) {
138
+ this.onDidChangeBreakpointsEmitter.fire(uri);
139
+ }
140
+ get onDispose() {
141
+ return this.toDispose.onDispose;
142
+ }
143
+ get configuration() {
144
+ return this.options.configuration;
145
+ }
146
+ get capabilities() {
147
+ return this._capabilities;
148
+ }
149
+ getSource(raw) {
150
+ const uri = debug_source_1.DebugSource.toUri(raw).toString();
151
+ const source = this.sources.get(uri) || new debug_source_1.DebugSource(this, this.editorManager, this.labelProvider);
152
+ source.update({ raw });
153
+ this.sources.set(uri, source);
154
+ return source;
155
+ }
156
+ getSourceForUri(uri) {
157
+ return this.sources.get(uri.toString());
158
+ }
159
+ async toSource(uri) {
160
+ const source = this.getSourceForUri(uri);
161
+ if (source) {
162
+ return source;
163
+ }
164
+ return this.getSource(await this.toDebugSource(uri));
165
+ }
166
+ async toDebugSource(uri) {
167
+ if (uri.scheme === debug_source_1.DebugSource.SCHEME) {
168
+ return {
169
+ name: uri.path.toString(),
170
+ sourceReference: Number(uri.query)
171
+ };
172
+ }
173
+ const name = uri.displayName;
174
+ let path;
175
+ const underlying = await this.fileService.toUnderlyingResource(uri);
176
+ if (underlying.scheme === 'file') {
177
+ path = await this.fileService.fsPath(underlying);
178
+ }
179
+ else {
180
+ path = uri.toString();
181
+ }
182
+ return { name, path };
183
+ }
184
+ get threads() {
185
+ return this._threads.values();
186
+ }
187
+ get threadCount() {
188
+ return this._threads.size;
189
+ }
190
+ *getThreads(filter) {
191
+ for (const thread of this.threads) {
192
+ if (filter(thread)) {
193
+ yield thread;
194
+ }
195
+ }
196
+ }
197
+ get runningThreads() {
198
+ return this.getThreads(thread => !thread.stopped);
199
+ }
200
+ get stoppedThreads() {
201
+ return this.getThreads(thread => thread.stopped);
202
+ }
203
+ async pauseAll() {
204
+ const promises = [];
205
+ for (const thread of this.runningThreads) {
206
+ promises.push((async () => {
207
+ try {
208
+ await thread.pause();
209
+ }
210
+ catch (e) {
211
+ console.error('pauseAll failed:', e);
212
+ }
213
+ })());
214
+ }
215
+ await Promise.all(promises);
216
+ }
217
+ async continueAll() {
218
+ const promises = [];
219
+ for (const thread of this.stoppedThreads) {
220
+ promises.push((async () => {
221
+ try {
222
+ await thread.continue();
223
+ }
224
+ catch (e) {
225
+ console.error('continueAll failed:', e);
226
+ }
227
+ })());
228
+ }
229
+ await Promise.all(promises);
230
+ }
231
+ get currentFrame() {
232
+ return this.currentThread && this.currentThread.currentFrame;
233
+ }
234
+ get currentThread() {
235
+ return this._currentThread;
236
+ }
237
+ set currentThread(thread) {
238
+ this.toDisposeOnCurrentThread.dispose();
239
+ this._currentThread = thread;
240
+ this.fireDidChange();
241
+ if (thread) {
242
+ this.toDisposeOnCurrentThread.push(thread.onDidChanged(() => this.fireDidChange()));
243
+ this.toDisposeOnCurrentThread.push(thread.onDidFocusStackFrame(frame => this.onDidFocusStackFrameEmitter.fire(frame)));
244
+ // If this thread is missing stack frame information, then load that.
245
+ this.updateFrames();
246
+ }
247
+ }
248
+ get state() {
249
+ if (this.connection.disposed) {
250
+ return DebugState.Inactive;
251
+ }
252
+ if (!this.initialized) {
253
+ return DebugState.Initializing;
254
+ }
255
+ const thread = this.currentThread;
256
+ if (thread) {
257
+ return thread.stopped ? DebugState.Stopped : DebugState.Running;
258
+ }
259
+ return !!this.stoppedThreads.next().value ? DebugState.Stopped : DebugState.Running;
260
+ }
261
+ async getScopes() {
262
+ const { currentFrame } = this;
263
+ return currentFrame ? currentFrame.getScopes() : [];
264
+ }
265
+ async start() {
266
+ await this.initialize();
267
+ await this.launchOrAttach();
268
+ }
269
+ async initialize() {
270
+ try {
271
+ const response = await this.connection.sendRequest('initialize', {
272
+ clientID: 'Theia',
273
+ clientName: 'Theia IDE',
274
+ adapterID: this.configuration.type,
275
+ locale: 'en-US',
276
+ linesStartAt1: true,
277
+ columnsStartAt1: true,
278
+ pathFormat: 'path',
279
+ supportsVariableType: false,
280
+ supportsVariablePaging: false,
281
+ supportsRunInTerminalRequest: true
282
+ });
283
+ this.updateCapabilities((response === null || response === void 0 ? void 0 : response.body) || {});
284
+ this.didReceiveCapabilities.resolve();
285
+ }
286
+ catch (err) {
287
+ this.didReceiveCapabilities.reject(err);
288
+ throw err;
289
+ }
290
+ }
291
+ async launchOrAttach() {
292
+ try {
293
+ await this.sendRequest(this.configuration.request, this.configuration);
294
+ }
295
+ catch (reason) {
296
+ this.messages.showMessage({
297
+ type: common_1.MessageType.Error,
298
+ text: reason.message || 'Debug session initialization failed. See console for details.',
299
+ options: {
300
+ timeout: 10000
301
+ }
302
+ });
303
+ throw reason;
304
+ }
305
+ }
306
+ async configure() {
307
+ await this.didReceiveCapabilities.promise;
308
+ if (this.capabilities.exceptionBreakpointFilters) {
309
+ const exceptionBreakpoints = [];
310
+ for (const filter of this.capabilities.exceptionBreakpointFilters) {
311
+ const origin = this.breakpoints.getExceptionBreakpoint(filter.filter);
312
+ exceptionBreakpoints.push(breakpoint_marker_1.ExceptionBreakpoint.create(filter, origin));
313
+ }
314
+ this.breakpoints.setExceptionBreakpoints(exceptionBreakpoints);
315
+ }
316
+ await this.updateBreakpoints({ sourceModified: false });
317
+ if (this.capabilities.supportsConfigurationDoneRequest) {
318
+ await this.sendRequest('configurationDone', {});
319
+ }
320
+ this.initialized = true;
321
+ await this.updateThreads(undefined);
322
+ }
323
+ canTerminate() {
324
+ return !!this.capabilities.supportsTerminateRequest;
325
+ }
326
+ canRestart() {
327
+ return !!this.capabilities.supportsRestartRequest;
328
+ }
329
+ async restart() {
330
+ if (this.canRestart()) {
331
+ await this.sendRequest('restart', {});
332
+ }
333
+ }
334
+ async stop(isRestart, callback) {
335
+ if (!this.isStopping) {
336
+ this.isStopping = true;
337
+ if (this.canTerminate()) {
338
+ const terminated = this.waitFor('terminated', this.stopTimeout);
339
+ try {
340
+ await this.connection.sendRequest('terminate', { restart: isRestart }, this.stopTimeout);
341
+ await terminated;
342
+ }
343
+ catch (e) {
344
+ this.handleTerminateError(e);
345
+ }
346
+ }
347
+ else {
348
+ const terminateDebuggee = this.initialized && this.capabilities.supportTerminateDebuggee;
349
+ try {
350
+ await this.sendRequest('disconnect', { restart: isRestart, terminateDebuggee }, this.stopTimeout);
351
+ }
352
+ catch (e) {
353
+ this.handleDisconnectError(e);
354
+ }
355
+ }
356
+ callback();
357
+ }
358
+ }
359
+ /**
360
+ * Invoked when sending the `terminate` request to the debugger is rejected or timed out.
361
+ */
362
+ handleTerminateError(err) {
363
+ console.error('Did not receive terminated event in time', err);
364
+ }
365
+ /**
366
+ * Invoked when sending the `disconnect` request to the debugger is rejected or timed out.
367
+ */
368
+ handleDisconnectError(err) {
369
+ console.error('Error on disconnect', err);
370
+ }
371
+ async disconnect(isRestart, callback) {
372
+ if (!this.isStopping) {
373
+ this.isStopping = true;
374
+ await this.sendRequest('disconnect', { restart: isRestart });
375
+ callback();
376
+ }
377
+ }
378
+ async completions(text, column, line) {
379
+ const frameId = this.currentFrame && this.currentFrame.raw.id;
380
+ const response = await this.sendRequest('completions', { frameId, text, column, line });
381
+ return response.body.targets;
382
+ }
383
+ async evaluate(expression, context) {
384
+ const frameId = this.currentFrame && this.currentFrame.raw.id;
385
+ const response = await this.sendRequest('evaluate', { expression, frameId, context });
386
+ return response.body;
387
+ }
388
+ sendRequest(command, args, timeout) {
389
+ return this.connection.sendRequest(command, args, timeout);
390
+ }
391
+ sendCustomRequest(command, args) {
392
+ return this.connection.sendCustomRequest(command, args);
393
+ }
394
+ on(kind, listener) {
395
+ return this.connection.on(kind, listener);
396
+ }
397
+ waitFor(kind, ms) {
398
+ return (0, promise_util_1.waitForEvent)(this.connection.onEvent(kind), ms).then();
399
+ }
400
+ get onDidCustomEvent() {
401
+ return this.connection.onDidCustomEvent;
402
+ }
403
+ async runInTerminal({ arguments: { title, cwd, args, env } }) {
404
+ const terminal = await this.doCreateTerminal({ title, cwd, env, useServerTitle: false });
405
+ const { processId } = terminal;
406
+ await terminal.executeCommand({ cwd, args, env });
407
+ return { processId: await processId };
408
+ }
409
+ async doCreateTerminal(options) {
410
+ let terminal = undefined;
411
+ for (const t of this.terminalServer.all) {
412
+ if ((t.title.label === options.title || t.title.caption === options.title) && (await t.hasChildProcesses()) === false) {
413
+ terminal = t;
414
+ break;
415
+ }
416
+ }
417
+ if (!terminal) {
418
+ terminal = await this.terminalServer.newTerminal(options);
419
+ await terminal.start();
420
+ }
421
+ this.terminalServer.open(terminal);
422
+ return terminal;
423
+ }
424
+ clearThreads() {
425
+ for (const thread of this.threads) {
426
+ thread.clear();
427
+ }
428
+ this.updateCurrentThread();
429
+ }
430
+ clearThread(threadId) {
431
+ const thread = this._threads.get(threadId);
432
+ if (thread) {
433
+ thread.clear();
434
+ }
435
+ this.updateCurrentThread();
436
+ }
437
+ updateThreads(stoppedDetails) {
438
+ return this.pendingThreads = this.pendingThreads.then(async () => {
439
+ try {
440
+ const response = await this.sendRequest('threads', {});
441
+ // java debugger returns an empty body sometimes
442
+ const threads = response && response.body && response.body.threads || [];
443
+ this.doUpdateThreads(threads, stoppedDetails);
444
+ }
445
+ catch (e) {
446
+ console.error('updateThreads failed:', e);
447
+ }
448
+ });
449
+ }
450
+ doUpdateThreads(threads, stoppedDetails) {
451
+ const existing = this._threads;
452
+ this._threads = new Map();
453
+ for (const raw of threads) {
454
+ const id = raw.id;
455
+ const thread = existing.get(id) || new debug_thread_1.DebugThread(this);
456
+ this._threads.set(id, thread);
457
+ const data = { raw };
458
+ if (stoppedDetails) {
459
+ if (stoppedDetails.threadId === id) {
460
+ data.stoppedDetails = stoppedDetails;
461
+ }
462
+ else if (stoppedDetails.allThreadsStopped) {
463
+ data.stoppedDetails = {
464
+ // When a debug adapter notifies us that all threads are stopped,
465
+ // we do not know why the others are stopped, so we should default
466
+ // to something generic.
467
+ reason: '',
468
+ };
469
+ }
470
+ }
471
+ thread.update(data);
472
+ }
473
+ this.updateCurrentThread(stoppedDetails);
474
+ }
475
+ updateCurrentThread(stoppedDetails) {
476
+ const { currentThread } = this;
477
+ let threadId = currentThread && currentThread.raw.id;
478
+ if (stoppedDetails && !stoppedDetails.preserveFocusHint && !!stoppedDetails.threadId) {
479
+ threadId = stoppedDetails.threadId;
480
+ }
481
+ this.currentThread = typeof threadId === 'number' && this._threads.get(threadId)
482
+ || this._threads.values().next().value;
483
+ }
484
+ async updateFrames() {
485
+ const thread = this._currentThread;
486
+ if (!thread || thread.pendingFrameCount || thread.frameCount) {
487
+ return;
488
+ }
489
+ if (this.capabilities.supportsDelayedStackTraceLoading) {
490
+ await thread.fetchFrames(1);
491
+ await thread.fetchFrames(19);
492
+ }
493
+ else {
494
+ await thread.fetchFrames();
495
+ }
496
+ }
497
+ updateCapabilities(capabilities) {
498
+ Object.assign(this._capabilities, capabilities);
499
+ this.deferredOnDidConfigureCapabilities.resolve();
500
+ }
501
+ get breakpointUris() {
502
+ return this._breakpoints.keys();
503
+ }
504
+ getSourceBreakpoints(uri) {
505
+ const breakpoints = [];
506
+ for (const breakpoint of this.getBreakpoints(uri)) {
507
+ if (breakpoint instanceof debug_source_breakpoint_1.DebugSourceBreakpoint) {
508
+ breakpoints.push(breakpoint);
509
+ }
510
+ }
511
+ return breakpoints;
512
+ }
513
+ getFunctionBreakpoints() {
514
+ return this.getBreakpoints(breakpoint_manager_1.BreakpointManager.FUNCTION_URI).filter((breakpoint) => breakpoint instanceof debug_function_breakpoint_1.DebugFunctionBreakpoint);
515
+ }
516
+ getInstructionBreakpoints() {
517
+ if (this.capabilities.supportsInstructionBreakpoints) {
518
+ return this.getBreakpoints(breakpoint_manager_1.BreakpointManager.INSTRUCTION_URI)
519
+ .filter((breakpoint) => breakpoint instanceof debug_instruction_breakpoint_1.DebugInstructionBreakpoint);
520
+ }
521
+ return this.breakpoints.getInstructionBreakpoints().map(origin => new debug_instruction_breakpoint_1.DebugInstructionBreakpoint(origin, this.asDebugBreakpointOptions()));
522
+ }
523
+ getBreakpoints(uri) {
524
+ if (uri) {
525
+ return this._breakpoints.get(uri.toString()) || [];
526
+ }
527
+ const result = [];
528
+ for (const breakpoints of this._breakpoints.values()) {
529
+ result.push(...breakpoints);
530
+ }
531
+ return result;
532
+ }
533
+ getBreakpoint(id) {
534
+ for (const breakpoints of this._breakpoints.values()) {
535
+ const breakpoint = breakpoints.find(b => b.id === id);
536
+ if (breakpoint) {
537
+ return breakpoint;
538
+ }
539
+ }
540
+ return undefined;
541
+ }
542
+ clearBreakpoints() {
543
+ const uris = [...this._breakpoints.keys()];
544
+ this._breakpoints.clear();
545
+ for (const uri of uris) {
546
+ this.fireDidChangeBreakpoints(new uri_1.default(uri));
547
+ }
548
+ }
549
+ updateBreakpoint(body) {
550
+ this.updatingBreakpoints = true;
551
+ try {
552
+ const raw = body.breakpoint;
553
+ if (body.reason === 'new') {
554
+ if (raw.source && typeof raw.line === 'number') {
555
+ const uri = debug_source_1.DebugSource.toUri(raw.source);
556
+ const origin = breakpoint_marker_1.SourceBreakpoint.create(uri, { line: raw.line, column: raw.column });
557
+ if (this.breakpoints.addBreakpoint(origin)) {
558
+ const breakpoints = this.getSourceBreakpoints(uri);
559
+ const breakpoint = new debug_source_breakpoint_1.DebugSourceBreakpoint(origin, this.asDebugBreakpointOptions());
560
+ breakpoint.update({ raw });
561
+ breakpoints.push(breakpoint);
562
+ this.setSourceBreakpoints(uri, breakpoints);
563
+ }
564
+ }
565
+ }
566
+ if (body.reason === 'removed' && raw.id) {
567
+ const toRemove = this.findBreakpoint(b => b.idFromAdapter === raw.id);
568
+ if (toRemove) {
569
+ toRemove.remove();
570
+ const breakpoints = this.getBreakpoints(toRemove.uri);
571
+ const index = breakpoints.indexOf(toRemove);
572
+ if (index !== -1) {
573
+ breakpoints.splice(index, 1);
574
+ this.setBreakpoints(toRemove.uri, breakpoints);
575
+ }
576
+ }
577
+ }
578
+ if (body.reason === 'changed' && raw.id) {
579
+ const toUpdate = this.findBreakpoint(b => b.idFromAdapter === raw.id);
580
+ if (toUpdate) {
581
+ toUpdate.update({ raw });
582
+ if (toUpdate instanceof debug_source_breakpoint_1.DebugSourceBreakpoint) {
583
+ const sourceBreakpoints = this.getSourceBreakpoints(toUpdate.uri);
584
+ // in order to dedup again if a debugger converted line breakpoint to inline breakpoint
585
+ // i.e. assigned a column to a line breakpoint
586
+ this.setSourceBreakpoints(toUpdate.uri, sourceBreakpoints);
587
+ }
588
+ else {
589
+ this.fireDidChangeBreakpoints(toUpdate.uri);
590
+ }
591
+ }
592
+ }
593
+ }
594
+ finally {
595
+ this.updatingBreakpoints = false;
596
+ }
597
+ }
598
+ findBreakpoint(match) {
599
+ for (const [, breakpoints] of this._breakpoints) {
600
+ for (const breakpoint of breakpoints) {
601
+ if (match(breakpoint)) {
602
+ return breakpoint;
603
+ }
604
+ }
605
+ }
606
+ return undefined;
607
+ }
608
+ async updateBreakpoints(options) {
609
+ if (this.updatingBreakpoints) {
610
+ return;
611
+ }
612
+ const { uri, sourceModified } = options;
613
+ await this.deferredOnDidConfigureCapabilities.promise;
614
+ for (const affectedUri of this.getAffectedUris(uri)) {
615
+ if (affectedUri.toString() === breakpoint_manager_1.BreakpointManager.EXCEPTION_URI.toString()) {
616
+ await this.sendExceptionBreakpoints();
617
+ }
618
+ else if (affectedUri.toString() === breakpoint_manager_1.BreakpointManager.FUNCTION_URI.toString()) {
619
+ await this.sendFunctionBreakpoints(affectedUri);
620
+ }
621
+ else if (affectedUri.toString() === breakpoint_manager_1.BreakpointManager.INSTRUCTION_URI.toString()) {
622
+ await this.sendInstructionBreakpoints();
623
+ }
624
+ else {
625
+ await this.sendSourceBreakpoints(affectedUri, sourceModified);
626
+ }
627
+ }
628
+ }
629
+ async sendExceptionBreakpoints() {
630
+ const filters = [];
631
+ const filterOptions = this.capabilities.supportsExceptionFilterOptions ? [] : undefined;
632
+ for (const breakpoint of this.breakpoints.getExceptionBreakpoints()) {
633
+ if (breakpoint.enabled) {
634
+ if (filterOptions) {
635
+ filterOptions.push({
636
+ filterId: breakpoint.raw.filter,
637
+ condition: breakpoint.condition
638
+ });
639
+ }
640
+ else {
641
+ filters.push(breakpoint.raw.filter);
642
+ }
643
+ }
644
+ }
645
+ await this.sendRequest('setExceptionBreakpoints', { filters, filterOptions });
646
+ }
647
+ async sendFunctionBreakpoints(affectedUri) {
648
+ const all = this.breakpoints.getFunctionBreakpoints().map(origin => new debug_function_breakpoint_1.DebugFunctionBreakpoint(origin, this.asDebugBreakpointOptions()));
649
+ const enabled = all.filter(b => b.enabled);
650
+ if (this.capabilities.supportsFunctionBreakpoints) {
651
+ try {
652
+ const response = await this.sendRequest('setFunctionBreakpoints', {
653
+ breakpoints: enabled.map(b => b.origin.raw)
654
+ });
655
+ // Apparently, `body` and `breakpoints` can be missing.
656
+ // https://github.com/eclipse-theia/theia/issues/11885
657
+ // https://github.com/microsoft/vscode/blob/80004351ccf0884b58359f7c8c801c91bb827d83/src/vs/workbench/contrib/debug/browser/debugSession.ts#L448-L449
658
+ if (response && response.body) {
659
+ response.body.breakpoints.forEach((raw, index) => {
660
+ // node debug adapter returns more breakpoints sometimes
661
+ if (enabled[index]) {
662
+ enabled[index].update({ raw });
663
+ }
664
+ });
665
+ }
666
+ }
667
+ catch (error) {
668
+ // could be error or promise rejection of DebugProtocol.SetFunctionBreakpoints
669
+ if (error instanceof Error) {
670
+ console.error(`Error setting breakpoints: ${error.message}`);
671
+ }
672
+ else {
673
+ // handle adapters that send failed DebugProtocol.SetFunctionBreakpoints for invalid breakpoints
674
+ const genericMessage = 'Function breakpoint not valid for current debug session';
675
+ const message = error.message ? `${error.message}` : genericMessage;
676
+ console.warn(`Could not handle function breakpoints: ${message}, disabling...`);
677
+ enabled.forEach(b => b.update({
678
+ raw: {
679
+ verified: false,
680
+ message
681
+ }
682
+ }));
683
+ }
684
+ }
685
+ }
686
+ this.setBreakpoints(affectedUri, all);
687
+ }
688
+ async sendSourceBreakpoints(affectedUri, sourceModified) {
689
+ const source = await this.toSource(affectedUri);
690
+ const all = this.breakpoints.findMarkers({ uri: affectedUri }).map(({ data }) => new debug_source_breakpoint_1.DebugSourceBreakpoint(data, this.asDebugBreakpointOptions()));
691
+ const enabled = all.filter(b => b.enabled);
692
+ try {
693
+ const breakpoints = enabled.map(({ origin }) => origin.raw);
694
+ const response = await this.sendRequest('setBreakpoints', {
695
+ source: source.raw,
696
+ sourceModified,
697
+ breakpoints,
698
+ lines: breakpoints.map(({ line }) => line)
699
+ });
700
+ response.body.breakpoints.forEach((raw, index) => {
701
+ // node debug adapter returns more breakpoints sometimes
702
+ if (enabled[index]) {
703
+ enabled[index].update({ raw });
704
+ }
705
+ });
706
+ }
707
+ catch (error) {
708
+ // could be error or promise rejection of DebugProtocol.SetBreakpointsResponse
709
+ if (error instanceof Error) {
710
+ console.error(`Error setting breakpoints: ${error.message}`);
711
+ }
712
+ else {
713
+ // handle adapters that send failed DebugProtocol.SetBreakpointsResponse for invalid breakpoints
714
+ const genericMessage = 'Breakpoint not valid for current debug session';
715
+ const message = error.message ? `${error.message}` : genericMessage;
716
+ console.warn(`Could not handle breakpoints for ${affectedUri}: ${message}, disabling...`);
717
+ enabled.forEach(b => b.update({
718
+ raw: {
719
+ verified: false,
720
+ message
721
+ }
722
+ }));
723
+ }
724
+ }
725
+ this.setSourceBreakpoints(affectedUri, all);
726
+ }
727
+ async sendInstructionBreakpoints() {
728
+ if (!this.capabilities.supportsInstructionBreakpoints) {
729
+ return;
730
+ }
731
+ const all = this.breakpoints.getInstructionBreakpoints().map(breakpoint => new debug_instruction_breakpoint_1.DebugInstructionBreakpoint(breakpoint, this.asDebugBreakpointOptions()));
732
+ const enabled = all.filter(breakpoint => breakpoint.enabled);
733
+ try {
734
+ const response = await this.sendRequest('setInstructionBreakpoints', {
735
+ breakpoints: enabled.map(renderable => renderable.origin),
736
+ });
737
+ response.body.breakpoints.forEach((raw, index) => { var _a; return (_a = enabled[index]) === null || _a === void 0 ? void 0 : _a.update({ raw }); });
738
+ }
739
+ catch {
740
+ enabled.forEach(breakpoint => breakpoint.update({ raw: { verified: false } }));
741
+ }
742
+ this.setBreakpoints(breakpoint_manager_1.BreakpointManager.INSTRUCTION_URI, all);
743
+ }
744
+ setBreakpoints(uri, breakpoints) {
745
+ this._breakpoints.set(uri.toString(), breakpoints);
746
+ this.fireDidChangeBreakpoints(uri);
747
+ }
748
+ setSourceBreakpoints(uri, breakpoints) {
749
+ const distinct = this.dedupSourceBreakpoints(breakpoints);
750
+ this.setBreakpoints(uri, distinct);
751
+ }
752
+ dedupSourceBreakpoints(all) {
753
+ const positions = new Map();
754
+ for (const breakpoint of all) {
755
+ let primary = positions.get(breakpoint.renderPosition()) || breakpoint;
756
+ if (primary !== breakpoint) {
757
+ let secondary = breakpoint;
758
+ if (secondary.raw && secondary.raw.line === secondary.origin.raw.line && secondary.raw.column === secondary.origin.raw.column) {
759
+ [primary, secondary] = [breakpoint, primary];
760
+ }
761
+ primary.origins.push(...secondary.origins);
762
+ }
763
+ positions.set(primary.renderPosition(), primary);
764
+ }
765
+ return [...positions.values()];
766
+ }
767
+ *getAffectedUris(uri) {
768
+ if (uri) {
769
+ yield uri;
770
+ }
771
+ else {
772
+ for (const uriString of this.breakpoints.getUris()) {
773
+ yield new uri_1.default(uriString);
774
+ }
775
+ yield breakpoint_manager_1.BreakpointManager.FUNCTION_URI;
776
+ yield breakpoint_manager_1.BreakpointManager.EXCEPTION_URI;
777
+ }
778
+ }
779
+ asDebugBreakpointOptions() {
780
+ const { labelProvider, breakpoints, editorManager } = this;
781
+ return { labelProvider, breakpoints, editorManager, session: this };
782
+ }
783
+ get label() {
784
+ const suffixes = [];
785
+ if (debug_session_options_1.InternalDebugSessionOptions.is(this.options) && this.options.id) {
786
+ suffixes.push(String(this.options.id + 1));
787
+ }
788
+ if (this.workspaceService.isMultiRootWorkspaceOpened && this.options.workspaceFolderUri) {
789
+ suffixes.push(this.labelProvider.getName(new uri_1.default(this.options.workspaceFolderUri)));
790
+ }
791
+ return suffixes.length === 0 ? this.configuration.name : this.configuration.name + ` (${suffixes.join(' - ')})`;
792
+ }
793
+ get visible() {
794
+ return this.state > DebugState.Inactive;
795
+ }
796
+ render() {
797
+ let label = '';
798
+ const state = this.state === DebugState.Stopped ? core_1.nls.localizeByDefault('Paused') : core_1.nls.localizeByDefault('Running');
799
+ const child = this.getSingleChildSession();
800
+ if (child && child.configuration.compact) {
801
+ // Inlines the name of the child debug session
802
+ label = `: ${child.label}`;
803
+ }
804
+ return React.createElement("div", { className: 'theia-debug-session', title: 'Session' },
805
+ React.createElement("span", { className: 'label' }, this.label + label),
806
+ React.createElement("span", { className: 'status' }, state));
807
+ }
808
+ *getElements() {
809
+ const child = this.getSingleChildSession();
810
+ if (child && child.configuration.compact) {
811
+ // Inlines the elements of the child debug session
812
+ return yield* child.getElements();
813
+ }
814
+ yield* this.threads;
815
+ yield* this.childSessions.values();
816
+ }
817
+ getSingleChildSession() {
818
+ if (this._threads.size === 0 && this.childSessions.size === 1) {
819
+ const child = this.childSessions.values().next().value;
820
+ return child;
821
+ }
822
+ return undefined;
823
+ }
824
+ async handleContinued({ body: { allThreadsContinued, threadId } }) {
825
+ if (allThreadsContinued !== false) {
826
+ this.clearThreads();
827
+ }
828
+ else {
829
+ this.clearThread(threadId);
830
+ }
831
+ }
832
+ ;
833
+ async handleStopped({ body }) {
834
+ // Update thread list
835
+ await this.updateThreads(body);
836
+ // Update current thread's frames immediately
837
+ await this.updateFrames();
838
+ }
839
+ ;
840
+ async handleThread({ body: { reason, threadId } }) {
841
+ if (reason === 'started') {
842
+ this.scheduleUpdateThreads();
843
+ }
844
+ else if (reason === 'exited') {
845
+ this._threads.delete(threadId);
846
+ this.updateCurrentThread();
847
+ }
848
+ }
849
+ ;
850
+ registerDebugContributions(configType, connection) {
851
+ for (const contrib of this.debugContributionProvider.getContributions()) {
852
+ contrib.register(configType, connection);
853
+ }
854
+ }
855
+ ;
856
+ /**
857
+ * Returns the top-most parent session that is responsible for the console. If this session uses a {@link DebugConsoleMode.Separate separate console}
858
+ * or does not have any parent session, undefined is returned.
859
+ */
860
+ findConsoleParent() {
861
+ if (this.configuration.consoleMode !== debug_common_1.DebugConsoleMode.MergeWithParent) {
862
+ return undefined;
863
+ }
864
+ let debugSession = this;
865
+ do {
866
+ debugSession = debugSession.parentSession;
867
+ } while ((debugSession === null || debugSession === void 0 ? void 0 : debugSession.parentSession) && debugSession.configuration.consoleMode === debug_common_1.DebugConsoleMode.MergeWithParent);
868
+ return debugSession;
869
+ }
870
+ }
871
+ exports.DebugSession = DebugSession;
872
872
  //# sourceMappingURL=debug-session.js.map