Skip to content

Commit

Permalink
debug: 'Add Log Point...' context menu action
Browse files Browse the repository at this point in the history
  • Loading branch information
isidorn committed Mar 16, 2018
1 parent 1a24638 commit 08ba132
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
34 changes: 13 additions & 21 deletions src/vs/workbench/parts/debug/browser/breakpointWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,24 @@ import { InputBox } from 'vs/base/browser/ui/inputbox/inputBox';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { ZoneWidget } from 'vs/editor/contrib/zoneWidget/zoneWidget';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IDebugService, IBreakpoint } from 'vs/workbench/parts/debug/common/debug';
import { IDebugService, IBreakpoint, BreakpointWidgetContext as Context } from 'vs/workbench/parts/debug/common/debug';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { once } from 'vs/base/common/functional';
import { attachInputBoxStyler, attachSelectBoxStyler } from 'vs/platform/theme/common/styler';
import { IThemeService } from 'vs/platform/theme/common/themeService';

const $ = dom.$;

enum Context {
CONDITION = 0,
HIT_COUNT = 1,
LOG_MESSAGE = 2
}

export class BreakpointWidget extends ZoneWidget {

private inputBox: InputBox;
private toDispose: lifecycle.IDisposable[];
private context: Context;
private conditionInput = '';
private hitCountInput = '';
private logMessageInput = '';
private breakpoint: IBreakpoint;

constructor(editor: ICodeEditor, private lineNumber: number, private column: number,
constructor(editor: ICodeEditor, private lineNumber: number, private column: number, private context: Context,
@IContextViewService private contextViewService: IContextViewService,
@IDebugService private debugService: IDebugService,
@IThemeService private themeService: IThemeService
Expand All @@ -50,6 +43,16 @@ export class BreakpointWidget extends ZoneWidget {
const uri = this.editor.getModel().uri;
this.breakpoint = this.debugService.getModel().getBreakpoints().filter(bp => bp.lineNumber === this.lineNumber && bp.column === this.column && bp.uri.toString() === uri.toString()).pop();

if (this.context === undefined) {
if (this.breakpoint && !this.breakpoint.condition && !this.breakpoint.hitCondition && this.breakpoint.logMessage) {
this.context = Context.LOG_MESSAGE;
} else if (this.breakpoint && !this.breakpoint.condition && this.breakpoint.hitCondition) {
this.context = Context.HIT_COUNT;
} else {
this.context = Context.CONDITION;
}
}

this.toDispose.push(this.debugService.getModel().onDidChangeBreakpoints(e => {
if (this.breakpoint && e.removed && e.removed.indexOf(this.breakpoint) >= 0) {
this.dispose();
Expand Down Expand Up @@ -106,18 +109,7 @@ export class BreakpointWidget extends ZoneWidget {

protected _fillContainer(container: HTMLElement): void {
this.setCssClass('breakpoint-widget');
let selected: number;
if (this.breakpoint && !this.breakpoint.condition && !this.breakpoint.hitCondition && this.breakpoint.logMessage) {
this.context = Context.LOG_MESSAGE;
selected = 2;
} else if (this.breakpoint && !this.breakpoint.condition && this.breakpoint.hitCondition) {
this.context = Context.HIT_COUNT;
selected = 1;
} else {
this.context = Context.CONDITION;
selected = 0;
}
const selectBox = new SelectBox([nls.localize('expression', "Expression"), nls.localize('hitCount', "Hit Count"), nls.localize('logMessage', "Log Message")], selected, this.contextViewService);
const selectBox = new SelectBox([nls.localize('expression', "Expression"), nls.localize('hitCount', "Hit Count"), nls.localize('logMessage', "Log Message")], this.context, this.contextViewService);
this.toDispose.push(attachSelectBoxStyler(selectBox, this.themeService));
selectBox.render(dom.append(container, $('.breakpoint-select-container')));
selectBox.onDidSelect(e => {
Expand Down
7 changes: 6 additions & 1 deletion src/vs/workbench/parts/debug/common/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,14 @@ export interface IDebugService {
}

// Editor interfaces
export enum BreakpointWidgetContext {
CONDITION = 0,
HIT_COUNT = 1,
LOG_MESSAGE = 2
}
export interface IDebugEditorContribution extends IEditorContribution {
showHover(range: Range, focus: boolean): TPromise<void>;
showBreakpointWidget(lineNumber: number, column: number): void;
showBreakpointWidget(lineNumber: number, column: number, context?: BreakpointWidgetContext): void;
closeBreakpointWidget(): void;
addLaunchConfiguration(): TPromise<any>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/c
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { DebugHoverWidget } from 'vs/workbench/parts/debug/electron-browser/debugHover';
import { RemoveBreakpointAction, EditConditionalBreakpointAction, EnableBreakpointAction, DisableBreakpointAction, AddConditionalBreakpointAction } from 'vs/workbench/parts/debug/browser/debugActions';
import { IDebugEditorContribution, IDebugService, State, IBreakpoint, EDITOR_CONTRIBUTION_ID, CONTEXT_BREAKPOINT_WIDGET_VISIBLE, IStackFrame, IDebugConfiguration, IExpression, IExceptionInfo } from 'vs/workbench/parts/debug/common/debug';
import { IDebugEditorContribution, IDebugService, State, IBreakpoint, EDITOR_CONTRIBUTION_ID, CONTEXT_BREAKPOINT_WIDGET_VISIBLE, IStackFrame, IDebugConfiguration, IExpression, IExceptionInfo, BreakpointWidgetContext } from 'vs/workbench/parts/debug/common/debug';
import { BreakpointWidget } from 'vs/workbench/parts/debug/browser/breakpointWidget';
import { ExceptionWidget } from 'vs/workbench/parts/debug/browser/exceptionWidget';
import { FloatingClickWidget } from 'vs/workbench/parts/preferences/browser/preferencesWidgets';
Expand Down Expand Up @@ -135,6 +135,13 @@ export class DebugEditorContribution implements IDebugEditorContribution {
() => this.debugService.addBreakpoints(uri, [{ lineNumber }])
));
actions.push(new AddConditionalBreakpointAction(AddConditionalBreakpointAction.ID, AddConditionalBreakpointAction.LABEL, this.editor, lineNumber, this.debugService, this.keybindingService));
actions.push(new Action(
'addLogPoint',
nls.localize('addLogPoint', "Add Log Point..."),
null,
true,
() => TPromise.as(this.editor.getContribution<IDebugEditorContribution>(EDITOR_CONTRIBUTION_ID).showBreakpointWidget(lineNumber, undefined, BreakpointWidgetContext.LOG_MESSAGE))
));
}

return TPromise.as(actions);
Expand Down Expand Up @@ -346,12 +353,12 @@ export class DebugEditorContribution implements IDebugEditorContribution {
// end hover business

// breakpoint widget
public showBreakpointWidget(lineNumber: number, column: number): void {
public showBreakpointWidget(lineNumber: number, column: number, context?: BreakpointWidgetContext): void {
if (this.breakpointWidget) {
this.breakpointWidget.dispose();
}

this.breakpointWidget = this.instantiationService.createInstance(BreakpointWidget, this.editor, lineNumber, column);
this.breakpointWidget = this.instantiationService.createInstance(BreakpointWidget, this.editor, lineNumber, column, context);
this.breakpointWidget.show({ lineNumber, column: 1 }, 2);
this.breakpointWidgetVisible.set(true);
}
Expand Down

0 comments on commit 08ba132

Please sign in to comment.