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