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

fix debug exception height computation #8382

Merged
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
2 changes: 1 addition & 1 deletion packages/debug/src/browser/editor/debug-editor-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class DebugEditorModel implements Disposable {

protected async toggleExceptionWidget(): Promise<void> {
const { currentFrame } = this.sessions;
if (!currentFrame) {
if (!currentFrame || !currentFrame.source || currentFrame.source.uri.toString() !== this.uri.toString()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe currentFrame?.source?.uri?.toString() !== this.uri.toString()

this.exceptionWidget.hide();
return;
}
Expand Down
61 changes: 42 additions & 19 deletions packages/debug/src/browser/editor/debug-exception-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ export interface ShowDebugExceptionParams {
column: number
}

export class DebugExceptionMonacoEditorZoneWidget extends MonacoEditorZoneWidget {

protected computeContainerHeight(zoneHeight: number): {
height: number,
frameWidth: number
} {
// reset height to match it to the content
this.containerNode.style.height = 'initial';
const height = this.containerNode.offsetHeight;
const result = super.computeContainerHeight(zoneHeight);
result.height = height;
return result;
}

}

@injectable()
export class DebugExceptionWidget implements Disposable {

Expand All @@ -40,45 +56,52 @@ export class DebugExceptionWidget implements Disposable {

@postConstruct()
protected async init(): Promise<void> {
this.toDispose.push(this.zone = new MonacoEditorZoneWidget(this.editor.getControl()));
this.toDispose.push(this.zone = new DebugExceptionMonacoEditorZoneWidget(this.editor.getControl()));
this.zone.containerNode.classList.add('theia-debug-exception-widget');
this.toDispose.push(Disposable.create(() => ReactDOM.unmountComponentAtNode(this.zone.containerNode)));
this.toDispose.push(this.editor.getControl().onDidLayoutChange(() => this.layout()));
}

dispose(): void {
this.toDispose.dispose();
}

show({ info, lineNumber, column }: ShowDebugExceptionParams): void {
this.render(info);

const fontInfo = this.editor.getControl().getOption(monaco.editor.EditorOption.fontInfo);
this.zone.containerNode.style.fontSize = `${fontInfo.fontSize}px`;
this.zone.containerNode.style.lineHeight = `${fontInfo.lineHeight}px`;

if (lineNumber !== undefined && column !== undefined) {
const afterLineNumber = lineNumber;
const afterColumn = column;
const heightInLines = 0;
this.zone.show({ showFrame: true, afterLineNumber, afterColumn, heightInLines, frameWidth: 1 });
}
this.render(info, () => {
const fontInfo = this.editor.getControl().getOption(monaco.editor.EditorOption.fontInfo);
this.zone.containerNode.style.fontSize = `${fontInfo.fontSize}px`;
this.zone.containerNode.style.lineHeight = `${fontInfo.lineHeight}px`;

if (lineNumber !== undefined && column !== undefined) {
const afterLineNumber = lineNumber;
const afterColumn = column;
this.zone.show({ showFrame: true, afterLineNumber, afterColumn, heightInLines: 0, frameWidth: 1 });
}

this.layout();
});
}

hide(): void {
this.zone.hide();
}

protected render(info: DebugExceptionInfo): void {
protected render(info: DebugExceptionInfo, cb: () => void): void {
const stackTrace = info.details && info.details.stackTrace;
ReactDOM.render(<React.Fragment>
<div className='title'>{info.id ? `Exception has occurred: ${info.id}` : 'Exception has occurred.'}</div>
{info.description && <div className='description'>{info.description}</div>}
{stackTrace && <div className='stack-trace'>{stackTrace}</div>}
</React.Fragment>, this.zone.containerNode, () => {
const lineHeight = this.editor.getControl().getOption(monaco.editor.EditorOption.lineHeight);
const heightInLines = Math.ceil(this.zone.containerNode.offsetHeight / lineHeight);
this.zone.layout(heightInLines);
});
</React.Fragment>, this.zone.containerNode, cb);
}

protected layout(): void {
// reset height to match it to the content
this.zone.containerNode.style.height = 'initial';

const lineHeight = this.editor.getControl().getOption(monaco.editor.EditorOption.lineHeight);
const heightInLines = Math.ceil(this.zone.containerNode.offsetHeight / lineHeight);
this.zone.layout(heightInLines);
}

}