Skip to content

Commit

Permalink
debug console: add copy all action
Browse files Browse the repository at this point in the history
  • Loading branch information
isidorn committed May 16, 2017
1 parent cd6ee09 commit 9afd541
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/vs/workbench/parts/debug/common/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ export interface ITreeElement {
getId(): string;
}

export interface IReplElement extends ITreeElement {
toString(): string;
}

export interface IExpressionContainer extends ITreeElement {
hasChildren: boolean;
getChildren(): TPromise<IExpression[]>;
}

export interface IExpression extends ITreeElement, IExpressionContainer {
export interface IExpression extends IReplElement, IExpressionContainer {
name: string;
value: string;
valueChanged?: boolean;
Expand Down Expand Up @@ -277,7 +281,7 @@ export interface IModel extends ITreeElement {
getFunctionBreakpoints(): IFunctionBreakpoint[];
getExceptionBreakpoints(): IExceptionBreakpoint[];
getWatchExpressions(): IExpression[];
getReplElements(): ITreeElement[];
getReplElements(): IReplElement[];

onDidChangeBreakpoints: Event<void>;
onDidChangeCallStack: Event<void>;
Expand Down
32 changes: 27 additions & 5 deletions src/vs/workbench/parts/debug/common/debugModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import { ISuggestion } from 'vs/editor/common/modes';
import { Position } from 'vs/editor/common/core/position';
import {
ITreeElement, IExpression, IExpressionContainer, IProcess, IStackFrame, IExceptionBreakpoint, IBreakpoint, IFunctionBreakpoint, IModel,
IConfig, ISession, IThread, IRawModelUpdate, IScope, IRawStoppedDetails, IEnablement, IRawBreakpoint, IExceptionInfo
IConfig, ISession, IThread, IRawModelUpdate, IScope, IRawStoppedDetails, IEnablement, IRawBreakpoint, IExceptionInfo, IReplElement
} from 'vs/workbench/parts/debug/common/debug';
import { Source } from 'vs/workbench/parts/debug/common/debugSource';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';

const MAX_REPL_LENGTH = 10000;

export abstract class AbstractOutputElement implements ITreeElement {
export abstract class AbstractOutputElement implements IReplElement {
private static ID_COUNTER = 0;

constructor(private id = AbstractOutputElement.ID_COUNTER++) {
Expand All @@ -35,6 +35,8 @@ export abstract class AbstractOutputElement implements ITreeElement {
public getId(): string {
return `outputelement:${this.id}`;
}

abstract toString(): string;
}

export class OutputElement extends AbstractOutputElement {
Expand All @@ -48,6 +50,10 @@ export class OutputElement extends AbstractOutputElement {
super();
this.counter = 1;
}

public toString(): string {
return this.value;
}
}

export class OutputNameValueElement extends AbstractOutputElement implements IExpression {
Expand Down Expand Up @@ -88,6 +94,10 @@ export class OutputNameValueElement extends AbstractOutputElement implements IEx

return TPromise.as(result);
}

public toString(): string {
return `${this.name}: ${this.value}`;
}
}

export class ExpressionContainer implements IExpressionContainer {
Expand Down Expand Up @@ -197,6 +207,10 @@ export class ExpressionContainer implements IExpressionContainer {
ExpressionContainer.allValues.get(this.getId()) !== Expression.DEFAULT_VALUE && ExpressionContainer.allValues.get(this.getId()) !== value;
ExpressionContainer.allValues.set(this.getId(), value);
}

public toString(): string {
return this.value;
}
}

export class Expression extends ExpressionContainer implements IExpression {
Expand Down Expand Up @@ -244,6 +258,10 @@ export class Expression extends ExpressionContainer implements IExpression {
this.reference = 0;
});
}

public toString(): string {
return `${this.name}\n${this.value}`;
}
}

export class Variable extends ExpressionContainer implements IExpression {
Expand Down Expand Up @@ -285,6 +303,10 @@ export class Variable extends ExpressionContainer implements IExpression {
this.errorMessage = err.message;
});
}

public toString(): string {
return `${this.name}: ${this.value}`;
}
}

export class Scope extends ExpressionContainer implements IScope {
Expand Down Expand Up @@ -714,7 +736,7 @@ export class Model implements IModel {

private processes: Process[];
private toDispose: lifecycle.IDisposable[];
private replElements: ITreeElement[];
private replElements: IReplElement[];
private _onDidChangeBreakpoints: Emitter<void>;
private _onDidChangeCallStack: Emitter<void>;
private _onDidChangeWatchExpressions: Emitter<IExpression>;
Expand Down Expand Up @@ -902,7 +924,7 @@ export class Model implements IModel {
this._onDidChangeBreakpoints.fire();
}

public getReplElements(): ITreeElement[] {
public getReplElements(): IReplElement[] {
return this.replElements;
}

Expand Down Expand Up @@ -939,7 +961,7 @@ export class Model implements IModel {
this._onDidChangeREPLElements.fire();
}

private addReplElements(newElements: ITreeElement[]): void {
private addReplElements(newElements: IReplElement[]): void {
this.replElements.push(...newElements);
if (this.replElements.length > MAX_REPL_LENGTH) {
this.replElements.splice(0, this.replElements.length - MAX_REPL_LENGTH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import * as nls from 'vs/nls';
import { Action } from 'vs/base/common/actions';
import { TPromise } from 'vs/base/common/winjs.base';
import { clipboard } from 'electron';
import { ITree } from 'vs/base/parts/tree/browser/tree';
import { Variable } from 'vs/workbench/parts/debug/common/debugModel';
import { IDebugService, IStackFrame } from 'vs/workbench/parts/debug/common/debug';
import { clipboard } from 'electron';

export class CopyValueAction extends Action {
static ID = 'workbench.debug.viewlet.action.copyValue';
Expand Down Expand Up @@ -42,6 +43,30 @@ export class CopyAction extends Action {
}
}

export class CopyAllAction extends Action {
static ID = 'workbench.debug.action.copyAll';
static LABEL = nls.localize('copyAll', "Copy All");

constructor(id: string, label: string, private tree: ITree) {
super(id, label);
}

public run(): TPromise<any> {
let text = '';
const navigator = this.tree.getNavigator();
// skip first navigator element - the root node
while (navigator.next()) {
if (text) {
text += `\n`;
}
text += navigator.current().toString();
}

clipboard.writeText(text);
return TPromise.as(null);
}
}

export class CopyStackTraceAction extends Action {
static ID = 'workbench.action.debug.copyStackTrace';
static LABEL = nls.localize('copyStackTrace', "Copy Call Stack");
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/parts/debug/electron-browser/replViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { IExpressionContainer, IExpression } from 'vs/workbench/parts/debug/comm
import { Model, OutputNameValueElement, Expression, OutputElement, Variable } from 'vs/workbench/parts/debug/common/debugModel';
import { renderVariable, renderExpressionValue, IVariableTemplateData, BaseDebugController } from 'vs/workbench/parts/debug/electron-browser/debugViewer';
import { ClearReplAction } from 'vs/workbench/parts/debug/browser/debugActions';
import { CopyAction } from 'vs/workbench/parts/debug/electron-browser/electronDebugActions';
import { CopyAction, CopyAllAction } from 'vs/workbench/parts/debug/electron-browser/electronDebugActions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { LinkDetector } from 'vs/workbench/parts/debug/browser/linkDetector';
Expand Down Expand Up @@ -408,6 +408,7 @@ export class ReplExpressionsActionProvider implements IActionProvider {
public getSecondaryActions(tree: ITree, element: any): TPromise<IAction[]> {
const actions: IAction[] = [];
actions.push(new CopyAction(CopyAction.ID, CopyAction.LABEL));
actions.push(new CopyAllAction(CopyAllAction.ID, CopyAllAction.LABEL, tree));
actions.push(this.instantiationService.createInstance(ClearReplAction, ClearReplAction.ID, ClearReplAction.LABEL));

return TPromise.as(actions);
Expand Down

0 comments on commit 9afd541

Please sign in to comment.