Skip to content

Commit

Permalink
Allows the child debug adapter to override some variable handling logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
changsi-an committed Feb 5, 2018
1 parent a4118f6 commit 8b85328
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
20 changes: 14 additions & 6 deletions src/chrome/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {IChromeDebugAdapterOpts, ChromeDebugSession} from './chromeDebugSession'
import {ChromeConnection} from './chromeConnection';
import * as ChromeUtils from './chromeUtils';
import Crdp from '../../crdp/crdp';
import {PropertyContainer, ScopeContainer, ExceptionContainer, isIndexedPropName} from './variables';
import {PropertyContainer, ScopeContainer, ExceptionContainer, isIndexedPropName, IVariableContainer} from './variables';
import * as variables from './variables';
import {formatConsoleArguments, formatExceptionDetails} from './consoleHelper';
import {StoppedEvent2, ReasonType} from './stoppedEvent';
Expand Down Expand Up @@ -74,6 +74,10 @@ export type CrdpDomain = keyof Crdp.CrdpClient;

export type LoadedSourceEventReason = 'new' | 'changed' | 'removed';

export interface ExtendedDebugProtocolVariable extends DebugProtocol.Variable {
msVariableMetadata?: string;
}

export abstract class ChromeDebugAdapter implements IDebugAdapter {
public static EVAL_NAME_PREFIX = ChromeUtils.EVAL_NAME_PREFIX;
public static EVAL_ROOT = '<eval>';
Expand Down Expand Up @@ -1790,7 +1794,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
});
}

public propertyDescriptorToVariable(propDesc: Crdp.Runtime.PropertyDescriptor, owningObjectId?: string, parentEvaluateName?: string): Promise<DebugProtocol.Variable> {
public propertyDescriptorToVariable(propDesc: Crdp.Runtime.PropertyDescriptor, owningObjectId?: string, parentEvaluateName?: string): Promise<ExtendedDebugProtocolVariable> {
if (propDesc.get) {
// Getter
const grabGetterValue = 'function remoteFunction(propName) { return this[propName]; }';
Expand Down Expand Up @@ -1821,7 +1825,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
}
}

public getVariablesForObjectId(objectId: string, evaluateName?: string, filter?: string, start?: number, count?: number): Promise<DebugProtocol.Variable[]> {
public getVariablesForObjectId(objectId: string, evaluateName?: string, filter?: string, start?: number, count?: number): Promise<ExtendedDebugProtocolVariable[]> {
if (typeof start === 'number' && typeof count === 'number') {
return this.getFilteredVariablesForObject(objectId, evaluateName, filter, start, count);
}
Expand Down Expand Up @@ -2166,7 +2170,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
error => Promise.reject<string>(errors.errorFromEvaluate(error.message)));
}

public remoteObjectToVariable(name: string, object: Crdp.Runtime.RemoteObject, parentEvaluateName?: string, stringify = true, context: VariableContext = 'variables'): Promise<DebugProtocol.Variable> {
public remoteObjectToVariable(name: string, object: Crdp.Runtime.RemoteObject, parentEvaluateName?: string, stringify = true, context: VariableContext = 'variables'): Promise<ExtendedDebugProtocolVariable> {
name = name || '""';

if (object) {
Expand Down Expand Up @@ -2236,7 +2240,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
}

const evaluateName = ChromeUtils.getEvaluateName(parentEvaluateName, name);
const variablesReference = this._variableHandles.create(new PropertyContainer(object.objectId, evaluateName), context);
const variablesReference = this._variableHandles.create(this.createPropertyContainer(object, evaluateName), context);
return propCountP.then(({ indexedVariables, namedVariables }) => (<DebugProtocol.Variable>{
name,
value,
Expand All @@ -2248,7 +2252,11 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
}));
}

public createPrimitiveVariable(name: string, object: Crdp.Runtime.RemoteObject, parentEvaluateName?: string, stringify?: boolean): DebugProtocol.Variable {
protected createPropertyContainer(object: Crdp.Runtime.RemoteObject, evaluateName: string): IVariableContainer {
return new PropertyContainer(object.objectId, evaluateName);
}

public createPrimitiveVariable(name: string, object: Crdp.Runtime.RemoteObject, parentEvaluateName?: string, stringify?: boolean): ExtendedDebugProtocolVariable {
const value = variables.getRemoteObjectPreview_primitive(object, stringify);
const variable = this.createPrimitiveVariableWithValue(name, value, parentEvaluateName);
variable.type = object.type;
Expand Down
4 changes: 2 additions & 2 deletions src/chrome/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import {DebugProtocol} from 'vscode-debugprotocol';
import {Handles} from 'vscode-debugadapter';

import {ChromeDebugAdapter, VariableContext} from './chromeDebugAdapter';
import {ChromeDebugAdapter, VariableContext, ExtendedDebugProtocolVariable} from './chromeDebugAdapter';
import Crdp from '../../crdp/crdp';
import * as utils from '../utils';

Expand All @@ -18,7 +18,7 @@ export abstract class BaseVariableContainer implements IVariableContainer {
constructor(protected objectId: string, protected evaluateName?: string) {
}

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

Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import {logger} from 'vscode-debugadapter';

import * as chromeConnection from './chrome/chromeConnection';
import {ChromeDebugAdapter, LoadedSourceEventReason} from './chrome/chromeDebugAdapter';
import {ChromeDebugAdapter, LoadedSourceEventReason, ExtendedDebugProtocolVariable} from './chrome/chromeDebugAdapter';
import {ChromeDebugSession, IChromeDebugSessionOpts} from './chrome/chromeDebugSession';
import * as chromeTargetDiscoveryStrategy from './chrome/chromeTargetDiscoveryStrategy';
import * as chromeUtils from './chrome/chromeUtils';
Expand All @@ -21,6 +21,7 @@ export * from './debugAdapterInterfaces';

import * as utils from './utils';
import * as telemetry from './telemetry';
import * as variables from './chrome/variables';
import {NullLogger} from './nullLogger';

import Crdp from '../crdp/crdp';
Expand All @@ -35,6 +36,7 @@ export {
logger,
stoppedEvent,
LoadedSourceEventReason,
ExtendedDebugProtocolVariable,

UrlPathTransformer,
BasePathTransformer,
Expand All @@ -43,6 +45,7 @@ export {

utils,
telemetry,
variables,
NullLogger,

Crdp
Expand Down

0 comments on commit 8b85328

Please sign in to comment.