@theia/debug 1.34.3 → 1.34.4

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,522 +1,522 @@
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
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
- return c > 3 && r && Object.defineProperty(target, key, r), r;
22
- };
23
- var __metadata = (this && this.__metadata) || function (k, v) {
24
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.DebugConfigurationManager = void 0;
28
- /*---------------------------------------------------------------------------------------------
29
- * Copyright (c) Microsoft Corporation. All rights reserved.
30
- * Licensed under the MIT License. See License.txt in the project root for license information.
31
- *--------------------------------------------------------------------------------------------*/
32
- const debounce = require("p-debounce");
33
- const jsonc_parser_1 = require("jsonc-parser");
34
- const inversify_1 = require("@theia/core/shared/inversify");
35
- const event_1 = require("@theia/core/lib/common/event");
36
- const browser_1 = require("@theia/editor/lib/browser");
37
- const monaco_editor_1 = require("@theia/monaco/lib/browser/monaco-editor");
38
- const browser_2 = require("@theia/core/lib/browser");
39
- const quick_pick_service_1 = require("@theia/core/lib/common/quick-pick-service");
40
- const workspace_service_1 = require("@theia/workspace/lib/browser/workspace-service");
41
- const debug_configuration_model_1 = require("./debug-configuration-model");
42
- const debug_session_options_1 = require("./debug-session-options");
43
- const debug_service_1 = require("../common/debug-service");
44
- const context_key_service_1 = require("@theia/core/lib/browser/context-key-service");
45
- const debug_common_1 = require("../common/debug-common");
46
- const workspace_variable_contribution_1 = require("@theia/workspace/lib/browser/workspace-variable-contribution");
47
- const preference_configurations_1 = require("@theia/core/lib/browser/preferences/preference-configurations");
48
- const monaco_text_model_service_1 = require("@theia/monaco/lib/browser/monaco-text-model-service");
49
- const commands_1 = require("@theia/monaco-editor-core/esm/vs/platform/commands/common/commands");
50
- const standaloneServices_1 = require("@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices");
51
- const core_1 = require("@theia/core");
52
- let DebugConfigurationManager = class DebugConfigurationManager {
53
- constructor() {
54
- this.onDidChangeEmitter = new event_1.Emitter();
55
- this.onDidChange = this.onDidChangeEmitter.event;
56
- this.onWillProvideDebugConfigurationEmitter = new event_1.Emitter();
57
- this.onWillProvideDebugConfiguration = this.onWillProvideDebugConfigurationEmitter.event;
58
- this.onWillProvideDynamicDebugConfigurationEmitter = new event_1.Emitter();
59
- this.recentDynamicOptionsTracker = [];
60
- this.models = new Map();
61
- this.updateModels = debounce(async () => {
62
- const roots = await this.workspaceService.roots;
63
- const toDelete = new Set(this.models.keys());
64
- for (const rootStat of roots) {
65
- const key = rootStat.resource.toString();
66
- toDelete.delete(key);
67
- if (!this.models.has(key)) {
68
- const model = new debug_configuration_model_1.DebugConfigurationModel(key, this.preferences);
69
- model.onDidChange(() => this.updateCurrent());
70
- model.onDispose(() => this.models.delete(key));
71
- this.models.set(key, model);
72
- }
73
- }
74
- for (const uri of toDelete) {
75
- const model = this.models.get(uri);
76
- if (model) {
77
- model.dispose();
78
- }
79
- }
80
- this.updateCurrent();
81
- }, 500);
82
- }
83
- get onWillProvideDynamicDebugConfiguration() {
84
- return this.onWillProvideDynamicDebugConfigurationEmitter.event;
85
- }
86
- get onDidChangeConfigurationProviders() {
87
- return this.debug.onDidChangeDebugConfigurationProviders;
88
- }
89
- async init() {
90
- this.debugConfigurationTypeKey = this.contextKeyService.createKey('debugConfigurationType', undefined);
91
- this.initialized = this.preferences.ready.then(() => {
92
- this.preferences.onPreferenceChanged(e => {
93
- if (e.preferenceName === 'launch') {
94
- this.updateModels();
95
- }
96
- });
97
- return this.updateModels();
98
- });
99
- }
100
- /**
101
- * All _non-dynamic_ debug configurations.
102
- */
103
- get all() {
104
- return this.getAll();
105
- }
106
- *getAll() {
107
- for (const model of this.models.values()) {
108
- for (const configuration of model.configurations) {
109
- yield this.configurationToOptions(configuration, model.workspaceFolderUri);
110
- }
111
- for (const compound of model.compounds) {
112
- yield this.compoundToOptions(compound, model.workspaceFolderUri);
113
- }
114
- }
115
- }
116
- get supported() {
117
- return this.getSupported();
118
- }
119
- async getSupported() {
120
- await this.initialized;
121
- const debugTypes = await this.debug.debugTypes();
122
- return this.doGetSupported(new Set(debugTypes));
123
- }
124
- *doGetSupported(debugTypes) {
125
- for (const options of this.getAll()) {
126
- if (options.configuration && debugTypes.has(options.configuration.type)) {
127
- yield options;
128
- }
129
- }
130
- }
131
- get current() {
132
- return this._currentOptions;
133
- }
134
- async getSelectedConfiguration() {
135
- if (!debug_session_options_1.DebugSessionOptions.isDynamic(this._currentOptions)) {
136
- return this._currentOptions;
137
- }
138
- // Refresh a dynamic configuration from the provider.
139
- // This allow providers to update properties before the execution e.g. program
140
- const { providerType, configuration: { name } } = this._currentOptions;
141
- const configuration = await this.fetchDynamicDebugConfiguration(name, providerType);
142
- if (!configuration) {
143
- const message = core_1.nls.localize('theia/debug/missingConfiguration', "Dynamic configuration '{0}:{1}' is missing or not applicable", providerType, name);
144
- throw new Error(message);
145
- }
146
- return { name, configuration, providerType };
147
- }
148
- set current(option) {
149
- this.updateCurrent(option);
150
- this.updateRecentlyUsedDynamicConfigurationOptions(option);
151
- }
152
- updateRecentlyUsedDynamicConfigurationOptions(option) {
153
- if (debug_session_options_1.DebugSessionOptions.isDynamic(option)) {
154
- // Removing an item already present in the list
155
- const index = this.recentDynamicOptionsTracker.findIndex(item => this.dynamicOptionsMatch(item, option));
156
- if (index > -1) {
157
- this.recentDynamicOptionsTracker.splice(index, 1);
158
- }
159
- // Adding new item, most recent at the top of the list
160
- const recentMax = 3;
161
- if (this.recentDynamicOptionsTracker.unshift(option) > recentMax) {
162
- // Keep the latest 3 dynamic configuration options to not clutter the dropdown.
163
- this.recentDynamicOptionsTracker.splice(recentMax);
164
- }
165
- }
166
- }
167
- dynamicOptionsMatch(one, other) {
168
- return one.providerType !== undefined
169
- && one.configuration.name === other.configuration.name
170
- && one.providerType === other.providerType;
171
- }
172
- get recentDynamicOptions() {
173
- return this.recentDynamicOptionsTracker;
174
- }
175
- updateCurrent(options = this._currentOptions) {
176
- var _a;
177
- if (debug_session_options_1.DebugSessionOptions.isCompound(options)) {
178
- this._currentOptions = options && this.find(options.compound, options.workspaceFolderUri);
179
- }
180
- else {
181
- this._currentOptions = options && this.find(options.configuration, options.workspaceFolderUri, options.providerType);
182
- }
183
- if (!this._currentOptions) {
184
- const model = this.getModel();
185
- if (model) {
186
- const configuration = model.configurations[0];
187
- if (configuration) {
188
- this._currentOptions = this.configurationToOptions(configuration, model.workspaceFolderUri);
189
- }
190
- }
191
- }
192
- this.debugConfigurationTypeKey.set(this.current && ((_a = this.current.configuration) === null || _a === void 0 ? void 0 : _a.type));
193
- this.onDidChangeEmitter.fire(undefined);
194
- }
195
- find(nameOrConfigurationOrCompound, workspaceFolderUri, providerType) {
196
- if (debug_common_1.DebugConfiguration.is(nameOrConfigurationOrCompound) && providerType) {
197
- // providerType is only applicable to dynamic debug configurations and may only be created if we have a configuration given
198
- return this.configurationToOptions(nameOrConfigurationOrCompound, workspaceFolderUri, providerType);
199
- }
200
- const name = typeof nameOrConfigurationOrCompound === 'string' ? nameOrConfigurationOrCompound : nameOrConfigurationOrCompound.name;
201
- const configuration = this.findConfiguration(name, workspaceFolderUri);
202
- if (configuration) {
203
- return this.configurationToOptions(configuration, workspaceFolderUri);
204
- }
205
- const compound = this.findCompound(name, workspaceFolderUri);
206
- if (compound) {
207
- return this.compoundToOptions(compound, workspaceFolderUri);
208
- }
209
- }
210
- findConfigurations(name, workspaceFolderUri) {
211
- const matches = [];
212
- for (const model of this.models.values()) {
213
- if (model.workspaceFolderUri === workspaceFolderUri) {
214
- for (const configuration of model.configurations) {
215
- if (configuration.name === name) {
216
- matches.push(configuration);
217
- }
218
- }
219
- }
220
- }
221
- return matches;
222
- }
223
- findConfiguration(name, workspaceFolderUri) {
224
- for (const model of this.models.values()) {
225
- if (model.workspaceFolderUri === workspaceFolderUri) {
226
- for (const configuration of model.configurations) {
227
- if (configuration.name === name) {
228
- return configuration;
229
- }
230
- }
231
- }
232
- }
233
- }
234
- findCompound(name, workspaceFolderUri) {
235
- for (const model of this.models.values()) {
236
- if (model.workspaceFolderUri === workspaceFolderUri) {
237
- for (const compound of model.compounds) {
238
- if (compound.name === name) {
239
- return compound;
240
- }
241
- }
242
- }
243
- }
244
- }
245
- async openConfiguration() {
246
- const model = this.getModel();
247
- if (model) {
248
- await this.doOpen(model);
249
- }
250
- }
251
- configurationToOptions(configuration, workspaceFolderUri, providerType) {
252
- return { name: configuration.name, configuration, providerType, workspaceFolderUri };
253
- }
254
- compoundToOptions(compound, workspaceFolderUri) {
255
- return { name: compound.name, compound, workspaceFolderUri };
256
- }
257
- async addConfiguration() {
258
- let rootUri = undefined;
259
- if (this.workspaceService.saved && this.workspaceService.tryGetRoots().length > 1) {
260
- rootUri = await this.selectRootUri();
261
- // Do not continue if the user explicitly does not choose a location.
262
- if (!rootUri) {
263
- return;
264
- }
265
- }
266
- const model = this.getModel(rootUri);
267
- if (!model) {
268
- return;
269
- }
270
- const widget = await this.doOpen(model);
271
- if (!(widget.editor instanceof monaco_editor_1.MonacoEditor)) {
272
- return;
273
- }
274
- const editor = widget.editor.getControl();
275
- const commandService = standaloneServices_1.StandaloneServices.get(commands_1.ICommandService);
276
- let position;
277
- let depthInArray = 0;
278
- let lastProperty = '';
279
- (0, jsonc_parser_1.visit)(editor.getValue(), {
280
- onObjectProperty: property => {
281
- lastProperty = property;
282
- },
283
- onArrayBegin: offset => {
284
- if (lastProperty === 'configurations' && depthInArray === 0) {
285
- position = editor.getModel().getPositionAt(offset + 1);
286
- }
287
- depthInArray++;
288
- },
289
- onArrayEnd: () => {
290
- depthInArray--;
291
- }
292
- });
293
- if (!position) {
294
- return;
295
- }
296
- // Check if there are more characters on a line after a "configurations": [, if yes enter a newline
297
- if (editor.getModel().getLineLastNonWhitespaceColumn(position.lineNumber) > position.column) {
298
- editor.setPosition(position);
299
- editor.trigger('debug', 'lineBreakInsert', undefined);
300
- }
301
- // Check if there is already an empty line to insert suggest, if yes just place the cursor
302
- if (editor.getModel().getLineLastNonWhitespaceColumn(position.lineNumber + 1) === 0) {
303
- editor.setPosition({ lineNumber: position.lineNumber + 1, column: 1 << 30 });
304
- await commandService.executeCommand('editor.action.deleteLines');
305
- }
306
- editor.setPosition(position);
307
- await commandService.executeCommand('editor.action.insertLineAfter');
308
- await commandService.executeCommand('editor.action.triggerSuggest');
309
- }
310
- async selectRootUri() {
311
- const workspaceRoots = this.workspaceService.tryGetRoots();
312
- const items = [];
313
- for (const workspaceRoot of workspaceRoots) {
314
- items.push({
315
- label: this.labelProvider.getName(workspaceRoot.resource),
316
- description: this.labelProvider.getLongName(workspaceRoot.resource),
317
- value: workspaceRoot.resource
318
- });
319
- }
320
- const root = await this.quickPickService.show(items, {
321
- placeholder: core_1.nls.localize('theia/debug/addConfigurationPlaceholder', 'Select workspace root to add configuration to'),
322
- ignoreFocusOut: true
323
- });
324
- return root === null || root === void 0 ? void 0 : root.value;
325
- }
326
- getModel(uri) {
327
- const workspaceFolderUri = this.workspaceVariables.getWorkspaceRootUri(uri);
328
- if (workspaceFolderUri) {
329
- const key = workspaceFolderUri.toString();
330
- for (const model of this.models.values()) {
331
- if (model.workspaceFolderUri === key) {
332
- return model;
333
- }
334
- }
335
- }
336
- for (const model of this.models.values()) {
337
- if (model.uri) {
338
- return model;
339
- }
340
- }
341
- return this.models.values().next().value;
342
- }
343
- async doOpen(model) {
344
- const uri = await this.doCreate(model);
345
- return this.editorManager.open(uri, {
346
- mode: 'activate'
347
- });
348
- }
349
- async doCreate(model) {
350
- var _a;
351
- const uri = (_a = model.uri) !== null && _a !== void 0 ? _a : this.preferences.getConfigUri(browser_2.PreferenceScope.Folder, model.workspaceFolderUri, 'launch');
352
- if (!uri) { // Since we are requesting information about a known workspace folder, this should never happen.
353
- throw new Error('PreferenceService.getConfigUri has returned undefined when a URI was expected.');
354
- }
355
- const settingsUri = this.preferences.getConfigUri(browser_2.PreferenceScope.Folder, model.workspaceFolderUri);
356
- // Users may have placed their debug configurations in a `settings.json`, in which case we shouldn't modify the file.
357
- if (settingsUri && !uri.isEqual(settingsUri)) {
358
- await this.ensureContent(uri, model);
359
- }
360
- return uri;
361
- }
362
- /**
363
- * Checks whether a `launch.json` file contains the minimum necessary content.
364
- * If content not found, provides content and populates the file using Monaco.
365
- */
366
- async ensureContent(uri, model) {
367
- const textModel = await this.textModelService.createModelReference(uri);
368
- const currentContent = textModel.object.valid ? textModel.object.getText() : '';
369
- try { // Look for the minimal well-formed launch.json content: {configurations: []}
370
- const parsedContent = (0, jsonc_parser_1.parse)(currentContent);
371
- if (Array.isArray(parsedContent.configurations)) {
372
- return;
373
- }
374
- }
375
- catch (_a) {
376
- // Just keep going
377
- }
378
- const debugType = await this.selectDebugType();
379
- const configurations = debugType ? await this.provideDebugConfigurations(debugType, model.workspaceFolderUri) : [];
380
- const content = this.getInitialConfigurationContent(configurations);
381
- textModel.object.textEditorModel.setValue(content); // Will clobber anything the user has entered!
382
- await textModel.object.save();
383
- }
384
- async provideDebugConfigurations(debugType, workspaceFolderUri) {
385
- await this.fireWillProvideDebugConfiguration();
386
- return this.debug.provideDebugConfigurations(debugType, workspaceFolderUri);
387
- }
388
- async fireWillProvideDebugConfiguration() {
389
- await event_1.WaitUntilEvent.fire(this.onWillProvideDebugConfigurationEmitter, {});
390
- }
391
- async provideDynamicDebugConfigurations() {
392
- await this.fireWillProvideDynamicDebugConfiguration();
393
- return this.debug.provideDynamicDebugConfigurations();
394
- }
395
- async fetchDynamicDebugConfiguration(name, type) {
396
- await this.fireWillProvideDynamicDebugConfiguration();
397
- return this.debug.fetchDynamicDebugConfiguration(name, type);
398
- }
399
- async fireWillProvideDynamicDebugConfiguration() {
400
- await this.initialized;
401
- await event_1.WaitUntilEvent.fire(this.onWillProvideDynamicDebugConfigurationEmitter, {});
402
- }
403
- getInitialConfigurationContent(initialConfigurations) {
404
- return `{
405
- // Use IntelliSense to learn about possible attributes.
406
- // Hover to view descriptions of existing attributes.
407
- "version": "0.2.0",
408
- "configurations": ${JSON.stringify(initialConfigurations, undefined, ' ').split('\n').map(line => ' ' + line).join('\n').trim()}
409
- }
410
- `;
411
- }
412
- async selectDebugType() {
413
- const widget = this.editorManager.currentEditor;
414
- if (!widget) {
415
- return undefined;
416
- }
417
- const { languageId } = widget.editor.document;
418
- const debuggers = await this.debug.getDebuggersForLanguage(languageId);
419
- if (debuggers.length === 0) {
420
- return undefined;
421
- }
422
- const items = debuggers.map(({ label, type }) => ({ label, value: type }));
423
- const selectedItem = await this.quickPickService.show(items, { placeholder: 'Select Environment' });
424
- return selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value;
425
- }
426
- async load() {
427
- var _a, _b;
428
- await this.initialized;
429
- const data = await this.storage.getData('debug.configurations', {});
430
- this.resolveRecentDynamicOptionsFromData(data.recentDynamicOptions);
431
- // Between versions v1.26 and v1.27, the expected format of the data changed so that old stored data
432
- // may not contain the configuration key.
433
- if (debug_session_options_1.DebugSessionOptions.isConfiguration(data.current)) {
434
- // ensure options name is reflected from old configurations data
435
- data.current.name = (_a = data.current.name) !== null && _a !== void 0 ? _a : (_b = data.current.configuration) === null || _b === void 0 ? void 0 : _b.name;
436
- this.current = this.find(data.current.configuration, data.current.workspaceFolderUri, data.current.providerType);
437
- }
438
- else if (debug_session_options_1.DebugSessionOptions.isCompound(data.current)) {
439
- this.current = this.find(data.current.name, data.current.workspaceFolderUri);
440
- }
441
- }
442
- resolveRecentDynamicOptionsFromData(options) {
443
- if (!options || this.recentDynamicOptionsTracker.length !== 0) {
444
- return;
445
- }
446
- // ensure options name is reflected from old configurations data
447
- const dynamicOptions = options.map(option => {
448
- var _a;
449
- option.name = (_a = option.name) !== null && _a !== void 0 ? _a : option.configuration.name;
450
- return option;
451
- }).filter(debug_session_options_1.DebugSessionOptions.isDynamic);
452
- this.recentDynamicOptionsTracker = dynamicOptions;
453
- }
454
- save() {
455
- const data = {};
456
- const { current, recentDynamicOptionsTracker } = this;
457
- if (current) {
458
- data.current = current;
459
- }
460
- if (this.recentDynamicOptionsTracker.length > 0) {
461
- data.recentDynamicOptions = recentDynamicOptionsTracker;
462
- }
463
- if (Object.keys(data).length > 0) {
464
- this.storage.setData('debug.configurations', data);
465
- }
466
- }
467
- };
468
- __decorate([
469
- (0, inversify_1.inject)(workspace_service_1.WorkspaceService),
470
- __metadata("design:type", workspace_service_1.WorkspaceService)
471
- ], DebugConfigurationManager.prototype, "workspaceService", void 0);
472
- __decorate([
473
- (0, inversify_1.inject)(browser_1.EditorManager),
474
- __metadata("design:type", browser_1.EditorManager)
475
- ], DebugConfigurationManager.prototype, "editorManager", void 0);
476
- __decorate([
477
- (0, inversify_1.inject)(debug_service_1.DebugService),
478
- __metadata("design:type", Object)
479
- ], DebugConfigurationManager.prototype, "debug", void 0);
480
- __decorate([
481
- (0, inversify_1.inject)(quick_pick_service_1.QuickPickService),
482
- __metadata("design:type", Object)
483
- ], DebugConfigurationManager.prototype, "quickPickService", void 0);
484
- __decorate([
485
- (0, inversify_1.inject)(context_key_service_1.ContextKeyService),
486
- __metadata("design:type", Object)
487
- ], DebugConfigurationManager.prototype, "contextKeyService", void 0);
488
- __decorate([
489
- (0, inversify_1.inject)(browser_2.LabelProvider),
490
- __metadata("design:type", browser_2.LabelProvider)
491
- ], DebugConfigurationManager.prototype, "labelProvider", void 0);
492
- __decorate([
493
- (0, inversify_1.inject)(monaco_text_model_service_1.MonacoTextModelService),
494
- __metadata("design:type", monaco_text_model_service_1.MonacoTextModelService)
495
- ], DebugConfigurationManager.prototype, "textModelService", void 0);
496
- __decorate([
497
- (0, inversify_1.inject)(browser_2.PreferenceService),
498
- __metadata("design:type", Object)
499
- ], DebugConfigurationManager.prototype, "preferences", void 0);
500
- __decorate([
501
- (0, inversify_1.inject)(preference_configurations_1.PreferenceConfigurations),
502
- __metadata("design:type", preference_configurations_1.PreferenceConfigurations)
503
- ], DebugConfigurationManager.prototype, "preferenceConfigurations", void 0);
504
- __decorate([
505
- (0, inversify_1.inject)(workspace_variable_contribution_1.WorkspaceVariableContribution),
506
- __metadata("design:type", workspace_variable_contribution_1.WorkspaceVariableContribution)
507
- ], DebugConfigurationManager.prototype, "workspaceVariables", void 0);
508
- __decorate([
509
- (0, inversify_1.postConstruct)(),
510
- __metadata("design:type", Function),
511
- __metadata("design:paramtypes", []),
512
- __metadata("design:returntype", Promise)
513
- ], DebugConfigurationManager.prototype, "init", null);
514
- __decorate([
515
- (0, inversify_1.inject)(browser_2.StorageService),
516
- __metadata("design:type", Object)
517
- ], DebugConfigurationManager.prototype, "storage", void 0);
518
- DebugConfigurationManager = __decorate([
519
- (0, inversify_1.injectable)()
520
- ], DebugConfigurationManager);
521
- exports.DebugConfigurationManager = DebugConfigurationManager;
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
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __metadata = (this && this.__metadata) || function (k, v) {
24
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.DebugConfigurationManager = void 0;
28
+ /*---------------------------------------------------------------------------------------------
29
+ * Copyright (c) Microsoft Corporation. All rights reserved.
30
+ * Licensed under the MIT License. See License.txt in the project root for license information.
31
+ *--------------------------------------------------------------------------------------------*/
32
+ const debounce = require("p-debounce");
33
+ const jsonc_parser_1 = require("jsonc-parser");
34
+ const inversify_1 = require("@theia/core/shared/inversify");
35
+ const event_1 = require("@theia/core/lib/common/event");
36
+ const browser_1 = require("@theia/editor/lib/browser");
37
+ const monaco_editor_1 = require("@theia/monaco/lib/browser/monaco-editor");
38
+ const browser_2 = require("@theia/core/lib/browser");
39
+ const quick_pick_service_1 = require("@theia/core/lib/common/quick-pick-service");
40
+ const workspace_service_1 = require("@theia/workspace/lib/browser/workspace-service");
41
+ const debug_configuration_model_1 = require("./debug-configuration-model");
42
+ const debug_session_options_1 = require("./debug-session-options");
43
+ const debug_service_1 = require("../common/debug-service");
44
+ const context_key_service_1 = require("@theia/core/lib/browser/context-key-service");
45
+ const debug_common_1 = require("../common/debug-common");
46
+ const workspace_variable_contribution_1 = require("@theia/workspace/lib/browser/workspace-variable-contribution");
47
+ const preference_configurations_1 = require("@theia/core/lib/browser/preferences/preference-configurations");
48
+ const monaco_text_model_service_1 = require("@theia/monaco/lib/browser/monaco-text-model-service");
49
+ const commands_1 = require("@theia/monaco-editor-core/esm/vs/platform/commands/common/commands");
50
+ const standaloneServices_1 = require("@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices");
51
+ const core_1 = require("@theia/core");
52
+ let DebugConfigurationManager = class DebugConfigurationManager {
53
+ constructor() {
54
+ this.onDidChangeEmitter = new event_1.Emitter();
55
+ this.onDidChange = this.onDidChangeEmitter.event;
56
+ this.onWillProvideDebugConfigurationEmitter = new event_1.Emitter();
57
+ this.onWillProvideDebugConfiguration = this.onWillProvideDebugConfigurationEmitter.event;
58
+ this.onWillProvideDynamicDebugConfigurationEmitter = new event_1.Emitter();
59
+ this.recentDynamicOptionsTracker = [];
60
+ this.models = new Map();
61
+ this.updateModels = debounce(async () => {
62
+ const roots = await this.workspaceService.roots;
63
+ const toDelete = new Set(this.models.keys());
64
+ for (const rootStat of roots) {
65
+ const key = rootStat.resource.toString();
66
+ toDelete.delete(key);
67
+ if (!this.models.has(key)) {
68
+ const model = new debug_configuration_model_1.DebugConfigurationModel(key, this.preferences);
69
+ model.onDidChange(() => this.updateCurrent());
70
+ model.onDispose(() => this.models.delete(key));
71
+ this.models.set(key, model);
72
+ }
73
+ }
74
+ for (const uri of toDelete) {
75
+ const model = this.models.get(uri);
76
+ if (model) {
77
+ model.dispose();
78
+ }
79
+ }
80
+ this.updateCurrent();
81
+ }, 500);
82
+ }
83
+ get onWillProvideDynamicDebugConfiguration() {
84
+ return this.onWillProvideDynamicDebugConfigurationEmitter.event;
85
+ }
86
+ get onDidChangeConfigurationProviders() {
87
+ return this.debug.onDidChangeDebugConfigurationProviders;
88
+ }
89
+ async init() {
90
+ this.debugConfigurationTypeKey = this.contextKeyService.createKey('debugConfigurationType', undefined);
91
+ this.initialized = this.preferences.ready.then(() => {
92
+ this.preferences.onPreferenceChanged(e => {
93
+ if (e.preferenceName === 'launch') {
94
+ this.updateModels();
95
+ }
96
+ });
97
+ return this.updateModels();
98
+ });
99
+ }
100
+ /**
101
+ * All _non-dynamic_ debug configurations.
102
+ */
103
+ get all() {
104
+ return this.getAll();
105
+ }
106
+ *getAll() {
107
+ for (const model of this.models.values()) {
108
+ for (const configuration of model.configurations) {
109
+ yield this.configurationToOptions(configuration, model.workspaceFolderUri);
110
+ }
111
+ for (const compound of model.compounds) {
112
+ yield this.compoundToOptions(compound, model.workspaceFolderUri);
113
+ }
114
+ }
115
+ }
116
+ get supported() {
117
+ return this.getSupported();
118
+ }
119
+ async getSupported() {
120
+ await this.initialized;
121
+ const debugTypes = await this.debug.debugTypes();
122
+ return this.doGetSupported(new Set(debugTypes));
123
+ }
124
+ *doGetSupported(debugTypes) {
125
+ for (const options of this.getAll()) {
126
+ if (options.configuration && debugTypes.has(options.configuration.type)) {
127
+ yield options;
128
+ }
129
+ }
130
+ }
131
+ get current() {
132
+ return this._currentOptions;
133
+ }
134
+ async getSelectedConfiguration() {
135
+ if (!debug_session_options_1.DebugSessionOptions.isDynamic(this._currentOptions)) {
136
+ return this._currentOptions;
137
+ }
138
+ // Refresh a dynamic configuration from the provider.
139
+ // This allow providers to update properties before the execution e.g. program
140
+ const { providerType, configuration: { name } } = this._currentOptions;
141
+ const configuration = await this.fetchDynamicDebugConfiguration(name, providerType);
142
+ if (!configuration) {
143
+ const message = core_1.nls.localize('theia/debug/missingConfiguration', "Dynamic configuration '{0}:{1}' is missing or not applicable", providerType, name);
144
+ throw new Error(message);
145
+ }
146
+ return { name, configuration, providerType };
147
+ }
148
+ set current(option) {
149
+ this.updateCurrent(option);
150
+ this.updateRecentlyUsedDynamicConfigurationOptions(option);
151
+ }
152
+ updateRecentlyUsedDynamicConfigurationOptions(option) {
153
+ if (debug_session_options_1.DebugSessionOptions.isDynamic(option)) {
154
+ // Removing an item already present in the list
155
+ const index = this.recentDynamicOptionsTracker.findIndex(item => this.dynamicOptionsMatch(item, option));
156
+ if (index > -1) {
157
+ this.recentDynamicOptionsTracker.splice(index, 1);
158
+ }
159
+ // Adding new item, most recent at the top of the list
160
+ const recentMax = 3;
161
+ if (this.recentDynamicOptionsTracker.unshift(option) > recentMax) {
162
+ // Keep the latest 3 dynamic configuration options to not clutter the dropdown.
163
+ this.recentDynamicOptionsTracker.splice(recentMax);
164
+ }
165
+ }
166
+ }
167
+ dynamicOptionsMatch(one, other) {
168
+ return one.providerType !== undefined
169
+ && one.configuration.name === other.configuration.name
170
+ && one.providerType === other.providerType;
171
+ }
172
+ get recentDynamicOptions() {
173
+ return this.recentDynamicOptionsTracker;
174
+ }
175
+ updateCurrent(options = this._currentOptions) {
176
+ var _a;
177
+ if (debug_session_options_1.DebugSessionOptions.isCompound(options)) {
178
+ this._currentOptions = options && this.find(options.compound, options.workspaceFolderUri);
179
+ }
180
+ else {
181
+ this._currentOptions = options && this.find(options.configuration, options.workspaceFolderUri, options.providerType);
182
+ }
183
+ if (!this._currentOptions) {
184
+ const model = this.getModel();
185
+ if (model) {
186
+ const configuration = model.configurations[0];
187
+ if (configuration) {
188
+ this._currentOptions = this.configurationToOptions(configuration, model.workspaceFolderUri);
189
+ }
190
+ }
191
+ }
192
+ this.debugConfigurationTypeKey.set(this.current && ((_a = this.current.configuration) === null || _a === void 0 ? void 0 : _a.type));
193
+ this.onDidChangeEmitter.fire(undefined);
194
+ }
195
+ find(nameOrConfigurationOrCompound, workspaceFolderUri, providerType) {
196
+ if (debug_common_1.DebugConfiguration.is(nameOrConfigurationOrCompound) && providerType) {
197
+ // providerType is only applicable to dynamic debug configurations and may only be created if we have a configuration given
198
+ return this.configurationToOptions(nameOrConfigurationOrCompound, workspaceFolderUri, providerType);
199
+ }
200
+ const name = typeof nameOrConfigurationOrCompound === 'string' ? nameOrConfigurationOrCompound : nameOrConfigurationOrCompound.name;
201
+ const configuration = this.findConfiguration(name, workspaceFolderUri);
202
+ if (configuration) {
203
+ return this.configurationToOptions(configuration, workspaceFolderUri);
204
+ }
205
+ const compound = this.findCompound(name, workspaceFolderUri);
206
+ if (compound) {
207
+ return this.compoundToOptions(compound, workspaceFolderUri);
208
+ }
209
+ }
210
+ findConfigurations(name, workspaceFolderUri) {
211
+ const matches = [];
212
+ for (const model of this.models.values()) {
213
+ if (model.workspaceFolderUri === workspaceFolderUri) {
214
+ for (const configuration of model.configurations) {
215
+ if (configuration.name === name) {
216
+ matches.push(configuration);
217
+ }
218
+ }
219
+ }
220
+ }
221
+ return matches;
222
+ }
223
+ findConfiguration(name, workspaceFolderUri) {
224
+ for (const model of this.models.values()) {
225
+ if (model.workspaceFolderUri === workspaceFolderUri) {
226
+ for (const configuration of model.configurations) {
227
+ if (configuration.name === name) {
228
+ return configuration;
229
+ }
230
+ }
231
+ }
232
+ }
233
+ }
234
+ findCompound(name, workspaceFolderUri) {
235
+ for (const model of this.models.values()) {
236
+ if (model.workspaceFolderUri === workspaceFolderUri) {
237
+ for (const compound of model.compounds) {
238
+ if (compound.name === name) {
239
+ return compound;
240
+ }
241
+ }
242
+ }
243
+ }
244
+ }
245
+ async openConfiguration() {
246
+ const model = this.getModel();
247
+ if (model) {
248
+ await this.doOpen(model);
249
+ }
250
+ }
251
+ configurationToOptions(configuration, workspaceFolderUri, providerType) {
252
+ return { name: configuration.name, configuration, providerType, workspaceFolderUri };
253
+ }
254
+ compoundToOptions(compound, workspaceFolderUri) {
255
+ return { name: compound.name, compound, workspaceFolderUri };
256
+ }
257
+ async addConfiguration() {
258
+ let rootUri = undefined;
259
+ if (this.workspaceService.saved && this.workspaceService.tryGetRoots().length > 1) {
260
+ rootUri = await this.selectRootUri();
261
+ // Do not continue if the user explicitly does not choose a location.
262
+ if (!rootUri) {
263
+ return;
264
+ }
265
+ }
266
+ const model = this.getModel(rootUri);
267
+ if (!model) {
268
+ return;
269
+ }
270
+ const widget = await this.doOpen(model);
271
+ if (!(widget.editor instanceof monaco_editor_1.MonacoEditor)) {
272
+ return;
273
+ }
274
+ const editor = widget.editor.getControl();
275
+ const commandService = standaloneServices_1.StandaloneServices.get(commands_1.ICommandService);
276
+ let position;
277
+ let depthInArray = 0;
278
+ let lastProperty = '';
279
+ (0, jsonc_parser_1.visit)(editor.getValue(), {
280
+ onObjectProperty: property => {
281
+ lastProperty = property;
282
+ },
283
+ onArrayBegin: offset => {
284
+ if (lastProperty === 'configurations' && depthInArray === 0) {
285
+ position = editor.getModel().getPositionAt(offset + 1);
286
+ }
287
+ depthInArray++;
288
+ },
289
+ onArrayEnd: () => {
290
+ depthInArray--;
291
+ }
292
+ });
293
+ if (!position) {
294
+ return;
295
+ }
296
+ // Check if there are more characters on a line after a "configurations": [, if yes enter a newline
297
+ if (editor.getModel().getLineLastNonWhitespaceColumn(position.lineNumber) > position.column) {
298
+ editor.setPosition(position);
299
+ editor.trigger('debug', 'lineBreakInsert', undefined);
300
+ }
301
+ // Check if there is already an empty line to insert suggest, if yes just place the cursor
302
+ if (editor.getModel().getLineLastNonWhitespaceColumn(position.lineNumber + 1) === 0) {
303
+ editor.setPosition({ lineNumber: position.lineNumber + 1, column: 1 << 30 });
304
+ await commandService.executeCommand('editor.action.deleteLines');
305
+ }
306
+ editor.setPosition(position);
307
+ await commandService.executeCommand('editor.action.insertLineAfter');
308
+ await commandService.executeCommand('editor.action.triggerSuggest');
309
+ }
310
+ async selectRootUri() {
311
+ const workspaceRoots = this.workspaceService.tryGetRoots();
312
+ const items = [];
313
+ for (const workspaceRoot of workspaceRoots) {
314
+ items.push({
315
+ label: this.labelProvider.getName(workspaceRoot.resource),
316
+ description: this.labelProvider.getLongName(workspaceRoot.resource),
317
+ value: workspaceRoot.resource
318
+ });
319
+ }
320
+ const root = await this.quickPickService.show(items, {
321
+ placeholder: core_1.nls.localize('theia/debug/addConfigurationPlaceholder', 'Select workspace root to add configuration to'),
322
+ ignoreFocusOut: true
323
+ });
324
+ return root === null || root === void 0 ? void 0 : root.value;
325
+ }
326
+ getModel(uri) {
327
+ const workspaceFolderUri = this.workspaceVariables.getWorkspaceRootUri(uri);
328
+ if (workspaceFolderUri) {
329
+ const key = workspaceFolderUri.toString();
330
+ for (const model of this.models.values()) {
331
+ if (model.workspaceFolderUri === key) {
332
+ return model;
333
+ }
334
+ }
335
+ }
336
+ for (const model of this.models.values()) {
337
+ if (model.uri) {
338
+ return model;
339
+ }
340
+ }
341
+ return this.models.values().next().value;
342
+ }
343
+ async doOpen(model) {
344
+ const uri = await this.doCreate(model);
345
+ return this.editorManager.open(uri, {
346
+ mode: 'activate'
347
+ });
348
+ }
349
+ async doCreate(model) {
350
+ var _a;
351
+ const uri = (_a = model.uri) !== null && _a !== void 0 ? _a : this.preferences.getConfigUri(browser_2.PreferenceScope.Folder, model.workspaceFolderUri, 'launch');
352
+ if (!uri) { // Since we are requesting information about a known workspace folder, this should never happen.
353
+ throw new Error('PreferenceService.getConfigUri has returned undefined when a URI was expected.');
354
+ }
355
+ const settingsUri = this.preferences.getConfigUri(browser_2.PreferenceScope.Folder, model.workspaceFolderUri);
356
+ // Users may have placed their debug configurations in a `settings.json`, in which case we shouldn't modify the file.
357
+ if (settingsUri && !uri.isEqual(settingsUri)) {
358
+ await this.ensureContent(uri, model);
359
+ }
360
+ return uri;
361
+ }
362
+ /**
363
+ * Checks whether a `launch.json` file contains the minimum necessary content.
364
+ * If content not found, provides content and populates the file using Monaco.
365
+ */
366
+ async ensureContent(uri, model) {
367
+ const textModel = await this.textModelService.createModelReference(uri);
368
+ const currentContent = textModel.object.valid ? textModel.object.getText() : '';
369
+ try { // Look for the minimal well-formed launch.json content: {configurations: []}
370
+ const parsedContent = (0, jsonc_parser_1.parse)(currentContent);
371
+ if (Array.isArray(parsedContent.configurations)) {
372
+ return;
373
+ }
374
+ }
375
+ catch (_a) {
376
+ // Just keep going
377
+ }
378
+ const debugType = await this.selectDebugType();
379
+ const configurations = debugType ? await this.provideDebugConfigurations(debugType, model.workspaceFolderUri) : [];
380
+ const content = this.getInitialConfigurationContent(configurations);
381
+ textModel.object.textEditorModel.setValue(content); // Will clobber anything the user has entered!
382
+ await textModel.object.save();
383
+ }
384
+ async provideDebugConfigurations(debugType, workspaceFolderUri) {
385
+ await this.fireWillProvideDebugConfiguration();
386
+ return this.debug.provideDebugConfigurations(debugType, workspaceFolderUri);
387
+ }
388
+ async fireWillProvideDebugConfiguration() {
389
+ await event_1.WaitUntilEvent.fire(this.onWillProvideDebugConfigurationEmitter, {});
390
+ }
391
+ async provideDynamicDebugConfigurations() {
392
+ await this.fireWillProvideDynamicDebugConfiguration();
393
+ return this.debug.provideDynamicDebugConfigurations();
394
+ }
395
+ async fetchDynamicDebugConfiguration(name, type) {
396
+ await this.fireWillProvideDynamicDebugConfiguration();
397
+ return this.debug.fetchDynamicDebugConfiguration(name, type);
398
+ }
399
+ async fireWillProvideDynamicDebugConfiguration() {
400
+ await this.initialized;
401
+ await event_1.WaitUntilEvent.fire(this.onWillProvideDynamicDebugConfigurationEmitter, {});
402
+ }
403
+ getInitialConfigurationContent(initialConfigurations) {
404
+ return `{
405
+ // Use IntelliSense to learn about possible attributes.
406
+ // Hover to view descriptions of existing attributes.
407
+ "version": "0.2.0",
408
+ "configurations": ${JSON.stringify(initialConfigurations, undefined, ' ').split('\n').map(line => ' ' + line).join('\n').trim()}
409
+ }
410
+ `;
411
+ }
412
+ async selectDebugType() {
413
+ const widget = this.editorManager.currentEditor;
414
+ if (!widget) {
415
+ return undefined;
416
+ }
417
+ const { languageId } = widget.editor.document;
418
+ const debuggers = await this.debug.getDebuggersForLanguage(languageId);
419
+ if (debuggers.length === 0) {
420
+ return undefined;
421
+ }
422
+ const items = debuggers.map(({ label, type }) => ({ label, value: type }));
423
+ const selectedItem = await this.quickPickService.show(items, { placeholder: 'Select Environment' });
424
+ return selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value;
425
+ }
426
+ async load() {
427
+ var _a, _b;
428
+ await this.initialized;
429
+ const data = await this.storage.getData('debug.configurations', {});
430
+ this.resolveRecentDynamicOptionsFromData(data.recentDynamicOptions);
431
+ // Between versions v1.26 and v1.27, the expected format of the data changed so that old stored data
432
+ // may not contain the configuration key.
433
+ if (debug_session_options_1.DebugSessionOptions.isConfiguration(data.current)) {
434
+ // ensure options name is reflected from old configurations data
435
+ data.current.name = (_a = data.current.name) !== null && _a !== void 0 ? _a : (_b = data.current.configuration) === null || _b === void 0 ? void 0 : _b.name;
436
+ this.current = this.find(data.current.configuration, data.current.workspaceFolderUri, data.current.providerType);
437
+ }
438
+ else if (debug_session_options_1.DebugSessionOptions.isCompound(data.current)) {
439
+ this.current = this.find(data.current.name, data.current.workspaceFolderUri);
440
+ }
441
+ }
442
+ resolveRecentDynamicOptionsFromData(options) {
443
+ if (!options || this.recentDynamicOptionsTracker.length !== 0) {
444
+ return;
445
+ }
446
+ // ensure options name is reflected from old configurations data
447
+ const dynamicOptions = options.map(option => {
448
+ var _a;
449
+ option.name = (_a = option.name) !== null && _a !== void 0 ? _a : option.configuration.name;
450
+ return option;
451
+ }).filter(debug_session_options_1.DebugSessionOptions.isDynamic);
452
+ this.recentDynamicOptionsTracker = dynamicOptions;
453
+ }
454
+ save() {
455
+ const data = {};
456
+ const { current, recentDynamicOptionsTracker } = this;
457
+ if (current) {
458
+ data.current = current;
459
+ }
460
+ if (this.recentDynamicOptionsTracker.length > 0) {
461
+ data.recentDynamicOptions = recentDynamicOptionsTracker;
462
+ }
463
+ if (Object.keys(data).length > 0) {
464
+ this.storage.setData('debug.configurations', data);
465
+ }
466
+ }
467
+ };
468
+ __decorate([
469
+ (0, inversify_1.inject)(workspace_service_1.WorkspaceService),
470
+ __metadata("design:type", workspace_service_1.WorkspaceService)
471
+ ], DebugConfigurationManager.prototype, "workspaceService", void 0);
472
+ __decorate([
473
+ (0, inversify_1.inject)(browser_1.EditorManager),
474
+ __metadata("design:type", browser_1.EditorManager)
475
+ ], DebugConfigurationManager.prototype, "editorManager", void 0);
476
+ __decorate([
477
+ (0, inversify_1.inject)(debug_service_1.DebugService),
478
+ __metadata("design:type", Object)
479
+ ], DebugConfigurationManager.prototype, "debug", void 0);
480
+ __decorate([
481
+ (0, inversify_1.inject)(quick_pick_service_1.QuickPickService),
482
+ __metadata("design:type", Object)
483
+ ], DebugConfigurationManager.prototype, "quickPickService", void 0);
484
+ __decorate([
485
+ (0, inversify_1.inject)(context_key_service_1.ContextKeyService),
486
+ __metadata("design:type", Object)
487
+ ], DebugConfigurationManager.prototype, "contextKeyService", void 0);
488
+ __decorate([
489
+ (0, inversify_1.inject)(browser_2.LabelProvider),
490
+ __metadata("design:type", browser_2.LabelProvider)
491
+ ], DebugConfigurationManager.prototype, "labelProvider", void 0);
492
+ __decorate([
493
+ (0, inversify_1.inject)(monaco_text_model_service_1.MonacoTextModelService),
494
+ __metadata("design:type", monaco_text_model_service_1.MonacoTextModelService)
495
+ ], DebugConfigurationManager.prototype, "textModelService", void 0);
496
+ __decorate([
497
+ (0, inversify_1.inject)(browser_2.PreferenceService),
498
+ __metadata("design:type", Object)
499
+ ], DebugConfigurationManager.prototype, "preferences", void 0);
500
+ __decorate([
501
+ (0, inversify_1.inject)(preference_configurations_1.PreferenceConfigurations),
502
+ __metadata("design:type", preference_configurations_1.PreferenceConfigurations)
503
+ ], DebugConfigurationManager.prototype, "preferenceConfigurations", void 0);
504
+ __decorate([
505
+ (0, inversify_1.inject)(workspace_variable_contribution_1.WorkspaceVariableContribution),
506
+ __metadata("design:type", workspace_variable_contribution_1.WorkspaceVariableContribution)
507
+ ], DebugConfigurationManager.prototype, "workspaceVariables", void 0);
508
+ __decorate([
509
+ (0, inversify_1.postConstruct)(),
510
+ __metadata("design:type", Function),
511
+ __metadata("design:paramtypes", []),
512
+ __metadata("design:returntype", Promise)
513
+ ], DebugConfigurationManager.prototype, "init", null);
514
+ __decorate([
515
+ (0, inversify_1.inject)(browser_2.StorageService),
516
+ __metadata("design:type", Object)
517
+ ], DebugConfigurationManager.prototype, "storage", void 0);
518
+ DebugConfigurationManager = __decorate([
519
+ (0, inversify_1.injectable)()
520
+ ], DebugConfigurationManager);
521
+ exports.DebugConfigurationManager = DebugConfigurationManager;
522
522
  //# sourceMappingURL=debug-configuration-manager.js.map