-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP fix #3312: complete support of source breakpoints
Signed-off-by: Anton Kosyakov <[email protected]>
- Loading branch information
Showing
8 changed files
with
467 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
packages/debug/src/browser/editor/debug-breakpoint-widget.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import { DebugProtocol } from 'vscode-debugprotocol'; | ||
import { injectable, postConstruct, inject } from 'inversify'; | ||
import { Disposable, DisposableCollection } from '@theia/core'; | ||
import URI from '@theia/core/lib/common/uri'; | ||
import { MonacoEditorProvider } from '@theia/monaco/lib/browser/monaco-editor-provider'; | ||
import { MonacoEditorZoneWidget } from '@theia/monaco/lib/browser/monaco-editor-zone-widget'; | ||
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor'; | ||
import { DebugEditor } from './debug-editor'; | ||
import { DebugBreakpoint } from '../model/debug-breakpoint'; | ||
|
||
export type ShowDebugBreakpointOptions = DebugBreakpoint | { | ||
position: monaco.Position, | ||
context: DebugBreakpointWidget.Context | ||
}; | ||
|
||
@injectable() | ||
export class DebugBreakpointWidget implements Disposable { | ||
|
||
@inject(DebugEditor) | ||
readonly editor: monaco.editor.IStandaloneCodeEditor; | ||
|
||
@inject(MonacoEditorProvider) | ||
protected readonly editorProvider: MonacoEditorProvider; | ||
|
||
protected selectNode: HTMLDivElement; | ||
|
||
protected zone: MonacoEditorZoneWidget; | ||
|
||
protected readonly toDispose = new DisposableCollection(); | ||
|
||
protected context: DebugBreakpointWidget.Context = 'condition'; | ||
protected values: { | ||
[context in DebugBreakpointWidget.Context]?: string | ||
} = {}; | ||
|
||
protected input: MonacoEditor; | ||
|
||
@postConstruct() | ||
protected async init(): Promise<void> { | ||
this.toDispose.push(this.zone = new MonacoEditorZoneWidget(this.editor)); | ||
this.zone.containerNode.classList.add('theia-debug-breakpoint-widget'); | ||
|
||
const selectNode = this.selectNode = document.createElement('div'); | ||
selectNode.classList.add('theia-debug-breakpoint-select'); | ||
this.zone.containerNode.appendChild(selectNode); | ||
|
||
const inputNode = document.createElement('div'); | ||
inputNode.classList.add('theia-debug-breakpoint-input'); | ||
this.zone.containerNode.appendChild(inputNode); | ||
|
||
// TODO: move input together with breakpoint decorations | ||
// TODO: placeholder | ||
// TODO: completions | ||
this.toDispose.push(this.input = await this.createInput(inputNode)); | ||
this.toDispose.push(this.zone.onDidLayoutChange(dimension => this.layout(dimension))); | ||
this.toDispose.push(this.input.getControl().onDidChangeModelContent(() => { | ||
const heightInLines = this.input.getControl().getModel().getLineCount() + 1; | ||
this.zone.layout(heightInLines); | ||
})); | ||
this.renderSelect(); | ||
this.toDispose.push(Disposable.create(() => ReactDOM.unmountComponentAtNode(selectNode))); | ||
} | ||
|
||
dispose(): void { | ||
this.toDispose.dispose(); | ||
} | ||
|
||
show(options: ShowDebugBreakpointOptions): void { | ||
if (options instanceof DebugBreakpoint) { | ||
if (options.logMessage) { | ||
this.context = 'logMessage'; | ||
} else if (options.hitCondition && !options.condition) { | ||
this.context = 'hitCondition'; | ||
} else { | ||
this.context = 'condition'; | ||
} | ||
this.values = { | ||
condition: options.condition, | ||
hitCondition: options.hitCondition, | ||
logMessage: options.logMessage | ||
}; | ||
} else { | ||
this.context = options.context; | ||
this.values = {}; | ||
} | ||
const editor = this.input.getControl(); | ||
const afterLineNumber = options instanceof DebugBreakpoint ? options.line : options.position.lineNumber; | ||
const afterColumn = options instanceof DebugBreakpoint ? options.column : options.position.column; | ||
const heightInLines = editor.getModel().getLineCount() + 1; | ||
this.zone.show({ afterLineNumber, afterColumn, heightInLines }); | ||
editor.setPosition(editor.getModel().getPositionAt(editor.getModel().getValueLength())); | ||
this.input.focus(); | ||
// TODO ENTER -> apply + focus editor | ||
// TODO SHIFT + ENTER -> new line | ||
// TODO ESC -> abort + focus editor | ||
} | ||
|
||
hide(): void { | ||
this.zone.hide(); | ||
} | ||
|
||
protected layout(dimension: monaco.editor.IDimension): void { | ||
this.input.getControl().layout(dimension); | ||
} | ||
|
||
protected createInput(node: HTMLElement): Promise<MonacoEditor> { | ||
return this.editorProvider.createInline(new URI().withScheme('breakpointinput').withPath(this.editor.getId()), node, { | ||
autoSizing: false | ||
}); | ||
} | ||
|
||
protected renderSelect(): void { | ||
if (this.toDispose.disposed) { | ||
return; | ||
} | ||
ReactDOM.render(<select value={this.context} onChange={this.updateInput}> | ||
{this.renderOption('condition', 'Expression')} | ||
{this.renderOption('hitCondition', 'Hit Count')} | ||
{this.renderOption('logMessage', 'Log Message')} | ||
</select>, this.selectNode); | ||
} | ||
protected renderOption(context: DebugBreakpointWidget.Context, label: string): JSX.Element { | ||
return <option value={context}>{label}</option>; | ||
} | ||
protected readonly updateInput = (e: React.ChangeEvent<HTMLSelectElement>) => { | ||
this.values[this.context] = this.input.getControl().getValue(); | ||
this.context = e.currentTarget.value as DebugBreakpointWidget.Context; | ||
this.input.getControl().setValue(this.values[this.context] || ''); | ||
this.renderSelect(); | ||
} | ||
|
||
} | ||
export namespace DebugBreakpointWidget { | ||
export type Context = keyof Pick<DebugProtocol.SourceBreakpoint, 'condition' | 'hitCondition' | 'logMessage'>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.