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

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 (86) hide show
  1. package/README.md +62 -62
  2. package/lib/browser/debug-configuration-manager.js +6 -6
  3. package/lib/common/inline-debug-adapter.d.ts +0 -1
  4. package/lib/common/inline-debug-adapter.d.ts.map +1 -1
  5. package/package.json +15 -15
  6. package/src/browser/breakpoint/breakpoint-manager.ts +369 -369
  7. package/src/browser/breakpoint/breakpoint-marker.ts +104 -104
  8. package/src/browser/console/debug-console-contribution.tsx +240 -240
  9. package/src/browser/console/debug-console-items.tsx +384 -384
  10. package/src/browser/console/debug-console-session.ts +205 -205
  11. package/src/browser/debug-call-stack-item-type-key.ts +20 -20
  12. package/src/browser/debug-configuration-manager.ts +591 -591
  13. package/src/browser/debug-configuration-model.ts +100 -100
  14. package/src/browser/debug-contribution.ts +43 -43
  15. package/src/browser/debug-frontend-application-contribution.ts +1551 -1551
  16. package/src/browser/debug-frontend-module.ts +133 -133
  17. package/src/browser/debug-package.spec.ts +20 -20
  18. package/src/browser/debug-preferences.ts +98 -98
  19. package/src/browser/debug-prefix-configuration.ts +195 -195
  20. package/src/browser/debug-resource.ts +59 -59
  21. package/src/browser/debug-schema-updater.ts +149 -149
  22. package/src/browser/debug-session-connection.ts +357 -357
  23. package/src/browser/debug-session-contribution.ts +157 -157
  24. package/src/browser/debug-session-manager.ts +683 -683
  25. package/src/browser/debug-session-options.ts +120 -120
  26. package/src/browser/debug-session.tsx +974 -974
  27. package/src/browser/debug-tab-bar-decorator.ts +57 -57
  28. package/src/browser/debug-watch-manager.ts +93 -93
  29. package/src/browser/disassembly-view/disassembly-view-accessibility-provider.ts +43 -43
  30. package/src/browser/disassembly-view/disassembly-view-breakpoint-renderer.ts +119 -119
  31. package/src/browser/disassembly-view/disassembly-view-contribution.ts +109 -109
  32. package/src/browser/disassembly-view/disassembly-view-instruction-renderer.ts +245 -245
  33. package/src/browser/disassembly-view/disassembly-view-table-delegate.ts +39 -39
  34. package/src/browser/disassembly-view/disassembly-view-utilities.ts +55 -55
  35. package/src/browser/disassembly-view/disassembly-view-widget.ts +463 -463
  36. package/src/browser/editor/debug-breakpoint-widget.tsx +293 -293
  37. package/src/browser/editor/debug-editor-model.ts +529 -529
  38. package/src/browser/editor/debug-editor-service.ts +192 -192
  39. package/src/browser/editor/debug-editor.ts +20 -20
  40. package/src/browser/editor/debug-exception-widget.tsx +122 -122
  41. package/src/browser/editor/debug-expression-provider.ts +78 -78
  42. package/src/browser/editor/debug-hover-source.tsx +105 -105
  43. package/src/browser/editor/debug-hover-widget.ts +298 -298
  44. package/src/browser/editor/debug-inline-value-decorator.ts +373 -373
  45. package/src/browser/model/debug-breakpoint.tsx +151 -151
  46. package/src/browser/model/debug-function-breakpoint.tsx +101 -101
  47. package/src/browser/model/debug-instruction-breakpoint.tsx +68 -68
  48. package/src/browser/model/debug-source-breakpoint.tsx +237 -237
  49. package/src/browser/model/debug-source.ts +93 -93
  50. package/src/browser/model/debug-stack-frame.tsx +177 -177
  51. package/src/browser/model/debug-thread.tsx +292 -292
  52. package/src/browser/preferences/launch-preferences.ts +38 -38
  53. package/src/browser/style/index.css +453 -453
  54. package/src/browser/view/debug-action.tsx +57 -57
  55. package/src/browser/view/debug-breakpoints-source.tsx +53 -53
  56. package/src/browser/view/debug-breakpoints-widget.ts +71 -71
  57. package/src/browser/view/debug-configuration-select.tsx +269 -269
  58. package/src/browser/view/debug-configuration-widget.tsx +121 -121
  59. package/src/browser/view/debug-exception-breakpoint.tsx +68 -68
  60. package/src/browser/view/debug-session-widget.ts +124 -124
  61. package/src/browser/view/debug-stack-frames-source.tsx +75 -75
  62. package/src/browser/view/debug-stack-frames-widget.ts +135 -135
  63. package/src/browser/view/debug-threads-source.tsx +48 -48
  64. package/src/browser/view/debug-threads-widget.ts +126 -126
  65. package/src/browser/view/debug-toolbar-widget.tsx +145 -145
  66. package/src/browser/view/debug-variables-source.ts +43 -43
  67. package/src/browser/view/debug-variables-widget.ts +61 -61
  68. package/src/browser/view/debug-view-model.ts +230 -230
  69. package/src/browser/view/debug-watch-expression.tsx +88 -88
  70. package/src/browser/view/debug-watch-source.ts +41 -41
  71. package/src/browser/view/debug-watch-widget.ts +61 -61
  72. package/src/browser/view/debug-widget.ts +97 -97
  73. package/src/common/debug-adapter-contribution-registry.ts +206 -206
  74. package/src/common/debug-adapter-session.ts +102 -102
  75. package/src/common/debug-common.ts +19 -19
  76. package/src/common/debug-compound.ts +33 -33
  77. package/src/common/debug-configuration.ts +112 -112
  78. package/src/common/debug-model.ts +200 -200
  79. package/src/common/debug-service.ts +184 -184
  80. package/src/common/debug-uri-utils.ts +24 -24
  81. package/src/common/inline-debug-adapter.ts +47 -47
  82. package/src/node/debug-adapter-factory.ts +107 -107
  83. package/src/node/debug-adapter-session-manager.ts +106 -106
  84. package/src/node/debug-backend-module.ts +57 -57
  85. package/src/node/debug-service-impl.ts +119 -119
  86. package/src/node/stream-debug-adapter.ts +126 -126
