Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into WIP/eager
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Sep 16, 2016
2 parents 7b0c298 + 65ccf37 commit b15a9f4
Show file tree
Hide file tree
Showing 8 changed files with 414 additions and 76 deletions.
12 changes: 8 additions & 4 deletions src/chrome/chromeConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ export class ChromeConnection {
return this.sendMessage('Debugger.pause');
}

public debugger_evaluateOnCallFrame(callFrameId: string, expression: string, objectGroup = 'dummyObjectGroup', returnByValue?: boolean): Promise<Chrome.Debugger.EvaluateOnCallFrameResponse> {
return this.sendMessage('Debugger.evaluateOnCallFrame', <Chrome.Debugger.EvaluateOnCallFrameParams>{ callFrameId, expression, objectGroup, returnByValue });
public debugger_evaluateOnCallFrame(callFrameId: string, expression: string, objectGroup = 'dummyObjectGroup', returnByValue?: boolean, silent?: boolean): Promise<Chrome.Debugger.EvaluateOnCallFrameResponse> {
return this.sendMessage('Debugger.evaluateOnCallFrame', <Chrome.Debugger.EvaluateOnCallFrameParams>{ callFrameId, expression, objectGroup, returnByValue, silent });
}

public debugger_setPauseOnExceptions(state: string): Promise<Chrome.Response> {
Expand All @@ -245,8 +245,12 @@ export class ChromeConnection {
return this.sendMessage('Debugger.getScriptSource', <Chrome.Debugger.GetScriptSourceParams>{ scriptId });
}

public runtime_getProperties(objectId: string, ownProperties: boolean, accessorPropertiesOnly: boolean): Promise<Chrome.Runtime.GetPropertiesResponse> {
return this.sendMessage('Runtime.getProperties', <Chrome.Runtime.GetPropertiesParams>{ objectId, ownProperties, accessorPropertiesOnly, generatePreview: true });
public debugger_setVariableValue(callFrameId: string, scopeNumber: number, variableName: string, newValue: Chrome.Runtime.CallArgument): Promise<Chrome.Debugger.SetVariableResponse> {
return this.sendMessage('Debugger.setVariableValue', <Chrome.Debugger.SetVariableParams>{ callFrameId, scopeNumber, variableName, newValue });
}

public runtime_getProperties(objectId: string, ownProperties: boolean, accessorPropertiesOnly: boolean, generatePreview?: boolean): Promise<Chrome.Runtime.GetPropertiesResponse> {
return this.sendMessage('Runtime.getProperties', <Chrome.Runtime.GetPropertiesParams>{ objectId, ownProperties, accessorPropertiesOnly, generatePreview });
}

public runtime_evaluate(expression: string, objectGroup = 'dummyObjectGroup', contextId = 1, returnByValue = false): Promise<Chrome.Runtime.EvaluateResponse> {
Expand Down
339 changes: 270 additions & 69 deletions src/chrome/chromeDebugAdapter.ts

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion src/chrome/chromeDebugProtocol.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ export namespace Debugger {
scriptSource: string;
};
}

export interface SetVariableParams {
scopeNumber: number;
variableName: string;
newValue: Runtime.CallArgument;
callFrameId: string;
}

export type SetVariableResponse = Response;
}

export namespace Runtime {
Expand Down Expand Up @@ -179,7 +188,6 @@ export namespace Runtime {
preview?: {
type: string;
description: string;
lossless: boolean;
overflow: boolean;
properties: PropertyPreview[];
};
Expand Down
35 changes: 34 additions & 1 deletion src/chrome/chromeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import * as url from 'url';
import * as path from 'path';

import * as utils from '../utils';
import * as Chrome from './chromeDebugProtocol';
import * as utils from '../utils';

/**
* Maps a url from target to an absolute local path.
Expand Down Expand Up @@ -55,6 +55,7 @@ export function targetUrlToClientPath(webRoot: string, aUrl: string): string {

/**
* Convert a RemoteObject to a value+variableHandleRef for the client.
* TODO - Delete after Microsoft/vscode#12019!
*/
export function remoteObjectToValue(object: Chrome.Runtime.RemoteObject, stringify = true): { value: string, variableHandleRef?: string } {
let value = '';
Expand Down Expand Up @@ -154,3 +155,35 @@ export function compareVariableNames(var1: string, var2: string): number {
// Compare strings as strings
return var1.localeCompare(var2);
}

/**
* Maybe this can be merged with remoteObjectToValue, they are somewhat similar
*/
export function remoteObjectToCallArgument(object: Chrome.Runtime.RemoteObject): Chrome.Runtime.CallArgument {
if (object) {
if (object.type === 'object') {
if (object.subtype === 'null') {
return { value: null };
} else {
// It's a non-null object, create a variable reference so the client can ask for its props
return { objectId: object.objectId };
}
} else if (object.type === 'undefined') {
return { value: undefined }; // ?
} else if (object.type === 'function') {
return { objectId: object.objectId };
} else {
// The value is a primitive value, or something that has a description (not object, primitive, or undefined). And force to be string
if (typeof object.value === 'undefined') {
return { value: undefined }; // uh
} else {
return { value: object.value }; // ??
}
}
}
}

export function errorMessageFromExceptionDetails(exceptionDetails: any): string {
const description: string = exceptionDetails.exception.description;
return description.substr(0, description.indexOf('\n'));
}
71 changes: 71 additions & 0 deletions src/chrome/variables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import * as DebugProtocol from 'vscode-debugadapter';

import {ChromeDebugAdapter} from './chromeDebugAdapter';
import * as Chrome from './chromeDebugProtocol.d';

export interface IVariableContainer {
objectId: string;
expand(adapter: ChromeDebugAdapter, filter?: string, start?: number, count?: number): Promise<DebugProtocol.Variable[]>;
setValue(adapter: ChromeDebugAdapter, name: string, value: string): Promise<string>;
}

export abstract class BaseVariableContainer implements IVariableContainer {
constructor(public objectId: string) {
}

public expand(adapter: ChromeDebugAdapter, filter?: string, start?: number, count?: number): Promise<DebugProtocol.Variable[]> {
return adapter.getVariablesForObjectId(this.objectId, filter, start, count);
}

public abstract setValue(adapter: ChromeDebugAdapter, name: string, value: string): Promise<string>;
}

export class PropertyContainer extends BaseVariableContainer {
public setValue(adapter: ChromeDebugAdapter, name: string, value: string): Promise<string> {
return adapter._setPropertyValue(this.objectId, name, value);
}
}

export class ScopeContainer extends BaseVariableContainer {
public thisObj: Chrome.Runtime.RemoteObject;

private _frameId: string;
private _scopeIndex: number;

public constructor(frameId: string, scopeIndex: number, objectId: string, thisObj?: Chrome.Runtime.RemoteObject) {
super(objectId);
this.thisObj = thisObj;
this._frameId = frameId;
this._scopeIndex = scopeIndex;
}

/**
* Call super then insert the 'this' object if needed
*/
public expand(adapter: ChromeDebugAdapter, filter?: string, start?: number, count?: number): Promise<DebugProtocol.Variable[]> {
// No filtering in scopes right now
return super.expand(adapter, 'all', start, count).then(variables => {
if (this.thisObj) {
// If this is a scope that should have the 'this', prop, insert it at the top of the list
return adapter.propertyDescriptorToVariable(<any>{ name: 'this', value: this.thisObj }).then(thisObjVar => {
variables.unshift(thisObjVar);
return variables;
});
} else {
return variables;
}
});
}

public setValue(adapter: ChromeDebugAdapter, name: string, value: string): Promise<string> {
return adapter._setVariableValue(this._frameId, this._scopeIndex, name, value);
}
}

export function isIndexedPropName(name: string): boolean {
return !isNaN(parseInt(name, 10));
}
7 changes: 7 additions & 0 deletions src/debugAdapterInterfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ export interface IVariablesResponseBody {

export interface IEvaluateResponseBody {
result: string;
type?: string;
variablesReference: number;
namedVariables?: number;
indexedVariables?: number;
}

export interface ISetVariableResponseBody {
value: string;
}

declare type PromiseOrNot<T> = T | Promise<T>;
Expand Down
14 changes: 14 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,18 @@ export function withInfoLink(id: number, format: string, variables: any, infoId:
url: 'http://go.microsoft.com/fwlink/?linkID=534832#_' + infoId.toString(),
urlLabel: localize('more.information', "More Information")
};
}

export function setValueNotSupported(): DebugProtocol.Message {
return {
id: 2004,
format: localize('setVariable.error', "Setting value not supported")
};
}

export function errorFromEvaluate(errMsg: string): DebugProtocol.Message {
return {
id: 2025,
format: errMsg
};
}
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"spaces"
],
"align": [
true,
false,
"statements"
],
"ban": false,
Expand Down

0 comments on commit b15a9f4

Please sign in to comment.