@theia/debug 1.53.0-next.4 → 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.
- package/README.md +62 -62
- package/lib/browser/debug-configuration-manager.js +6 -6
- package/lib/browser/debug-frontend-application-contribution.d.ts.map +1 -1
- package/lib/browser/debug-frontend-application-contribution.js.map +1 -1
- package/lib/common/inline-debug-adapter.d.ts +1 -0
- package/lib/common/inline-debug-adapter.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/browser/breakpoint/breakpoint-manager.ts +369 -369
- package/src/browser/breakpoint/breakpoint-marker.ts +104 -104
- package/src/browser/console/debug-console-contribution.tsx +240 -240
- package/src/browser/console/debug-console-items.tsx +384 -384
- package/src/browser/console/debug-console-session.ts +205 -205
- package/src/browser/debug-call-stack-item-type-key.ts +20 -20
- package/src/browser/debug-configuration-manager.ts +591 -591
- package/src/browser/debug-configuration-model.ts +100 -100
- package/src/browser/debug-contribution.ts +43 -43
- package/src/browser/debug-frontend-application-contribution.ts +1551 -1551
- package/src/browser/debug-frontend-module.ts +133 -133
- package/src/browser/debug-package.spec.ts +20 -20
- package/src/browser/debug-preferences.ts +98 -98
- package/src/browser/debug-prefix-configuration.ts +195 -195
- package/src/browser/debug-resource.ts +59 -59
- package/src/browser/debug-schema-updater.ts +149 -149
- package/src/browser/debug-session-connection.ts +357 -357
- package/src/browser/debug-session-contribution.ts +157 -157
- package/src/browser/debug-session-manager.ts +683 -683
- package/src/browser/debug-session-options.ts +120 -120
- package/src/browser/debug-session.tsx +974 -974
- package/src/browser/debug-tab-bar-decorator.ts +57 -57
- package/src/browser/debug-watch-manager.ts +93 -93
- package/src/browser/disassembly-view/disassembly-view-accessibility-provider.ts +43 -43
- package/src/browser/disassembly-view/disassembly-view-breakpoint-renderer.ts +119 -119
- package/src/browser/disassembly-view/disassembly-view-contribution.ts +109 -109
- package/src/browser/disassembly-view/disassembly-view-instruction-renderer.ts +245 -245
- package/src/browser/disassembly-view/disassembly-view-table-delegate.ts +39 -39
- package/src/browser/disassembly-view/disassembly-view-utilities.ts +55 -55
- package/src/browser/disassembly-view/disassembly-view-widget.ts +463 -463
- package/src/browser/editor/debug-breakpoint-widget.tsx +293 -293
- package/src/browser/editor/debug-editor-model.ts +529 -529
- package/src/browser/editor/debug-editor-service.ts +192 -192
- package/src/browser/editor/debug-editor.ts +20 -20
- package/src/browser/editor/debug-exception-widget.tsx +122 -122
- package/src/browser/editor/debug-expression-provider.ts +78 -78
- package/src/browser/editor/debug-hover-source.tsx +105 -105
- package/src/browser/editor/debug-hover-widget.ts +298 -298
- package/src/browser/editor/debug-inline-value-decorator.ts +373 -373
- package/src/browser/model/debug-breakpoint.tsx +151 -151
- package/src/browser/model/debug-function-breakpoint.tsx +101 -101
- package/src/browser/model/debug-instruction-breakpoint.tsx +68 -68
- package/src/browser/model/debug-source-breakpoint.tsx +237 -237
- package/src/browser/model/debug-source.ts +93 -93
- package/src/browser/model/debug-stack-frame.tsx +177 -177
- package/src/browser/model/debug-thread.tsx +292 -292
- package/src/browser/preferences/launch-preferences.ts +38 -38
- package/src/browser/style/index.css +453 -453
- package/src/browser/view/debug-action.tsx +57 -57
- package/src/browser/view/debug-breakpoints-source.tsx +53 -53
- package/src/browser/view/debug-breakpoints-widget.ts +71 -71
- package/src/browser/view/debug-configuration-select.tsx +269 -269
- package/src/browser/view/debug-configuration-widget.tsx +121 -121
- package/src/browser/view/debug-exception-breakpoint.tsx +68 -68
- package/src/browser/view/debug-session-widget.ts +124 -124
- package/src/browser/view/debug-stack-frames-source.tsx +75 -75
- package/src/browser/view/debug-stack-frames-widget.ts +135 -135
- package/src/browser/view/debug-threads-source.tsx +48 -48
- package/src/browser/view/debug-threads-widget.ts +126 -126
- package/src/browser/view/debug-toolbar-widget.tsx +145 -145
- package/src/browser/view/debug-variables-source.ts +43 -43
- package/src/browser/view/debug-variables-widget.ts +61 -61
- package/src/browser/view/debug-view-model.ts +230 -230
- package/src/browser/view/debug-watch-expression.tsx +88 -88
- package/src/browser/view/debug-watch-source.ts +41 -41
- package/src/browser/view/debug-watch-widget.ts +61 -61
- package/src/browser/view/debug-widget.ts +97 -97
- package/src/common/debug-adapter-contribution-registry.ts +206 -206
- package/src/common/debug-adapter-session.ts +102 -102
- package/src/common/debug-common.ts +19 -19
- package/src/common/debug-compound.ts +33 -33
- package/src/common/debug-configuration.ts +112 -112
- package/src/common/debug-model.ts +200 -200
- package/src/common/debug-service.ts +184 -184
- package/src/common/debug-uri-utils.ts +24 -24
- package/src/common/inline-debug-adapter.ts +47 -47
- package/src/node/debug-adapter-factory.ts +107 -107
- package/src/node/debug-adapter-session-manager.ts +106 -106
- package/src/node/debug-backend-module.ts +57 -57
- package/src/node/debug-service-impl.ts +119 -119
- 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
|
+
}
|