@theia/debug 1.53.0-next.5 → 1.53.0-next.55

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 (88) hide show
  1. package/README.md +62 -62
  2. package/lib/browser/debug-configuration-manager.js +6 -6
  3. package/lib/browser/debug-frontend-application-contribution.d.ts.map +1 -1
  4. package/lib/browser/debug-frontend-application-contribution.js.map +1 -1
  5. package/lib/common/inline-debug-adapter.d.ts +1 -0
  6. package/lib/common/inline-debug-adapter.d.ts.map +1 -1
  7. package/package.json +16 -16
  8. package/src/browser/breakpoint/breakpoint-manager.ts +369 -369
  9. package/src/browser/breakpoint/breakpoint-marker.ts +104 -104
  10. package/src/browser/console/debug-console-contribution.tsx +240 -240
  11. package/src/browser/console/debug-console-items.tsx +384 -384
  12. package/src/browser/console/debug-console-session.ts +205 -205
  13. package/src/browser/debug-call-stack-item-type-key.ts +20 -20
  14. package/src/browser/debug-configuration-manager.ts +591 -591
  15. package/src/browser/debug-configuration-model.ts +100 -100
  16. package/src/browser/debug-contribution.ts +43 -43
  17. package/src/browser/debug-frontend-application-contribution.ts +1551 -1551
  18. package/src/browser/debug-frontend-module.ts +133 -133
  19. package/src/browser/debug-package.spec.ts +20 -20
  20. package/src/browser/debug-preferences.ts +98 -98
  21. package/src/browser/debug-prefix-configuration.ts +195 -195
  22. package/src/browser/debug-resource.ts +59 -59
  23. package/src/browser/debug-schema-updater.ts +149 -149
  24. package/src/browser/debug-session-connection.ts +357 -357
  25. package/src/browser/debug-session-contribution.ts +157 -157
  26. package/src/browser/debug-session-manager.ts +683 -683
  27. package/src/browser/debug-session-options.ts +120 -120
  28. package/src/browser/debug-session.tsx +974 -974
  29. package/src/browser/debug-tab-bar-decorator.ts +57 -57
  30. package/src/browser/debug-watch-manager.ts +93 -93
  31. package/src/browser/disassembly-view/disassembly-view-accessibility-provider.ts +43 -43
  32. package/src/browser/disassembly-view/disassembly-view-breakpoint-renderer.ts +119 -119
  33. package/src/browser/disassembly-view/disassembly-view-contribution.ts +109 -109
  34. package/src/browser/disassembly-view/disassembly-view-instruction-renderer.ts +245 -245
  35. package/src/browser/disassembly-view/disassembly-view-table-delegate.ts +39 -39
  36. package/src/browser/disassembly-view/disassembly-view-utilities.ts +55 -55
  37. package/src/browser/disassembly-view/disassembly-view-widget.ts +463 -463
  38. package/src/browser/editor/debug-breakpoint-widget.tsx +293 -293
  39. package/src/browser/editor/debug-editor-model.ts +529 -529
  40. package/src/browser/editor/debug-editor-service.ts +192 -192
  41. package/src/browser/editor/debug-editor.ts +20 -20
  42. package/src/browser/editor/debug-exception-widget.tsx +122 -122
  43. package/src/browser/editor/debug-expression-provider.ts +78 -78
  44. package/src/browser/editor/debug-hover-source.tsx +105 -105
  45. package/src/browser/editor/debug-hover-widget.ts +298 -298
  46. package/src/browser/editor/debug-inline-value-decorator.ts +373 -373
  47. package/src/browser/model/debug-breakpoint.tsx +151 -151
  48. package/src/browser/model/debug-function-breakpoint.tsx +101 -101
  49. package/src/browser/model/debug-instruction-breakpoint.tsx +68 -68
  50. package/src/browser/model/debug-source-breakpoint.tsx +237 -237
  51. package/src/browser/model/debug-source.ts +93 -93
  52. package/src/browser/model/debug-stack-frame.tsx +177 -177
  53. package/src/browser/model/debug-thread.tsx +292 -292
  54. package/src/browser/preferences/launch-preferences.ts +38 -38
  55. package/src/browser/style/index.css +453 -453
  56. package/src/browser/view/debug-action.tsx +57 -57
  57. package/src/browser/view/debug-breakpoints-source.tsx +53 -53
  58. package/src/browser/view/debug-breakpoints-widget.ts +71 -71
  59. package/src/browser/view/debug-configuration-select.tsx +269 -269
  60. package/src/browser/view/debug-configuration-widget.tsx +121 -121
  61. package/src/browser/view/debug-exception-breakpoint.tsx +68 -68
  62. package/src/browser/view/debug-session-widget.ts +124 -124
  63. package/src/browser/view/debug-stack-frames-source.tsx +75 -75
  64. package/src/browser/view/debug-stack-frames-widget.ts +135 -135
  65. package/src/browser/view/debug-threads-source.tsx +48 -48
  66. package/src/browser/view/debug-threads-widget.ts +126 -126
  67. package/src/browser/view/debug-toolbar-widget.tsx +145 -145
  68. package/src/browser/view/debug-variables-source.ts +43 -43
  69. package/src/browser/view/debug-variables-widget.ts +61 -61
  70. package/src/browser/view/debug-view-model.ts +230 -230
  71. package/src/browser/view/debug-watch-expression.tsx +88 -88
  72. package/src/browser/view/debug-watch-source.ts +41 -41
  73. package/src/browser/view/debug-watch-widget.ts +61 -61
  74. package/src/browser/view/debug-widget.ts +97 -97
  75. package/src/common/debug-adapter-contribution-registry.ts +206 -206
  76. package/src/common/debug-adapter-session.ts +102 -102
  77. package/src/common/debug-common.ts +19 -19
  78. package/src/common/debug-compound.ts +33 -33
  79. package/src/common/debug-configuration.ts +112 -112
  80. package/src/common/debug-model.ts +200 -200
  81. package/src/common/debug-service.ts +184 -184
  82. package/src/common/debug-uri-utils.ts +24 -24
  83. package/src/common/inline-debug-adapter.ts +47 -47
  84. package/src/node/debug-adapter-factory.ts +107 -107
  85. package/src/node/debug-adapter-session-manager.ts +106 -106
  86. package/src/node/debug-backend-module.ts +57 -57
  87. package/src/node/debug-service-impl.ts +119 -119
  88. package/src/node/stream-debug-adapter.ts +126 -126
