Skip to content

Use editor widget as key for debug editor models #15516

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

Merged
merged 1 commit into from
Apr 28, 2025
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
34 changes: 8 additions & 26 deletions packages/debug/src/browser/editor/debug-editor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ContextMenuRenderer } from '@theia/core/lib/browser';
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
import { DebugSessionManager } from '../debug-session-manager';
import { DebugEditorModel, DebugEditorModelFactory } from './debug-editor-model';
import { BreakpointManager, SourceBreakpointsChangeEvent } from '../breakpoint/breakpoint-manager';
import { BreakpointManager } from '../breakpoint/breakpoint-manager';
import { DebugSourceBreakpoint } from '../model/debug-source-breakpoint';
import { DebugBreakpointWidget } from './debug-breakpoint-widget';
import URI from '@theia/core/lib/common/uri';
Expand All @@ -44,7 +44,7 @@ export class DebugEditorService {
@inject(DebugEditorModelFactory)
protected readonly factory: DebugEditorModelFactory;

protected readonly models = new Map<string, DebugEditorModel>();
protected readonly models = new Map<MonacoEditor, DebugEditorModel>();

@postConstruct()
protected init(): void {
Expand All @@ -57,19 +57,17 @@ export class DebugEditorService {
if (!(editor instanceof MonacoEditor)) {
return;
}
const uri = editor.getResourceUri().toString();
const debugModel = this.factory(editor);
this.models.set(uri, debugModel);
editor.getControl().onDidDispose(() => {
this.models.set(editor, debugModel);
widget.onDispose(() => {
debugModel.dispose();
this.models.delete(uri);
this.models.delete(editor);
});
}

get model(): DebugEditorModel | undefined {
const { currentEditor } = this.editors;
const uri = currentEditor && currentEditor.getResourceUri();
return uri && this.models.get(uri.toString());
return currentEditor && this.models.get(currentEditor.editor as MonacoEditor);
}

get currentUri(): URI | undefined {
Expand Down Expand Up @@ -160,8 +158,8 @@ export class DebugEditorService {
}

if (breakpointOrPosition) {
await breakpointOrPosition.open();
const model = this.models.get(breakpointOrPosition.uri.toString());
const editor = await breakpointOrPosition.open();
const model = this.models.get(editor.editor as MonacoEditor);
if (model) {
model.breakpointWidget.show(breakpointOrPosition);
}
Expand All @@ -179,20 +177,4 @@ export class DebugEditorService {
model.acceptBreakpoint();
}
}
protected closeBreakpointIfAffected({ uri, removed }: SourceBreakpointsChangeEvent): void {
const model = this.models.get(uri.toString());
if (!model) {
return;
}
const position = model.breakpointWidget.position;
if (!position) {
return;
}
for (const breakpoint of removed) {
if (breakpoint.raw.line === position.lineNumber) {
model.breakpointWidget.hide();
}
}
}

}
8 changes: 4 additions & 4 deletions packages/debug/src/browser/model/debug-source-breakpoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as React from '@theia/core/shared/react';
import { DebugProtocol } from '@vscode/debugprotocol/lib/debugProtocol';
import { RecursivePartial } from '@theia/core';
import URI from '@theia/core/lib/common/uri';
import { Range } from '@theia/editor/lib/browser';
import { EditorWidget, Range } from '@theia/editor/lib/browser';
import { TREE_NODE_INFO_CLASS, WidgetOpenerOptions } from '@theia/core/lib/browser';
import { TreeElement } from '@theia/core/lib/browser/source-tree';
import { SourceBreakpoint } from '../breakpoint/breakpoint-marker';
Expand Down Expand Up @@ -113,7 +113,7 @@ export class DebugSourceBreakpoint extends DebugBreakpoint<SourceBreakpoint> imp

async open(options: WidgetOpenerOptions = {
mode: 'reveal'
}): Promise<void> {
}): Promise<EditorWidget> {
const { line, column, endLine, endColumn } = this;
const selection: RecursivePartial<Range> = {
start: {
Expand All @@ -128,12 +128,12 @@ export class DebugSourceBreakpoint extends DebugBreakpoint<SourceBreakpoint> imp
};
}
if (this.source) {
await this.source.open({
return await this.source.open({
...options,
selection
});
} else {
await this.editorManager.open(this.uri, {
return await this.editorManager.open(this.uri, {
...options,
selection
});
Expand Down
Loading