Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire breakpoint events only if breakpoint metadata changes #12183

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@theia/variable-resolver": "1.34.0",
"@theia/workspace": "1.34.0",
"@vscode/debugprotocol": "^1.51.0",
"fast-deep-equal": "^3.1.3",
"jsonc-parser": "^2.2.0",
"p-debounce": "^2.1.0"
},
Expand Down
20 changes: 14 additions & 6 deletions packages/debug/src/browser/breakpoint/breakpoint-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// *****************************************************************************

import * as deepEqual from 'fast-deep-equal';
import { injectable, inject } from '@theia/core/shared/inversify';
import { Emitter } from '@theia/core/lib/common';
import { StorageService } from '@theia/core/lib/browser';
Expand Down Expand Up @@ -60,26 +61,33 @@ export class BreakpointManager extends MarkerManager<SourceBreakpoint> {
readonly onDidChangeInstructionBreakpoints = this.onDidChangeInstructionBreakpointsEmitter.event;

override setMarkers(uri: URI, owner: string, newMarkers: SourceBreakpoint[]): Marker<SourceBreakpoint>[] {
const result = super.setMarkers(uri, owner, newMarkers);
const result = this.findMarkers({ uri, owner });
const added: SourceBreakpoint[] = [];
const removed: SourceBreakpoint[] = [];
const changed: SourceBreakpoint[] = [];
const oldMarkers = new Map(result.map(({ data }) => [data.id, data] as [string, SourceBreakpoint]));
const oldMarkers = new Map(result.map(({ data }) => [data.id, data]));
const ids = new Set<string>();
let didChangeMarkers = false;
for (const newMarker of newMarkers) {
ids.add(newMarker.id);
if (oldMarkers.has(newMarker.id)) {
changed.push(newMarker);
} else {
const oldMarker = oldMarkers.get(newMarker.id);
if (!oldMarker) {
added.push(newMarker);
} else {
// We emit all existing markers as 'changed', but we only fire an event if something really did change.
didChangeMarkers ||= !!added.length || !deepEqual(oldMarker, newMarker);
changed.push(newMarker);
}
}
for (const [id, data] of oldMarkers.entries()) {
if (!ids.has(id)) {
removed.push(data);
}
}
this.onDidChangeBreakpointsEmitter.fire({ uri, added, removed, changed });
if (added.length || removed.length || didChangeMarkers) {
super.setMarkers(uri, owner, newMarkers);
this.onDidChangeBreakpointsEmitter.fire({ uri, added, removed, changed });
}
return result;
}

Expand Down
24 changes: 13 additions & 11 deletions packages/debug/src/browser/editor/debug-editor-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class DebugEditorModel implements Disposable {
protected uri: URI;

protected breakpointDecorations: string[] = [];
protected breakpointRanges = new Map<string, monaco.Range>();
protected breakpointRanges = new Map<string, [monaco.Range, SourceBreakpoint]>();

protected currentBreakpointDecorations: string[] = [];

Expand Down Expand Up @@ -248,12 +248,12 @@ export class DebugEditorModel implements Disposable {
this.renderCurrentBreakpoints();
}
protected renderBreakpoints(): void {
const decorations = this.createBreakpointDecorations();
const breakpoints = this.breakpoints.getBreakpoints(this.uri);
const decorations = this.createBreakpointDecorations(breakpoints);
this.breakpointDecorations = this.deltaDecorations(this.breakpointDecorations, decorations);
this.updateBreakpointRanges();
this.updateBreakpointRanges(breakpoints);
}
protected createBreakpointDecorations(): monaco.editor.IModelDeltaDecoration[] {
const breakpoints = this.breakpoints.getBreakpoints(this.uri);
protected createBreakpointDecorations(breakpoints: SourceBreakpoint[]): monaco.editor.IModelDeltaDecoration[] {
return breakpoints.map(breakpoint => this.createBreakpointDecoration(breakpoint));
}
protected createBreakpointDecoration(breakpoint: SourceBreakpoint): monaco.editor.IModelDeltaDecoration {
Expand All @@ -267,11 +267,14 @@ export class DebugEditorModel implements Disposable {
}
};
}
protected updateBreakpointRanges(): void {

protected updateBreakpointRanges(breakpoints: SourceBreakpoint[]): void {
this.breakpointRanges.clear();
for (const decoration of this.breakpointDecorations) {
for (let i = 0; i < this.breakpointDecorations.length; i++) {
const decoration = this.breakpointDecorations[i];
const breakpoint = breakpoints[i];
const range = this.editor.getControl().getModel()!.getDecorationRange(decoration)!;
this.breakpointRanges.set(decoration, range);
this.breakpointRanges.set(decoration, [range, breakpoint]);
}
}

Expand Down Expand Up @@ -312,7 +315,7 @@ export class DebugEditorModel implements Disposable {
}
for (const decoration of this.breakpointDecorations) {
const range = this.editor.getControl().getModel()!.getDecorationRange(decoration);
const oldRange = this.breakpointRanges.get(decoration)!;
const oldRange = this.breakpointRanges.get(decoration)![0];
if (!range || !range.equalsRange(oldRange)) {
return true;
}
Expand All @@ -328,8 +331,7 @@ export class DebugEditorModel implements Disposable {
if (range && !lines.has(range.startLineNumber)) {
const line = range.startLineNumber;
const column = range.startColumn;
const oldRange = this.breakpointRanges.get(decoration);
const oldBreakpoint = oldRange && this.breakpoints.getInlineBreakpoint(uri, oldRange.startLineNumber, oldRange.startColumn);
const oldBreakpoint = this.breakpointRanges.get(decoration)?.[1];
const breakpoint = SourceBreakpoint.create(uri, { line, column }, oldBreakpoint);
breakpoints.push(breakpoint);
lines.add(line);
Expand Down