@@ -1,293 +1,293 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import * as React from '@theia/core/shared/react';
18
- import { createRoot, Root } from '@theia/core/shared/react-dom/client';
19
- import { DebugProtocol } from '@vscode/debugprotocol';
20
- import { injectable, postConstruct, inject } from '@theia/core/shared/inversify';
21
- import { Disposable, DisposableCollection, nls } from '@theia/core';
22
- import URI from '@theia/core/lib/common/uri';
23
- import { MonacoEditorProvider } from '@theia/monaco/lib/browser/monaco-editor-provider';
24
- import { MonacoEditorZoneWidget } from '@theia/monaco/lib/browser/monaco-editor-zone-widget';
25
- import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
26
- import { DebugEditor } from './debug-editor';
27
- import { DebugSourceBreakpoint } from '../model/debug-source-breakpoint';
28
- import { Dimension } from '@theia/editor/lib/browser';
29
- import * as monaco from '@theia/monaco-editor-core';
30
- import { LanguageSelector } from '@theia/monaco-editor-core/esm/vs/editor/common/languageSelector';
31
- import { provideSuggestionItems, CompletionOptions } from '@theia/monaco-editor-core/esm/vs/editor/contrib/suggest/browser/suggest';
32
- import { IDecorationOptions } from '@theia/monaco-editor-core/esm/vs/editor/common/editorCommon';
33
- import { StandaloneCodeEditor } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneCodeEditor';
34
- import { CompletionItemKind, CompletionContext } from '@theia/monaco-editor-core/esm/vs/editor/common/languages';
35
- import { ILanguageFeaturesService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/languageFeatures';
36
- import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
37
- import { TextModel } from '@theia/monaco-editor-core/esm/vs/editor/common/model/textModel';
38
- import { SelectComponent, SelectOption } from '@theia/core/lib/browser/widgets/select-component';
39
-
40
- export type ShowDebugBreakpointOptions = DebugSourceBreakpoint | {
41
- position: monaco.Position,
42
- context: DebugBreakpointWidget.Context
43
- } | {
44
- breakpoint: DebugSourceBreakpoint,
45
- context: DebugBreakpointWidget.Context
46
- };
47
-
48
- @injectable()
49
- export class DebugBreakpointWidget implements Disposable {
50
-
51
- @inject(DebugEditor)
52
- readonly editor: DebugEditor;
53
-
54
- @inject(MonacoEditorProvider)
55
- protected readonly editorProvider: MonacoEditorProvider;
56
-
57
- protected selectNode: HTMLDivElement;
58
- protected selectNodeRoot: Root;
59
-
60
- protected zone: MonacoEditorZoneWidget;
61
-
62
- protected readonly toDispose = new DisposableCollection();
63
-
64
- protected context: DebugBreakpointWidget.Context = 'condition';
65
- protected _values: {
66
- [context in DebugBreakpointWidget.Context]?: string
67
- } = {};
68
- get values(): {
69
- [context in DebugBreakpointWidget.Context]?: string
70
- } | undefined {
71
- if (!this._input) {
72
- return undefined;
73
- }
74
- return {
75
- ...this._values,
76
- [this.context]: this._input.getControl().getValue()
77
- };
78
- }
79
-
80
- protected _input: MonacoEditor | undefined;
81
- get input(): MonacoEditor | undefined {
82
- return this._input;
83
- }
84
- // eslint-disable-next-line no-null/no-null
85
- set inputSize(dimension: Dimension | null) {
86
- if (this._input) {
87
- if (dimension) {
88
- this._input.setSize(dimension);
89
- } else {
90
- this._input.resizeToFit();
91
- }
92
- }
93
- }
94
-
95
- private readonly selectComponentRef = React.createRef<SelectComponent>();
96
-
97
- @postConstruct()
98
- protected init(): void {
99
- this.doInit();
100
- }
101
-
102
- protected async doInit(): Promise<void> {
103
- this.toDispose.push(this.zone = new MonacoEditorZoneWidget(this.editor.getControl()));
104
- this.zone.containerNode.classList.add('theia-debug-breakpoint-widget');
105
-
106
- const selectNode = this.selectNode = document.createElement('div');
107
- selectNode.classList.add('theia-debug-breakpoint-select');
108
- this.zone.containerNode.appendChild(selectNode);
109
- this.selectNodeRoot = createRoot(this.selectNode);
110
- this.toDispose.push(Disposable.create(() => this.selectNodeRoot.unmount()));
111
-
112
- const inputNode = document.createElement('div');
113
- inputNode.classList.add('theia-debug-breakpoint-input');
114
- this.zone.containerNode.appendChild(inputNode);
115
-
116
- const input = this._input = await this.createInput(inputNode);
117
- if (this.toDispose.disposed) {
118
- input.dispose();
119
- return;
120
- }
121
- this.toDispose.push(input);
122
- this.toDispose.push((monaco.languages.registerCompletionItemProvider as (languageId: LanguageSelector, provider: monaco.languages.CompletionItemProvider) => Disposable)
123
- ({ scheme: input.uri.scheme }, {
124
- provideCompletionItems: async (model, position, context, token): Promise<monaco.languages.CompletionList> => {
125
- const suggestions: monaco.languages.CompletionItem[] = [];
126
- if ((this.context === 'condition' || this.context === 'logMessage')
127
- && input.uri.toString() === model.uri.toString()) {
128
- const editor = this.editor.getControl();
129
- const completions = await provideSuggestionItems(
130
- StandaloneServices.get(ILanguageFeaturesService).completionProvider,
131
- editor.getModel()! as unknown as TextModel,
132
- new monaco.Position(editor.getPosition()!.lineNumber, 1),
133
- new CompletionOptions(undefined, new Set<CompletionItemKind>().add(CompletionItemKind.Snippet)),
134
- context as unknown as CompletionContext, token);
135
- let overwriteBefore = 0;
136
- if (this.context === 'condition') {
137
- overwriteBefore = position.column - 1;
138
- } else {
139
- // Inside the curly brackets, need to count how many useful characters are behind the position so they would all be taken into account
140
- const value = editor.getModel()!.getValue();
141
- while ((position.column - 2 - overwriteBefore >= 0)
142
- && value[position.column - 2 - overwriteBefore] !== '{' && value[position.column - 2 - overwriteBefore] !== ' ') {
143
- overwriteBefore++;
144
- }
145
- }
146
- for (const { completion } of completions.items) {
147
- completion.range = monaco.Range.fromPositions(position.delta(0, -overwriteBefore), position);
148
- suggestions.push(completion as unknown as monaco.languages.CompletionItem);
149
- }
150
- }
151
- return { suggestions };
152
- }
153
- }));
154
- this.toDispose.push(this.zone.onDidLayoutChange(dimension => this.layout(dimension)));
155
- this.toDispose.push(input.getControl().onDidChangeModelContent(() => {
156
- const heightInLines = input.getControl().getModel()!.getLineCount() + 1;
157
- this.zone.layout(heightInLines);
158
- this.updatePlaceholder();
159
- }));
160
- this._input.getControl().createContextKey<boolean>('breakpointWidgetFocus', true);
161
- }
162
-
163
- dispose(): void {
164
- this.toDispose.dispose();
165
- }
166
-
167
- get position(): monaco.Position | undefined {
168
- const options = this.zone.options;
169
- return options && new monaco.Position(options.afterLineNumber, options.afterColumn || -1);
170
- }
171
-
172
- show(options: ShowDebugBreakpointOptions): void {
173
- if (!this._input) {
174
- return;
175
- }
176
- const breakpoint = options instanceof DebugSourceBreakpoint ? options : 'breakpoint' in options ? options.breakpoint : undefined;
177
- this._values = breakpoint ? {
178
- condition: breakpoint.condition,
179
- hitCondition: breakpoint.hitCondition,
180
- logMessage: breakpoint.logMessage
181
- } : {};
182
- if (options instanceof DebugSourceBreakpoint) {
183
- if (options.logMessage) {
184
- this.context = 'logMessage';
185
- } else if (options.hitCondition && !options.condition) {
186
- this.context = 'hitCondition';
187
- } else {
188
- this.context = 'condition';
189
- }
190
- } else {
191
- this.context = options.context;
192
- }
193
- this.render();
194
- const position = 'position' in options ? options.position : undefined;
195
- const afterLineNumber = breakpoint ? breakpoint.line : position!.lineNumber;
196
- const afterColumn = breakpoint ? breakpoint.column : position!.column;
197
- const editor = this._input.getControl();
198
- const heightInLines = editor.getModel()!.getLineCount() + 1;
199
- this.zone.show({ afterLineNumber, afterColumn, heightInLines, frameWidth: 1 });
200
- editor.setPosition(editor.getModel()!.getPositionAt(editor.getModel()!.getValueLength()));
201
- this._input.focus();
202
- this.editor.getControl().createContextKey<boolean>('isBreakpointWidgetVisible', true);
203
- }
204
-
205
- hide(): void {
206
- this.zone.hide();
207
- this.editor.getControl().createContextKey<boolean>('isBreakpointWidgetVisible', false);
208
- this.editor.focus();
209
- }
210
-
211
- protected layout(dimension: monaco.editor.IDimension): void {
212
- if (this._input) {
213
- this._input.getControl().layout(dimension);
214
- }
215
- }
216
-
217
- protected createInput(node: HTMLElement): Promise<MonacoEditor> {
218
- return this.editorProvider.createInline(new URI().withScheme('breakpointinput').withPath(this.editor.getControl().getId()), node, {
219
- autoSizing: false
220
- });
221
- }
222
-
223
- protected render(): void {
224
- if (this._input) {
225
- this._input.getControl().setValue(this._values[this.context] || '');
226
- }
227
- const selectComponent = this.selectComponentRef.current;
228
- if (selectComponent && selectComponent.value !== this.context) {
229
- selectComponent.value = this.context;
230
- }
231
- this.selectNodeRoot.render(<SelectComponent
232
- defaultValue={this.context} onChange={this.updateInput}
233
- options={[
234
- { value: 'condition', label: nls.localizeByDefault('Expression') },
235
- { value: 'hitCondition', label: nls.localizeByDefault('Hit Count') },
236
- { value: 'logMessage', label: nls.localizeByDefault('Log Message') },
237
- ]}
238
- ref={this.selectComponentRef}
239
- />);
240
- }
241
-
242
- protected readonly updateInput = (option: SelectOption) => {
243
- if (this._input) {
244
- this._values[this.context] = this._input.getControl().getValue();
245
- }
246
- this.context = option.value as DebugBreakpointWidget.Context;
247
- this.render();
248
- if (this._input) {
249
- this._input.focus();
250
- }
251
- };
252
-
253
- static PLACEHOLDER_DECORATION = 'placeholderDecoration';
254
- protected updatePlaceholder(): void {
255
- if (!this._input) {
256
- return;
257
- }
258
- const value = this._input.getControl().getValue();
259
- const decorations: IDecorationOptions[] = !!value ? [] : [{
260
- range: {
261
- startLineNumber: 0,
262
- endLineNumber: 0,
263
- startColumn: 0,
264
- endColumn: 1
265
- },
266
- renderOptions: {
267
- after: {
268
- contentText: this.placeholder,
269
- opacity: '0.4'
270
- }
271
- }
272
- }];
273
- (this._input.getControl() as unknown as StandaloneCodeEditor)
274
- .setDecorationsByType('Debug breakpoint placeholder', DebugBreakpointWidget.PLACEHOLDER_DECORATION, decorations);
275
- }
276
- protected get placeholder(): string {
277
- const acceptString = 'Enter';
278
- const closeString = 'Escape';
279
- if (this.context === 'logMessage') {
280
- return nls.localizeByDefault(
281
- "Message to log when breakpoint is hit. Expressions within {} are interpolated. '{0}' to accept, '{1}' to cancel.", acceptString, closeString
282
- );
283
- }
284
- if (this.context === 'hitCondition') {
285
- return nls.localizeByDefault("Break when hit count condition is met. '{0}' to accept, '{1}' to cancel.", acceptString, closeString);
286
- }
287
- return nls.localizeByDefault("Break when expression evaluates to true. '{0}' to accept, '{1}' to cancel.", acceptString, closeString);
288
- }
289
-
290
- }
291
- export namespace DebugBreakpointWidget {
292
- export type Context = keyof Pick<DebugProtocol.SourceBreakpoint, 'condition' | 'hitCondition' | 'logMessage'>;
293
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import * as React from '@theia/core/shared/react';
18
+ import { createRoot, Root } from '@theia/core/shared/react-dom/client';
19
+ import { DebugProtocol } from '@vscode/debugprotocol';
20
+ import { injectable, postConstruct, inject } from '@theia/core/shared/inversify';
21
+ import { Disposable, DisposableCollection, nls } from '@theia/core';
22
+ import URI from '@theia/core/lib/common/uri';
23
+ import { MonacoEditorProvider } from '@theia/monaco/lib/browser/monaco-editor-provider';
24
+ import { MonacoEditorZoneWidget } from '@theia/monaco/lib/browser/monaco-editor-zone-widget';
25
+ import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
26
+ import { DebugEditor } from './debug-editor';
27
+ import { DebugSourceBreakpoint } from '../model/debug-source-breakpoint';
28
+ import { Dimension } from '@theia/editor/lib/browser';
29
+ import * as monaco from '@theia/monaco-editor-core';
30
+ import { LanguageSelector } from '@theia/monaco-editor-core/esm/vs/editor/common/languageSelector';
31
+ import { provideSuggestionItems, CompletionOptions } from '@theia/monaco-editor-core/esm/vs/editor/contrib/suggest/browser/suggest';
32
+ import { IDecorationOptions } from '@theia/monaco-editor-core/esm/vs/editor/common/editorCommon';
33
+ import { StandaloneCodeEditor } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneCodeEditor';
34
+ import { CompletionItemKind, CompletionContext } from '@theia/monaco-editor-core/esm/vs/editor/common/languages';
35
+ import { ILanguageFeaturesService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/languageFeatures';
36
+ import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
37
+ import { TextModel } from '@theia/monaco-editor-core/esm/vs/editor/common/model/textModel';
38
+ import { SelectComponent, SelectOption } from '@theia/core/lib/browser/widgets/select-component';
39
+
40
+ export type ShowDebugBreakpointOptions = DebugSourceBreakpoint | {
41
+ position: monaco.Position,
42
+ context: DebugBreakpointWidget.Context
43
+ } | {
44
+ breakpoint: DebugSourceBreakpoint,
45
+ context: DebugBreakpointWidget.Context
46
+ };
47
+
48
+ @injectable()
49
+ export class DebugBreakpointWidget implements Disposable {
50
+
51
+ @inject(DebugEditor)
52
+ readonly editor: DebugEditor;
53
+
54
+ @inject(MonacoEditorProvider)
55
+ protected readonly editorProvider: MonacoEditorProvider;
56
+
57
+ protected selectNode: HTMLDivElement;
58
+ protected selectNodeRoot: Root;
59
+
60
+ protected zone: MonacoEditorZoneWidget;
61
+
62
+ protected readonly toDispose = new DisposableCollection();
63
+
64
+ protected context: DebugBreakpointWidget.Context = 'condition';
65
+ protected _values: {
66
+ [context in DebugBreakpointWidget.Context]?: string
67
+ } = {};
68
+ get values(): {
69
+ [context in DebugBreakpointWidget.Context]?: string
70
+ } | undefined {
71
+ if (!this._input) {
72
+ return undefined;
73
+ }
74
+ return {
75
+ ...this._values,
76
+ [this.context]: this._input.getControl().getValue()
77
+ };
78
+ }
79
+
80
+ protected _input: MonacoEditor | undefined;
81
+ get input(): MonacoEditor | undefined {
82
+ return this._input;
83
+ }
84
+ // eslint-disable-next-line no-null/no-null
85
+ set inputSize(dimension: Dimension | null) {
86
+ if (this._input) {
87
+ if (dimension) {
88
+ this._input.setSize(dimension);
89
+ } else {
90
+ this._input.resizeToFit();
91
+ }
92
+ }
93
+ }
94
+
95
+ private readonly selectComponentRef = React.createRef<SelectComponent>();
96
+
97
+ @postConstruct()
98
+ protected init(): void {
99
+ this.doInit();
100
+ }
101
+
102
+ protected async doInit(): Promise<void> {
103
+ this.toDispose.push(this.zone = new MonacoEditorZoneWidget(this.editor.getControl()));
104
+ this.zone.containerNode.classList.add('theia-debug-breakpoint-widget');
105
+
106
+ const selectNode = this.selectNode = document.createElement('div');
107
+ selectNode.classList.add('theia-debug-breakpoint-select');
108
+ this.zone.containerNode.appendChild(selectNode);
109
+ this.selectNodeRoot = createRoot(this.selectNode);
110
+ this.toDispose.push(Disposable.create(() => this.selectNodeRoot.unmount()));
111
+
112
+ const inputNode = document.createElement('div');
113
+ inputNode.classList.add('theia-debug-breakpoint-input');
114
+ this.zone.containerNode.appendChild(inputNode);
115
+
116
+ const input = this._input = await this.createInput(inputNode);
117
+ if (this.toDispose.disposed) {
118
+ input.dispose();
119
+ return;
120
+ }
121
+ this.toDispose.push(input);
122
+ this.toDispose.push((monaco.languages.registerCompletionItemProvider as (languageId: LanguageSelector, provider: monaco.languages.CompletionItemProvider) => Disposable)
123
+ ({ scheme: input.uri.scheme }, {
124
+ provideCompletionItems: async (model, position, context, token): Promise<monaco.languages.CompletionList> => {
125
+ const suggestions: monaco.languages.CompletionItem[] = [];
126
+ if ((this.context === 'condition' || this.context === 'logMessage')
127
+ && input.uri.toString() === model.uri.toString()) {
128
+ const editor = this.editor.getControl();
129
+ const completions = await provideSuggestionItems(
130
+ StandaloneServices.get(ILanguageFeaturesService).completionProvider,
131
+ editor.getModel()! as unknown as TextModel,
132
+ new monaco.Position(editor.getPosition()!.lineNumber, 1),
133
+ new CompletionOptions(undefined, new Set<CompletionItemKind>().add(CompletionItemKind.Snippet)),
134
+ context as unknown as CompletionContext, token);
135
+ let overwriteBefore = 0;
136
+ if (this.context === 'condition') {
137
+ overwriteBefore = position.column - 1;
138
+ } else {
139
+ // Inside the curly brackets, need to count how many useful characters are behind the position so they would all be taken into account
140
+ const value = editor.getModel()!.getValue();
141
+ while ((position.column - 2 - overwriteBefore >= 0)
142
+ && value[position.column - 2 - overwriteBefore] !== '{' && value[position.column - 2 - overwriteBefore] !== ' ') {
143
+ overwriteBefore++;
144
+ }
145
+ }
146
+ for (const { completion } of completions.items) {
147
+ completion.range = monaco.Range.fromPositions(position.delta(0, -overwriteBefore), position);
148
+ suggestions.push(completion as unknown as monaco.languages.CompletionItem);
149
+ }
150
+ }
151
+ return { suggestions };
152
+ }
153
+ }));
154
+ this.toDispose.push(this.zone.onDidLayoutChange(dimension => this.layout(dimension)));
155
+ this.toDispose.push(input.getControl().onDidChangeModelContent(() => {
156
+ const heightInLines = input.getControl().getModel()!.getLineCount() + 1;
157
+ this.zone.layout(heightInLines);
158
+ this.updatePlaceholder();
159
+ }));
160
+ this._input.getControl().createContextKey<boolean>('breakpointWidgetFocus', true);
161
+ }
162
+
163
+ dispose(): void {
164
+ this.toDispose.dispose();
165
+ }
166
+
167
+ get position(): monaco.Position | undefined {
168
+ const options = this.zone.options;
169
+ return options && new monaco.Position(options.afterLineNumber, options.afterColumn || -1);
170
+ }
171
+
172
+ show(options: ShowDebugBreakpointOptions): void {
173
+ if (!this._input) {
174
+ return;
175
+ }
176
+ const breakpoint = options instanceof DebugSourceBreakpoint ? options : 'breakpoint' in options ? options.breakpoint : undefined;
177
+ this._values = breakpoint ? {
178
+ condition: breakpoint.condition,
179
+ hitCondition: breakpoint.hitCondition,
180
+ logMessage: breakpoint.logMessage
181
+ } : {};
182
+ if (options instanceof DebugSourceBreakpoint) {
183
+ if (options.logMessage) {
184
+ this.context = 'logMessage';
185
+ } else if (options.hitCondition && !options.condition) {
186
+ this.context = 'hitCondition';
187
+ } else {
188
+ this.context = 'condition';
189
+ }
190
+ } else {
191
+ this.context = options.context;
192
+ }
193
+ this.render();
194
+ const position = 'position' in options ? options.position : undefined;
195
+ const afterLineNumber = breakpoint ? breakpoint.line : position!.lineNumber;
196
+ const afterColumn = breakpoint ? breakpoint.column : position!.column;
197
+ const editor = this._input.getControl();
198
+ const heightInLines = editor.getModel()!.getLineCount() + 1;
199
+ this.zone.show({ afterLineNumber, afterColumn, heightInLines, frameWidth: 1 });
200
+ editor.setPosition(editor.getModel()!.getPositionAt(editor.getModel()!.getValueLength()));
201
+ this._input.focus();
202
+ this.editor.getControl().createContextKey<boolean>('isBreakpointWidgetVisible', true);
203
+ }
204
+
205
+ hide(): void {
206
+ this.zone.hide();
207
+ this.editor.getControl().createContextKey<boolean>('isBreakpointWidgetVisible', false);
208
+ this.editor.focus();
209
+ }
210
+
211
+ protected layout(dimension: monaco.editor.IDimension): void {
212
+ if (this._input) {
213
+ this._input.getControl().layout(dimension);
214
+ }
215
+ }
216
+
217
+ protected createInput(node: HTMLElement): Promise<MonacoEditor> {
218
+ return this.editorProvider.createInline(new URI().withScheme('breakpointinput').withPath(this.editor.getControl().getId()), node, {
219
+ autoSizing: false
220
+ });
221
+ }
222
+
223
+ protected render(): void {
224
+ if (this._input) {
225
+ this._input.getControl().setValue(this._values[this.context] || '');
226
+ }
227
+ const selectComponent = this.selectComponentRef.current;
228
+ if (selectComponent && selectComponent.value !== this.context) {
229
+ selectComponent.value = this.context;
230
+ }
231
+ this.selectNodeRoot.render(<SelectComponent
232
+ defaultValue={this.context} onChange={this.updateInput}
233
+ options={[
234
+ { value: 'condition', label: nls.localizeByDefault('Expression') },
235
+ { value: 'hitCondition', label: nls.localizeByDefault('Hit Count') },
236
+ { value: 'logMessage', label: nls.localizeByDefault('Log Message') },
237
+ ]}
238
+ ref={this.selectComponentRef}
239
+ />);
240
+ }
241
+
242
+ protected readonly updateInput = (option: SelectOption) => {
243
+ if (this._input) {
244
+ this._values[this.context] = this._input.getControl().getValue();
245
+ }
246
+ this.context = option.value as DebugBreakpointWidget.Context;
247
+ this.render();
248
+ if (this._input) {
249
+ this._input.focus();
250
+ }
251
+ };
252
+
253
+ static PLACEHOLDER_DECORATION = 'placeholderDecoration';
254
+ protected updatePlaceholder(): void {
255
+ if (!this._input) {
256
+ return;
257
+ }
258
+ const value = this._input.getControl().getValue();
259
+ const decorations: IDecorationOptions[] = !!value ? [] : [{
260
+ range: {
261
+ startLineNumber: 0,
262
+ endLineNumber: 0,
263
+ startColumn: 0,
264
+ endColumn: 1
265
+ },
266
+ renderOptions: {
267
+ after: {
268
+ contentText: this.placeholder,
269
+ opacity: '0.4'
270
+ }
271
+ }
272
+ }];
273
+ (this._input.getControl() as unknown as StandaloneCodeEditor)
274
+ .setDecorationsByType('Debug breakpoint placeholder', DebugBreakpointWidget.PLACEHOLDER_DECORATION, decorations);
275
+ }
276
+ protected get placeholder(): string {
277
+ const acceptString = 'Enter';
278
+ const closeString = 'Escape';
279
+ if (this.context === 'logMessage') {
280
+ return nls.localizeByDefault(
281
+ "Message to log when breakpoint is hit. Expressions within {} are interpolated. '{0}' to accept, '{1}' to cancel.", acceptString, closeString
282
+ );
283
+ }
284
+ if (this.context === 'hitCondition') {
285
+ return nls.localizeByDefault("Break when hit count condition is met. '{0}' to accept, '{1}' to cancel.", acceptString, closeString);
286
+ }
287
+ return nls.localizeByDefault("Break when expression evaluates to true. '{0}' to accept, '{1}' to cancel.", acceptString, closeString);
288
+ }
289
+
290
+ }
291
+ export namespace DebugBreakpointWidget {
292
+ export type Context = keyof Pick<DebugProtocol.SourceBreakpoint, 'condition' | 'hitCondition' | 'logMessage'>;
293
+ }