@@ -1,529 +1,529 @@
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 debounce = require('p-debounce');
18
- import { injectable, inject, postConstruct, interfaces, Container } from '@theia/core/shared/inversify';
19
- import * as monaco from '@theia/monaco-editor-core';
20
- import { IConfigurationService } from '@theia/monaco-editor-core/esm/vs/platform/configuration/common/configuration';
21
- import { StandaloneCodeEditor } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneCodeEditor';
22
- import { IDecorationOptions } from '@theia/monaco-editor-core/esm/vs/editor/common/editorCommon';
23
- import { IEditorHoverOptions } from '@theia/monaco-editor-core/esm/vs/editor/common/config/editorOptions';
24
- import URI from '@theia/core/lib/common/uri';
25
- import { Disposable, DisposableCollection, MenuPath, isOSX } from '@theia/core';
26
- import { ContextMenuRenderer } from '@theia/core/lib/browser';
27
- import { BreakpointManager, SourceBreakpointsChangeEvent } from '../breakpoint/breakpoint-manager';
28
- import { DebugSourceBreakpoint } from '../model/debug-source-breakpoint';
29
- import { DebugSessionManager } from '../debug-session-manager';
30
- import { SourceBreakpoint } from '../breakpoint/breakpoint-marker';
31
- import { DebugEditor } from './debug-editor';
32
- import { DebugHoverWidget, createDebugHoverWidgetContainer } from './debug-hover-widget';
33
- import { DebugBreakpointWidget } from './debug-breakpoint-widget';
34
- import { DebugExceptionWidget } from './debug-exception-widget';
35
- import { DebugProtocol } from '@vscode/debugprotocol';
36
- import { DebugInlineValueDecorator, INLINE_VALUE_DECORATION_KEY } from './debug-inline-value-decorator';
37
- import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
38
-
39
- export const DebugEditorModelFactory = Symbol('DebugEditorModelFactory');
40
- export type DebugEditorModelFactory = (editor: DebugEditor) => DebugEditorModel;
41
-
42
- @injectable()
43
- export class DebugEditorModel implements Disposable {
44
-
45
- static createContainer(parent: interfaces.Container, editor: DebugEditor): Container {
46
- const child = createDebugHoverWidgetContainer(parent, editor);
47
- child.bind(DebugEditorModel).toSelf();
48
- child.bind(DebugBreakpointWidget).toSelf();
49
- child.bind(DebugExceptionWidget).toSelf();
50
- return child;
51
- }
52
- static createModel(parent: interfaces.Container, editor: DebugEditor): DebugEditorModel {
53
- return DebugEditorModel.createContainer(parent, editor).get(DebugEditorModel);
54
- }
55
-
56
- static CONTEXT_MENU: MenuPath = ['debug-editor-context-menu'];
57
-
58
- protected readonly toDispose = new DisposableCollection();
59
- protected readonly toDisposeOnUpdate = new DisposableCollection();
60
-
61
- protected uri: URI;
62
-
63
- protected breakpointDecorations: string[] = [];
64
- protected breakpointRanges = new Map<string, [monaco.Range, SourceBreakpoint]>();
65
-
66
- protected currentBreakpointDecorations: string[] = [];
67
-
68
- protected editorDecorations: string[] = [];
69
- protected topFrameRange: monaco.Range | undefined;
70
-
71
- protected updatingDecorations = false;
72
-
73
- @inject(DebugHoverWidget)
74
- readonly hover: DebugHoverWidget;
75
-
76
- @inject(DebugEditor)
77
- readonly editor: DebugEditor;
78
-
79
- @inject(BreakpointManager)
80
- readonly breakpoints: BreakpointManager;
81
-
82
- @inject(DebugSessionManager)
83
- readonly sessions: DebugSessionManager;
84
-
85
- @inject(ContextMenuRenderer)
86
- readonly contextMenu: ContextMenuRenderer;
87
-
88
- @inject(DebugBreakpointWidget)
89
- readonly breakpointWidget: DebugBreakpointWidget;
90
-
91
- @inject(DebugExceptionWidget)
92
- readonly exceptionWidget: DebugExceptionWidget;
93
-
94
- @inject(DebugInlineValueDecorator)
95
- readonly inlineValueDecorator: DebugInlineValueDecorator;
96
-
97
- @inject(DebugSessionManager)
98
- protected readonly sessionManager: DebugSessionManager;
99
-
100
- @postConstruct()
101
- protected init(): void {
102
- this.uri = new URI(this.editor.getControl().getModel()!.uri.toString());
103
- this.toDispose.pushAll([
104
- this.hover,
105
- this.breakpointWidget,
106
- this.exceptionWidget,
107
- this.editor.getControl().onMouseDown(event => this.handleMouseDown(event)),
108
- this.editor.getControl().onMouseMove(event => this.handleMouseMove(event)),
109
- this.editor.getControl().onMouseLeave(event => this.handleMouseLeave(event)),
110
- this.editor.getControl().onKeyDown(() => this.hover.hide({ immediate: false })),
111
- this.editor.getControl().onDidChangeModelContent(() => this.update()),
112
- this.editor.getControl().getModel()!.onDidChangeDecorations(() => this.updateBreakpoints()),
113
- this.editor.onDidResize(e => this.breakpointWidget.inputSize = e),
114
- this.sessions.onDidChange(() => this.update()),
115
- this.toDisposeOnUpdate,
116
- this.sessionManager.onDidChangeBreakpoints(({ session, uri }) => {
117
- if ((!session || session === this.sessionManager.currentSession) && uri.isEqual(this.uri)) {
118
- this.render();
119
- }
120
- }),
121
- this.breakpoints.onDidChangeBreakpoints(event => this.closeBreakpointIfAffected(event)),
122
- ]);
123
- this.update();
124
- this.render();
125
- }
126
-
127
- dispose(): void {
128
- this.toDispose.dispose();
129
- }
130
-
131
- protected readonly update = debounce(async () => {
132
- if (this.toDispose.disposed) {
133
- return;
134
- }
135
- this.toDisposeOnUpdate.dispose();
136
- this.toggleExceptionWidget();
137
- await this.updateEditorDecorations();
138
- this.updateEditorHover();
139
- }, 100);
140
-
141
- /**
142
- * To disable the default editor-contribution hover from Code when
143
- * the editor has the `currentFrame`. Otherwise, both `textdocument/hover`
144
- * and the debug hovers are visible at the same time when hovering over a symbol.
145
- */
146
- protected async updateEditorHover(): Promise<void> {
147
- if (this.sessions.isCurrentEditorFrame(this.uri)) {
148
- const codeEditor = this.editor.getControl();
149
- codeEditor.updateOptions({ hover: { enabled: false } });
150
- this.toDisposeOnUpdate.push(Disposable.create(() => {
151
- const model = codeEditor.getModel()!;
152
- const overrides = {
153
- resource: model.uri,
154
- overrideIdentifier: model.getLanguageId(),
155
- };
156
- const { enabled, delay, sticky } = StandaloneServices.get(IConfigurationService).getValue<IEditorHoverOptions>('editor.hover', overrides);
157
- codeEditor.updateOptions({
158
- hover: {
159
- enabled,
160
- delay,
161
- sticky
162
- }
163
- });
164
- }));
165
- }
166
- }
167
-
168
- protected async updateEditorDecorations(): Promise<void> {
169
- const [newFrameDecorations, inlineValueDecorations] = await Promise.all([
170
- this.createFrameDecorations(),
171
- this.createInlineValueDecorations()
172
- ]);
173
- const codeEditor = this.editor.getControl() as unknown as StandaloneCodeEditor;
174
- codeEditor.removeDecorations([INLINE_VALUE_DECORATION_KEY]);
175
- codeEditor.setDecorationsByType('Inline debug decorations', INLINE_VALUE_DECORATION_KEY, inlineValueDecorations);
176
- this.editorDecorations = this.deltaDecorations(this.editorDecorations, newFrameDecorations);
177
- }
178
-
179
- protected async createInlineValueDecorations(): Promise<IDecorationOptions[]> {
180
- if (!this.sessions.isCurrentEditorFrame(this.uri)) {
181
- return [];
182
- }
183
- const { currentFrame } = this.sessions;
184
- return this.inlineValueDecorator.calculateDecorations(this, currentFrame);
185
- }
186
-
187
- protected createFrameDecorations(): monaco.editor.IModelDeltaDecoration[] {
188
- const { currentFrame, topFrame } = this.sessions;
189
- if (!currentFrame) {
190
- return [];
191
- }
192
-
193
- if (!currentFrame.thread.stopped) {
194
- return [];
195
- }
196
-
197
- if (!this.sessions.isCurrentEditorFrame(this.uri)) {
198
- return [];
199
- }
200
-
201
- const decorations: monaco.editor.IModelDeltaDecoration[] = [];
202
- const columnUntilEOLRange = new monaco.Range(currentFrame.raw.line, currentFrame.raw.column, currentFrame.raw.line, 1 << 30);
203
- const range = new monaco.Range(currentFrame.raw.line, currentFrame.raw.column, currentFrame.raw.line, currentFrame.raw.column + 1);
204
-
205
- if (topFrame === currentFrame) {
206
- decorations.push({
207
- options: DebugEditorModel.TOP_STACK_FRAME_MARGIN,
208
- range
209
- });
210
- decorations.push({
211
- options: DebugEditorModel.TOP_STACK_FRAME_DECORATION,
212
- range: columnUntilEOLRange
213
- });
214
- const { topFrameRange } = this;
215
- if (topFrameRange && topFrameRange.startLineNumber === currentFrame.raw.line && topFrameRange.startColumn !== currentFrame.raw.column) {
216
- decorations.push({
217
- options: DebugEditorModel.TOP_STACK_FRAME_INLINE_DECORATION,
218
- range: columnUntilEOLRange
219
- });
220
- }
221
- this.topFrameRange = columnUntilEOLRange;
222
- } else {
223
- decorations.push({
224
- options: DebugEditorModel.FOCUSED_STACK_FRAME_MARGIN,
225
- range
226
- });
227
- decorations.push({
228
- options: DebugEditorModel.FOCUSED_STACK_FRAME_DECORATION,
229
- range: columnUntilEOLRange
230
- });
231
- }
232
- return decorations;
233
- }
234
-
235
- protected async toggleExceptionWidget(): Promise<void> {
236
- const { currentFrame } = this.sessions;
237
- if (!currentFrame) {
238
- return;
239
- }
240
- if (!this.sessions.isCurrentEditorFrame(this.uri)) {
241
- this.exceptionWidget.hide();
242
- return;
243
- }
244
- const info = await currentFrame.thread.getExceptionInfo();
245
- if (!info) {
246
- this.exceptionWidget.hide();
247
- return;
248
- }
249
- this.exceptionWidget.show({
250
- info,
251
- lineNumber: currentFrame.raw.line,
252
- column: currentFrame.raw.column
253
- });
254
- }
255
-
256
- render(): void {
257
- this.renderBreakpoints();
258
- this.renderCurrentBreakpoints();
259
- }
260
- protected renderBreakpoints(): void {
261
- const breakpoints = this.breakpoints.getBreakpoints(this.uri);
262
- const decorations = this.createBreakpointDecorations(breakpoints);
263
- this.breakpointDecorations = this.deltaDecorations(this.breakpointDecorations, decorations);
264
- this.updateBreakpointRanges(breakpoints);
265
- }
266
- protected createBreakpointDecorations(breakpoints: SourceBreakpoint[]): monaco.editor.IModelDeltaDecoration[] {
267
- return breakpoints.map(breakpoint => this.createBreakpointDecoration(breakpoint));
268
- }
269
- protected createBreakpointDecoration(breakpoint: SourceBreakpoint): monaco.editor.IModelDeltaDecoration {
270
- const lineNumber = breakpoint.raw.line;
271
- const column = breakpoint.raw.column;
272
- const range = typeof column === 'number' ? new monaco.Range(lineNumber, column, lineNumber, column + 1) : new monaco.Range(lineNumber, 1, lineNumber, 2);
273
- return {
274
- range,
275
- options: {
276
- stickiness: DebugEditorModel.STICKINESS
277
- }
278
- };
279
- }
280
-
281
- protected updateBreakpointRanges(breakpoints: SourceBreakpoint[]): void {
282
- this.breakpointRanges.clear();
283
- for (let i = 0; i < this.breakpointDecorations.length; i++) {
284
- const decoration = this.breakpointDecorations[i];
285
- const breakpoint = breakpoints[i];
286
- const range = this.editor.getControl().getModel()!.getDecorationRange(decoration)!;
287
- this.breakpointRanges.set(decoration, [range, breakpoint]);
288
- }
289
- }
290
-
291
- protected renderCurrentBreakpoints(): void {
292
- const decorations = this.createCurrentBreakpointDecorations();
293
- this.currentBreakpointDecorations = this.deltaDecorations(this.currentBreakpointDecorations, decorations);
294
- }
295
- protected createCurrentBreakpointDecorations(): monaco.editor.IModelDeltaDecoration[] {
296
- const breakpoints = this.sessions.getBreakpoints(this.uri);
297
- return breakpoints.map(breakpoint => this.createCurrentBreakpointDecoration(breakpoint));
298
- }
299
- protected createCurrentBreakpointDecoration(breakpoint: DebugSourceBreakpoint): monaco.editor.IModelDeltaDecoration {
300
- const lineNumber = breakpoint.line;
301
- const column = breakpoint.column;
302
- const range = typeof column === 'number' ? new monaco.Range(lineNumber, column, lineNumber, column + 1) : new monaco.Range(lineNumber, 1, lineNumber, 1);
303
- const { className, message } = breakpoint.getDecoration();
304
- const renderInline = typeof column === 'number' && (column > this.editor.getControl().getModel()!.getLineFirstNonWhitespaceColumn(lineNumber));
305
- return {
306
- range,
307
- options: {
308
- glyphMarginClassName: className,
309
- glyphMarginHoverMessage: message.map(value => ({ value })),
310
- stickiness: DebugEditorModel.STICKINESS,
311
- beforeContentClassName: renderInline ? `theia-debug-breakpoint-column codicon ${className}` : undefined
312
- }
313
- };
314
- }
315
-
316
- protected updateBreakpoints(): void {
317
- if (this.areBreakpointsAffected()) {
318
- const breakpoints = this.createBreakpoints();
319
- this.breakpoints.setBreakpoints(this.uri, breakpoints);
320
- }
321
- }
322
- protected areBreakpointsAffected(): boolean {
323
- if (this.updatingDecorations || !this.editor.getControl().getModel()) {
324
- return false;
325
- }
326
- for (const decoration of this.breakpointDecorations) {
327
- const range = this.editor.getControl().getModel()!.getDecorationRange(decoration);
328
- const oldRange = this.breakpointRanges.get(decoration)![0];
329
- if (!range || !range.equalsRange(oldRange)) {
330
- return true;
331
- }
332
- }
333
- return false;
334
- }
335
- protected createBreakpoints(): SourceBreakpoint[] {
336
- const { uri } = this;
337
- const lines = new Set<number>();
338
- const breakpoints: SourceBreakpoint[] = [];
339
- for (const decoration of this.breakpointDecorations) {
340
- const range = this.editor.getControl().getModel()!.getDecorationRange(decoration);
341
- if (range && !lines.has(range.startLineNumber)) {
342
- const line = range.startLineNumber;
343
- const column = range.startColumn;
344
- const oldBreakpoint = this.breakpointRanges.get(decoration)?.[1];
345
- const isLineBreakpoint = oldBreakpoint?.raw.line !== undefined && oldBreakpoint?.raw.column === undefined;
346
- const change = isLineBreakpoint ? { line } : { line, column };
347
- const breakpoint = SourceBreakpoint.create(uri, change, oldBreakpoint);
348
- breakpoints.push(breakpoint);
349
- lines.add(line);
350
- }
351
- }
352
- return breakpoints;
353
- }
354
-
355
- get position(): monaco.Position {
356
- return this.editor.getControl().getPosition()!;
357
- }
358
- getBreakpoint(position: monaco.Position = this.position): DebugSourceBreakpoint | undefined {
359
- return this.getInlineBreakpoint(position) || this.getLineBreakpoints(position)[0];
360
- }
361
-
362
- getInlineBreakpoint(position: monaco.Position = this.position): DebugSourceBreakpoint | undefined {
363
- return this.sessions.getInlineBreakpoint(this.uri, position.lineNumber, position.column);
364
- }
365
-
366
- protected getLineBreakpoints(position: monaco.Position = this.position): DebugSourceBreakpoint[] {
367
- return this.sessions.getLineBreakpoints(this.uri, position.lineNumber);
368
- }
369
-
370
- protected addBreakpoint(raw: DebugProtocol.SourceBreakpoint): void {
371
- this.breakpoints.addBreakpoint(SourceBreakpoint.create(this.uri, raw));
372
- }
373
-
374
- toggleBreakpoint(position: monaco.Position = this.position): void {
375
- const { lineNumber } = position;
376
- const breakpoints = this.getLineBreakpoints(position);
377
- if (breakpoints.length) {
378
- for (const breakpoint of breakpoints) {
379
- breakpoint.remove();
380
- }
381
- } else {
382
- this.addBreakpoint({ line: lineNumber });
383
- }
384
- }
385
-
386
- addInlineBreakpoint(): void {
387
- const { position } = this;
388
- const { lineNumber, column } = position;
389
- const breakpoint = this.getInlineBreakpoint(position);
390
- if (breakpoint) {
391
- return;
392
- }
393
- this.addBreakpoint({ line: lineNumber, column });
394
- }
395
-
396
- acceptBreakpoint(): void {
397
- const { position, values } = this.breakpointWidget;
398
- if (position && values) {
399
- const breakpoint = position.column > 0 ? this.getInlineBreakpoint(position) : this.getLineBreakpoints(position)[0];
400
- if (breakpoint) {
401
- breakpoint.updateOrigins(values);
402
- } else {
403
- const { lineNumber } = position;
404
- const column = position.column > 0 ? position.column : undefined;
405
- this.addBreakpoint({ line: lineNumber, column, ...values });
406
- }
407
- this.breakpointWidget.hide();
408
- }
409
- }
410
-
411
- protected handleMouseDown(event: monaco.editor.IEditorMouseEvent): void {
412
- if (event.target && event.target.type === monaco.editor.MouseTargetType.GUTTER_GLYPH_MARGIN) {
413
- if (!event.event.rightButton) {
414
- this.toggleBreakpoint(event.target.position!);
415
- }
416
- }
417
- this.hintBreakpoint(event);
418
- }
419
- protected handleMouseMove(event: monaco.editor.IEditorMouseEvent): void {
420
- this.showHover(event);
421
- this.hintBreakpoint(event);
422
- }
423
- protected handleMouseLeave(event: monaco.editor.IPartialEditorMouseEvent): void {
424
- this.hideHover(event);
425
- this.deltaHintDecorations([]);
426
- }
427
-
428
- protected hintDecorations: string[] = [];
429
- protected hintBreakpoint(event: monaco.editor.IEditorMouseEvent): void {
430
- const hintDecorations = this.createHintDecorations(event);
431
- this.deltaHintDecorations(hintDecorations);
432
- }
433
- protected deltaHintDecorations(hintDecorations: monaco.editor.IModelDeltaDecoration[]): void {
434
- this.hintDecorations = this.deltaDecorations(this.hintDecorations, hintDecorations);
435
- }
436
- protected createHintDecorations(event: monaco.editor.IEditorMouseEvent): monaco.editor.IModelDeltaDecoration[] {
437
- if (event.target && event.target.type === monaco.editor.MouseTargetType.GUTTER_GLYPH_MARGIN && event.target.position) {
438
- const lineNumber = event.target.position.lineNumber;
439
- if (this.getLineBreakpoints(event.target.position).length) {
440
- return [];
441
- }
442
- return [{
443
- range: new monaco.Range(lineNumber, 1, lineNumber, 1),
444
- options: DebugEditorModel.BREAKPOINT_HINT_DECORATION
445
- }];
446
- }
447
- return [];
448
- }
449
-
450
- protected closeBreakpointIfAffected({ uri, removed }: SourceBreakpointsChangeEvent): void {
451
- if (!uri.isEqual(this.uri)) {
452
- return;
453
- }
454
- const position = this.breakpointWidget.position;
455
- if (!position) {
456
- return;
457
- }
458
- for (const breakpoint of removed) {
459
- if (breakpoint.raw.line === position.lineNumber) {
460
- this.breakpointWidget.hide();
461
- break;
462
- }
463
- }
464
- }
465
-
466
- protected showHover(mouseEvent: monaco.editor.IEditorMouseEvent): void {
467
- const targetType = mouseEvent.target.type;
468
- const stopKey = isOSX ? 'metaKey' : 'ctrlKey';
469
-
470
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
471
- if (targetType === monaco.editor.MouseTargetType.CONTENT_WIDGET && mouseEvent.target.detail === this.hover.getId() && !(<any>mouseEvent.event)[stopKey]) {
472
- // mouse moved on top of debug hover widget
473
- return;
474
- }
475
- if (targetType === monaco.editor.MouseTargetType.CONTENT_TEXT) {
476
- this.hover.show({
477
- selection: mouseEvent.target.range!,
478
- immediate: false
479
- });
480
- } else {
481
- this.hover.hide({ immediate: false });
482
- }
483
- }
484
- protected hideHover({ event }: monaco.editor.IPartialEditorMouseEvent): void {
485
- const rect = this.hover.getDomNode().getBoundingClientRect();
486
- if (event.posx < rect.left || event.posx > rect.right || event.posy < rect.top || event.posy > rect.bottom) {
487
- this.hover.hide({ immediate: false });
488
- }
489
- }
490
-
491
- protected deltaDecorations(oldDecorations: string[], newDecorations: monaco.editor.IModelDeltaDecoration[]): string[] {
492
- this.updatingDecorations = true;
493
- try {
494
- return this.editor.getControl().deltaDecorations(oldDecorations, newDecorations);
495
- } finally {
496
- this.updatingDecorations = false;
497
- }
498
- }
499
-
500
- static STICKINESS = monaco.editor.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges;
501
-
502
- static BREAKPOINT_HINT_DECORATION: monaco.editor.IModelDecorationOptions = {
503
- glyphMarginClassName: 'codicon-debug-hint',
504
- stickiness: DebugEditorModel.STICKINESS
505
- };
506
-
507
- static TOP_STACK_FRAME_MARGIN: monaco.editor.IModelDecorationOptions = {
508
- glyphMarginClassName: 'codicon-debug-stackframe',
509
- stickiness: DebugEditorModel.STICKINESS
510
- };
511
- static FOCUSED_STACK_FRAME_MARGIN: monaco.editor.IModelDecorationOptions = {
512
- glyphMarginClassName: 'codicon-debug-stackframe-focused',
513
- stickiness: DebugEditorModel.STICKINESS
514
- };
515
- static TOP_STACK_FRAME_DECORATION: monaco.editor.IModelDecorationOptions = {
516
- isWholeLine: true,
517
- className: 'theia-debug-top-stack-frame-line',
518
- stickiness: DebugEditorModel.STICKINESS
519
- };
520
- static TOP_STACK_FRAME_INLINE_DECORATION: monaco.editor.IModelDecorationOptions = {
521
- beforeContentClassName: 'theia-debug-top-stack-frame-column'
522
- };
523
- static FOCUSED_STACK_FRAME_DECORATION: monaco.editor.IModelDecorationOptions = {
524
- isWholeLine: true,
525
- className: 'theia-debug-focused-stack-frame-line',
526
- stickiness: DebugEditorModel.STICKINESS
527
- };
528
-
529
- }
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 debounce = require('p-debounce');
18
+ import { injectable, inject, postConstruct, interfaces, Container } from '@theia/core/shared/inversify';
19
+ import * as monaco from '@theia/monaco-editor-core';
20
+ import { IConfigurationService } from '@theia/monaco-editor-core/esm/vs/platform/configuration/common/configuration';
21
+ import { StandaloneCodeEditor } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneCodeEditor';
22
+ import { IDecorationOptions } from '@theia/monaco-editor-core/esm/vs/editor/common/editorCommon';
23
+ import { IEditorHoverOptions } from '@theia/monaco-editor-core/esm/vs/editor/common/config/editorOptions';
24
+ import URI from '@theia/core/lib/common/uri';
25
+ import { Disposable, DisposableCollection, MenuPath, isOSX } from '@theia/core';
26
+ import { ContextMenuRenderer } from '@theia/core/lib/browser';
27
+ import { BreakpointManager, SourceBreakpointsChangeEvent } from '../breakpoint/breakpoint-manager';
28
+ import { DebugSourceBreakpoint } from '../model/debug-source-breakpoint';
29
+ import { DebugSessionManager } from '../debug-session-manager';
30
+ import { SourceBreakpoint } from '../breakpoint/breakpoint-marker';
31
+ import { DebugEditor } from './debug-editor';
32
+ import { DebugHoverWidget, createDebugHoverWidgetContainer } from './debug-hover-widget';
33
+ import { DebugBreakpointWidget } from './debug-breakpoint-widget';
34
+ import { DebugExceptionWidget } from './debug-exception-widget';
35
+ import { DebugProtocol } from '@vscode/debugprotocol';
36
+ import { DebugInlineValueDecorator, INLINE_VALUE_DECORATION_KEY } from './debug-inline-value-decorator';
37
+ import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
38
+
39
+ export const DebugEditorModelFactory = Symbol('DebugEditorModelFactory');
40
+ export type DebugEditorModelFactory = (editor: DebugEditor) => DebugEditorModel;
41
+
42
+ @injectable()
43
+ export class DebugEditorModel implements Disposable {
44
+
45
+ static createContainer(parent: interfaces.Container, editor: DebugEditor): Container {
46
+ const child = createDebugHoverWidgetContainer(parent, editor);
47
+ child.bind(DebugEditorModel).toSelf();
48
+ child.bind(DebugBreakpointWidget).toSelf();
49
+ child.bind(DebugExceptionWidget).toSelf();
50
+ return child;
51
+ }
52
+ static createModel(parent: interfaces.Container, editor: DebugEditor): DebugEditorModel {
53
+ return DebugEditorModel.createContainer(parent, editor).get(DebugEditorModel);
54
+ }
55
+
56
+ static CONTEXT_MENU: MenuPath = ['debug-editor-context-menu'];
57
+
58
+ protected readonly toDispose = new DisposableCollection();
59
+ protected readonly toDisposeOnUpdate = new DisposableCollection();
60
+
61
+ protected uri: URI;
62
+
63
+ protected breakpointDecorations: string[] = [];
64
+ protected breakpointRanges = new Map<string, [monaco.Range, SourceBreakpoint]>();
65
+
66
+ protected currentBreakpointDecorations: string[] = [];
67
+
68
+ protected editorDecorations: string[] = [];
69
+ protected topFrameRange: monaco.Range | undefined;
70
+
71
+ protected updatingDecorations = false;
72
+
73
+ @inject(DebugHoverWidget)
74
+ readonly hover: DebugHoverWidget;
75
+
76
+ @inject(DebugEditor)
77
+ readonly editor: DebugEditor;
78
+
79
+ @inject(BreakpointManager)
80
+ readonly breakpoints: BreakpointManager;
81
+
82
+ @inject(DebugSessionManager)
83
+ readonly sessions: DebugSessionManager;
84
+
85
+ @inject(ContextMenuRenderer)
86
+ readonly contextMenu: ContextMenuRenderer;
87
+
88
+ @inject(DebugBreakpointWidget)
89
+ readonly breakpointWidget: DebugBreakpointWidget;
90
+
91
+ @inject(DebugExceptionWidget)
92
+ readonly exceptionWidget: DebugExceptionWidget;
93
+
94
+ @inject(DebugInlineValueDecorator)
95
+ readonly inlineValueDecorator: DebugInlineValueDecorator;
96
+
97
+ @inject(DebugSessionManager)
98
+ protected readonly sessionManager: DebugSessionManager;
99
+
100
+ @postConstruct()
101
+ protected init(): void {
102
+ this.uri = new URI(this.editor.getControl().getModel()!.uri.toString());
103
+ this.toDispose.pushAll([
104
+ this.hover,
105
+ this.breakpointWidget,
106
+ this.exceptionWidget,
107
+ this.editor.getControl().onMouseDown(event => this.handleMouseDown(event)),
108
+ this.editor.getControl().onMouseMove(event => this.handleMouseMove(event)),
109
+ this.editor.getControl().onMouseLeave(event => this.handleMouseLeave(event)),
110
+ this.editor.getControl().onKeyDown(() => this.hover.hide({ immediate: false })),
111
+ this.editor.getControl().onDidChangeModelContent(() => this.update()),
112
+ this.editor.getControl().getModel()!.onDidChangeDecorations(() => this.updateBreakpoints()),
113
+ this.editor.onDidResize(e => this.breakpointWidget.inputSize = e),
114
+ this.sessions.onDidChange(() => this.update()),
115
+ this.toDisposeOnUpdate,
116
+ this.sessionManager.onDidChangeBreakpoints(({ session, uri }) => {
117
+ if ((!session || session === this.sessionManager.currentSession) && uri.isEqual(this.uri)) {
118
+ this.render();
119
+ }
120
+ }),
121
+ this.breakpoints.onDidChangeBreakpoints(event => this.closeBreakpointIfAffected(event)),
122
+ ]);
123
+ this.update();
124
+ this.render();
125
+ }
126
+
127
+ dispose(): void {
128
+ this.toDispose.dispose();
129
+ }
130
+
131
+ protected readonly update = debounce(async () => {
132
+ if (this.toDispose.disposed) {
133
+ return;
134
+ }
135
+ this.toDisposeOnUpdate.dispose();
136
+ this.toggleExceptionWidget();
137
+ await this.updateEditorDecorations();
138
+ this.updateEditorHover();
139
+ }, 100);
140
+
141
+ /**
142
+ * To disable the default editor-contribution hover from Code when
143
+ * the editor has the `currentFrame`. Otherwise, both `textdocument/hover`
144
+ * and the debug hovers are visible at the same time when hovering over a symbol.
145
+ */
146
+ protected async updateEditorHover(): Promise<void> {
147
+ if (this.sessions.isCurrentEditorFrame(this.uri)) {
148
+ const codeEditor = this.editor.getControl();
149
+ codeEditor.updateOptions({ hover: { enabled: false } });
150
+ this.toDisposeOnUpdate.push(Disposable.create(() => {
151
+ const model = codeEditor.getModel()!;
152
+ const overrides = {
153
+ resource: model.uri,
154
+ overrideIdentifier: model.getLanguageId(),
155
+ };
156
+ const { enabled, delay, sticky } = StandaloneServices.get(IConfigurationService).getValue<IEditorHoverOptions>('editor.hover', overrides);
157
+ codeEditor.updateOptions({
158
+ hover: {
159
+ enabled,
160
+ delay,
161
+ sticky
162
+ }
163
+ });
164
+ }));
165
+ }
166
+ }
167
+
168
+ protected async updateEditorDecorations(): Promise<void> {
169
+ const [newFrameDecorations, inlineValueDecorations] = await Promise.all([
170
+ this.createFrameDecorations(),
171
+ this.createInlineValueDecorations()
172
+ ]);
173
+ const codeEditor = this.editor.getControl() as unknown as StandaloneCodeEditor;
174
+ codeEditor.removeDecorations([INLINE_VALUE_DECORATION_KEY]);
175
+ codeEditor.setDecorationsByType('Inline debug decorations', INLINE_VALUE_DECORATION_KEY, inlineValueDecorations);
176
+ this.editorDecorations = this.deltaDecorations(this.editorDecorations, newFrameDecorations);
177
+ }
178
+
179
+ protected async createInlineValueDecorations(): Promise<IDecorationOptions[]> {
180
+ if (!this.sessions.isCurrentEditorFrame(this.uri)) {
181
+ return [];
182
+ }
183
+ const { currentFrame } = this.sessions;
184
+ return this.inlineValueDecorator.calculateDecorations(this, currentFrame);
185
+ }
186
+
187
+ protected createFrameDecorations(): monaco.editor.IModelDeltaDecoration[] {
188
+ const { currentFrame, topFrame } = this.sessions;
189
+ if (!currentFrame) {
190
+ return [];
191
+ }
192
+
193
+ if (!currentFrame.thread.stopped) {
194
+ return [];
195
+ }
196
+
197
+ if (!this.sessions.isCurrentEditorFrame(this.uri)) {
198
+ return [];
199
+ }
200
+
201
+ const decorations: monaco.editor.IModelDeltaDecoration[] = [];
202
+ const columnUntilEOLRange = new monaco.Range(currentFrame.raw.line, currentFrame.raw.column, currentFrame.raw.line, 1 << 30);
203
+ const range = new monaco.Range(currentFrame.raw.line, currentFrame.raw.column, currentFrame.raw.line, currentFrame.raw.column + 1);
204
+
205
+ if (topFrame === currentFrame) {
206
+ decorations.push({
207
+ options: DebugEditorModel.TOP_STACK_FRAME_MARGIN,
208
+ range
209
+ });
210
+ decorations.push({
211
+ options: DebugEditorModel.TOP_STACK_FRAME_DECORATION,
212
+ range: columnUntilEOLRange
213
+ });
214
+ const { topFrameRange } = this;
215
+ if (topFrameRange && topFrameRange.startLineNumber === currentFrame.raw.line && topFrameRange.startColumn !== currentFrame.raw.column) {
216
+ decorations.push({
217
+ options: DebugEditorModel.TOP_STACK_FRAME_INLINE_DECORATION,
218
+ range: columnUntilEOLRange
219
+ });
220
+ }
221
+ this.topFrameRange = columnUntilEOLRange;
222
+ } else {
223
+ decorations.push({
224
+ options: DebugEditorModel.FOCUSED_STACK_FRAME_MARGIN,
225
+ range
226
+ });
227
+ decorations.push({
228
+ options: DebugEditorModel.FOCUSED_STACK_FRAME_DECORATION,
229
+ range: columnUntilEOLRange
230
+ });
231
+ }
232
+ return decorations;
233
+ }
234
+
235
+ protected async toggleExceptionWidget(): Promise<void> {
236
+ const { currentFrame } = this.sessions;
237
+ if (!currentFrame) {
238
+ return;
239
+ }
240
+ if (!this.sessions.isCurrentEditorFrame(this.uri)) {
241
+ this.exceptionWidget.hide();
242
+ return;
243
+ }
244
+ const info = await currentFrame.thread.getExceptionInfo();
245
+ if (!info) {
246
+ this.exceptionWidget.hide();
247
+ return;
248
+ }
249
+ this.exceptionWidget.show({
250
+ info,
251
+ lineNumber: currentFrame.raw.line,
252
+ column: currentFrame.raw.column
253
+ });
254
+ }
255
+
256
+ render(): void {
257
+ this.renderBreakpoints();
258
+ this.renderCurrentBreakpoints();
259
+ }
260
+ protected renderBreakpoints(): void {
261
+ const breakpoints = this.breakpoints.getBreakpoints(this.uri);
262
+ const decorations = this.createBreakpointDecorations(breakpoints);
263
+ this.breakpointDecorations = this.deltaDecorations(this.breakpointDecorations, decorations);
264
+ this.updateBreakpointRanges(breakpoints);
265
+ }
266
+ protected createBreakpointDecorations(breakpoints: SourceBreakpoint[]): monaco.editor.IModelDeltaDecoration[] {
267
+ return breakpoints.map(breakpoint => this.createBreakpointDecoration(breakpoint));
268
+ }
269
+ protected createBreakpointDecoration(breakpoint: SourceBreakpoint): monaco.editor.IModelDeltaDecoration {
270
+ const lineNumber = breakpoint.raw.line;
271
+ const column = breakpoint.raw.column;
272
+ const range = typeof column === 'number' ? new monaco.Range(lineNumber, column, lineNumber, column + 1) : new monaco.Range(lineNumber, 1, lineNumber, 2);
273
+ return {
274
+ range,
275
+ options: {
276
+ stickiness: DebugEditorModel.STICKINESS
277
+ }
278
+ };
279
+ }
280
+
281
+ protected updateBreakpointRanges(breakpoints: SourceBreakpoint[]): void {
282
+ this.breakpointRanges.clear();
283
+ for (let i = 0; i < this.breakpointDecorations.length; i++) {
284
+ const decoration = this.breakpointDecorations[i];
285
+ const breakpoint = breakpoints[i];
286
+ const range = this.editor.getControl().getModel()!.getDecorationRange(decoration)!;
287
+ this.breakpointRanges.set(decoration, [range, breakpoint]);
288
+ }
289
+ }
290
+
291
+ protected renderCurrentBreakpoints(): void {
292
+ const decorations = this.createCurrentBreakpointDecorations();
293
+ this.currentBreakpointDecorations = this.deltaDecorations(this.currentBreakpointDecorations, decorations);
294
+ }
295
+ protected createCurrentBreakpointDecorations(): monaco.editor.IModelDeltaDecoration[] {
296
+ const breakpoints = this.sessions.getBreakpoints(this.uri);
297
+ return breakpoints.map(breakpoint => this.createCurrentBreakpointDecoration(breakpoint));
298
+ }
299
+ protected createCurrentBreakpointDecoration(breakpoint: DebugSourceBreakpoint): monaco.editor.IModelDeltaDecoration {
300
+ const lineNumber = breakpoint.line;
301
+ const column = breakpoint.column;
302
+ const range = typeof column === 'number' ? new monaco.Range(lineNumber, column, lineNumber, column + 1) : new monaco.Range(lineNumber, 1, lineNumber, 1);
303
+ const { className, message } = breakpoint.getDecoration();
304
+ const renderInline = typeof column === 'number' && (column > this.editor.getControl().getModel()!.getLineFirstNonWhitespaceColumn(lineNumber));
305
+ return {
306
+ range,
307
+ options: {
308
+ glyphMarginClassName: className,
309
+ glyphMarginHoverMessage: message.map(value => ({ value })),
310
+ stickiness: DebugEditorModel.STICKINESS,
311
+ beforeContentClassName: renderInline ? `theia-debug-breakpoint-column codicon ${className}` : undefined
312
+ }
313
+ };
314
+ }
315
+
316
+ protected updateBreakpoints(): void {
317
+ if (this.areBreakpointsAffected()) {
318
+ const breakpoints = this.createBreakpoints();
319
+ this.breakpoints.setBreakpoints(this.uri, breakpoints);
320
+ }
321
+ }
322
+ protected areBreakpointsAffected(): boolean {
323
+ if (this.updatingDecorations || !this.editor.getControl().getModel()) {
324
+ return false;
325
+ }
326
+ for (const decoration of this.breakpointDecorations) {
327
+ const range = this.editor.getControl().getModel()!.getDecorationRange(decoration);
328
+ const oldRange = this.breakpointRanges.get(decoration)![0];
329
+ if (!range || !range.equalsRange(oldRange)) {
330
+ return true;
331
+ }
332
+ }
333
+ return false;
334
+ }
335
+ protected createBreakpoints(): SourceBreakpoint[] {
336
+ const { uri } = this;
337
+ const lines = new Set<number>();
338
+ const breakpoints: SourceBreakpoint[] = [];
339
+ for (const decoration of this.breakpointDecorations) {
340
+ const range = this.editor.getControl().getModel()!.getDecorationRange(decoration);
341
+ if (range && !lines.has(range.startLineNumber)) {
342
+ const line = range.startLineNumber;
343
+ const column = range.startColumn;
344
+ const oldBreakpoint = this.breakpointRanges.get(decoration)?.[1];
345
+ const isLineBreakpoint = oldBreakpoint?.raw.line !== undefined && oldBreakpoint?.raw.column === undefined;
346
+ const change = isLineBreakpoint ? { line } : { line, column };
347
+ const breakpoint = SourceBreakpoint.create(uri, change, oldBreakpoint);
348
+ breakpoints.push(breakpoint);
349
+ lines.add(line);
350
+ }
351
+ }
352
+ return breakpoints;
353
+ }
354
+
355
+ get position(): monaco.Position {
356
+ return this.editor.getControl().getPosition()!;
357
+ }
358
+ getBreakpoint(position: monaco.Position = this.position): DebugSourceBreakpoint | undefined {
359
+ return this.getInlineBreakpoint(position) || this.getLineBreakpoints(position)[0];
360
+ }
361
+
362
+ getInlineBreakpoint(position: monaco.Position = this.position): DebugSourceBreakpoint | undefined {
363
+ return this.sessions.getInlineBreakpoint(this.uri, position.lineNumber, position.column);
364
+ }
365
+
366
+ protected getLineBreakpoints(position: monaco.Position = this.position): DebugSourceBreakpoint[] {
367
+ return this.sessions.getLineBreakpoints(this.uri, position.lineNumber);
368
+ }
369
+
370
+ protected addBreakpoint(raw: DebugProtocol.SourceBreakpoint): void {
371
+ this.breakpoints.addBreakpoint(SourceBreakpoint.create(this.uri, raw));
372
+ }
373
+
374
+ toggleBreakpoint(position: monaco.Position = this.position): void {
375
+ const { lineNumber } = position;
376
+ const breakpoints = this.getLineBreakpoints(position);
377
+ if (breakpoints.length) {
378
+ for (const breakpoint of breakpoints) {
379
+ breakpoint.remove();
380
+ }
381
+ } else {
382
+ this.addBreakpoint({ line: lineNumber });
383
+ }
384
+ }
385
+
386
+ addInlineBreakpoint(): void {
387
+ const { position } = this;
388
+ const { lineNumber, column } = position;
389
+ const breakpoint = this.getInlineBreakpoint(position);
390
+ if (breakpoint) {
391
+ return;
392
+ }
393
+ this.addBreakpoint({ line: lineNumber, column });
394
+ }
395
+
396
+ acceptBreakpoint(): void {
397
+ const { position, values } = this.breakpointWidget;
398
+ if (position && values) {
399
+ const breakpoint = position.column > 0 ? this.getInlineBreakpoint(position) : this.getLineBreakpoints(position)[0];
400
+ if (breakpoint) {
401
+ breakpoint.updateOrigins(values);
402
+ } else {
403
+ const { lineNumber } = position;
404
+ const column = position.column > 0 ? position.column : undefined;
405
+ this.addBreakpoint({ line: lineNumber, column, ...values });
406
+ }
407
+ this.breakpointWidget.hide();
408
+ }
409
+ }
410
+
411
+ protected handleMouseDown(event: monaco.editor.IEditorMouseEvent): void {
412
+ if (event.target && event.target.type === monaco.editor.MouseTargetType.GUTTER_GLYPH_MARGIN) {
413
+ if (!event.event.rightButton) {
414
+ this.toggleBreakpoint(event.target.position!);
415
+ }
416
+ }
417
+ this.hintBreakpoint(event);
418
+ }
419
+ protected handleMouseMove(event: monaco.editor.IEditorMouseEvent): void {
420
+ this.showHover(event);
421
+ this.hintBreakpoint(event);
422
+ }
423
+ protected handleMouseLeave(event: monaco.editor.IPartialEditorMouseEvent): void {
424
+ this.hideHover(event);
425
+ this.deltaHintDecorations([]);
426
+ }
427
+
428
+ protected hintDecorations: string[] = [];
429
+ protected hintBreakpoint(event: monaco.editor.IEditorMouseEvent): void {
430
+ const hintDecorations = this.createHintDecorations(event);
431
+ this.deltaHintDecorations(hintDecorations);
432
+ }
433
+ protected deltaHintDecorations(hintDecorations: monaco.editor.IModelDeltaDecoration[]): void {
434
+ this.hintDecorations = this.deltaDecorations(this.hintDecorations, hintDecorations);
435
+ }
436
+ protected createHintDecorations(event: monaco.editor.IEditorMouseEvent): monaco.editor.IModelDeltaDecoration[] {
437
+ if (event.target && event.target.type === monaco.editor.MouseTargetType.GUTTER_GLYPH_MARGIN && event.target.position) {
438
+ const lineNumber = event.target.position.lineNumber;
439
+ if (this.getLineBreakpoints(event.target.position).length) {
440
+ return [];
441
+ }
442
+ return [{
443
+ range: new monaco.Range(lineNumber, 1, lineNumber, 1),
444
+ options: DebugEditorModel.BREAKPOINT_HINT_DECORATION
445
+ }];
446
+ }
447
+ return [];
448
+ }
449
+
450
+ protected closeBreakpointIfAffected({ uri, removed }: SourceBreakpointsChangeEvent): void {
451
+ if (!uri.isEqual(this.uri)) {
452
+ return;
453
+ }
454
+ const position = this.breakpointWidget.position;
455
+ if (!position) {
456
+ return;
457
+ }
458
+ for (const breakpoint of removed) {
459
+ if (breakpoint.raw.line === position.lineNumber) {
460
+ this.breakpointWidget.hide();
461
+ break;
462
+ }
463
+ }
464
+ }
465
+
466
+ protected showHover(mouseEvent: monaco.editor.IEditorMouseEvent): void {
467
+ const targetType = mouseEvent.target.type;
468
+ const stopKey = isOSX ? 'metaKey' : 'ctrlKey';
469
+
470
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
471
+ if (targetType === monaco.editor.MouseTargetType.CONTENT_WIDGET && mouseEvent.target.detail === this.hover.getId() && !(<any>mouseEvent.event)[stopKey]) {
472
+ // mouse moved on top of debug hover widget
473
+ return;
474
+ }
475
+ if (targetType === monaco.editor.MouseTargetType.CONTENT_TEXT) {
476
+ this.hover.show({
477
+ selection: mouseEvent.target.range!,
478
+ immediate: false
479
+ });
480
+ } else {
481
+ this.hover.hide({ immediate: false });
482
+ }
483
+ }
484
+ protected hideHover({ event }: monaco.editor.IPartialEditorMouseEvent): void {
485
+ const rect = this.hover.getDomNode().getBoundingClientRect();
486
+ if (event.posx < rect.left || event.posx > rect.right || event.posy < rect.top || event.posy > rect.bottom) {
487
+ this.hover.hide({ immediate: false });
488
+ }
489
+ }
490
+
491
+ protected deltaDecorations(oldDecorations: string[], newDecorations: monaco.editor.IModelDeltaDecoration[]): string[] {
492
+ this.updatingDecorations = true;
493
+ try {
494
+ return this.editor.getControl().deltaDecorations(oldDecorations, newDecorations);
495
+ } finally {
496
+ this.updatingDecorations = false;
497
+ }
498
+ }
499
+
500
+ static STICKINESS = monaco.editor.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges;
501
+
502
+ static BREAKPOINT_HINT_DECORATION: monaco.editor.IModelDecorationOptions = {
503
+ glyphMarginClassName: 'codicon-debug-hint',
504
+ stickiness: DebugEditorModel.STICKINESS
505
+ };
506
+
507
+ static TOP_STACK_FRAME_MARGIN: monaco.editor.IModelDecorationOptions = {
508
+ glyphMarginClassName: 'codicon-debug-stackframe',
509
+ stickiness: DebugEditorModel.STICKINESS
510
+ };
511
+ static FOCUSED_STACK_FRAME_MARGIN: monaco.editor.IModelDecorationOptions = {
512
+ glyphMarginClassName: 'codicon-debug-stackframe-focused',
513
+ stickiness: DebugEditorModel.STICKINESS
514
+ };
515
+ static TOP_STACK_FRAME_DECORATION: monaco.editor.IModelDecorationOptions = {
516
+ isWholeLine: true,
517
+ className: 'theia-debug-top-stack-frame-line',
518
+ stickiness: DebugEditorModel.STICKINESS
519
+ };
520
+ static TOP_STACK_FRAME_INLINE_DECORATION: monaco.editor.IModelDecorationOptions = {
521
+ beforeContentClassName: 'theia-debug-top-stack-frame-column'
522
+ };
523
+ static FOCUSED_STACK_FRAME_DECORATION: monaco.editor.IModelDecorationOptions = {
524
+ isWholeLine: true,
525
+ className: 'theia-debug-focused-stack-frame-line',
526
+ stickiness: DebugEditorModel.STICKINESS
527
+ };
528
+
529
+ }