Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Override the variables retrieval and mutation logic for EDP.
Browse files Browse the repository at this point in the history
  • Loading branch information
changsi-an committed Feb 7, 2018
1 parent 456613a commit 6c242c1
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/edgeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ import * as path from 'path';

import {ChromeDebugAdapter as CoreDebugAdapter, logger, utils as coreUtils, ISourceMapPathOverrides} from 'vscode-chrome-debug-core';
import {spawn, ChildProcess, fork, execSync} from 'child_process';
import {Crdp, LoadedSourceEventReason, chromeConnection, utils as chromecoreutil} from 'vscode-chrome-debug-core';
import {Crdp, LoadedSourceEventReason, chromeConnection, chromeUtils, variables} from 'vscode-chrome-debug-core';
import {DebugProtocol} from 'vscode-debugprotocol';

import {ILaunchRequestArgs, IAttachRequestArgs, ICommonRequestArgs} from './edgeDebugInterfaces';
import {ExtendedDebugProtocolVariable, MSPropertyContainer} from './edgeVariablesContainer';
import * as utils from './utils';
import * as errors from './errors';

import * as nls from 'vscode-nls';
const localize = nls.config(process.env.VSCODE_NLS_CONFIG)();

export const localize = nls.config(process.env.VSCODE_NLS_CONFIG)();

interface ExtendedEdgeRemoteObject extends Crdp.Runtime.RemoteObject{
msDebuggerPropertyId: string;
}

const DefaultWebSourceMapPathOverrides: ISourceMapPathOverrides = {
'webpack:///./~/*': '${webRoot}/node_modules/*',
Expand Down Expand Up @@ -188,7 +194,7 @@ export class EdgeDebugAdapter extends CoreDebugAdapter {
}

const closeTabApiUrl = `http://127.0.0.1:${this._debugProxyPort}/json/close/${this._debuggerId}`;
return chromecoreutil.getURL(closeTabApiUrl).then(() => {
return coreUtils.getURL(closeTabApiUrl).then(() => {
this._edgeProc = null;
}, (e) => {
logger.log(`Cannot call close API, ${require('util').inspect(e)}`);
Expand Down Expand Up @@ -279,6 +285,22 @@ export class EdgeDebugAdapter extends CoreDebugAdapter {
return edgeProc;
}
}

public createPrimitiveVariable(name: string, object: Crdp.Runtime.RemoteObject, parentEvaluateName?: string, stringify?: boolean): DebugProtocol.Variable {
let variable: ExtendedDebugProtocolVariable = super.createPrimitiveVariable(name, object, parentEvaluateName);
const edgeRemoteObject = object as ExtendedEdgeRemoteObject;
if (edgeRemoteObject.msDebuggerPropertyId) {
variable.msDebuggerPropertyId = edgeRemoteObject.msDebuggerPropertyId;
} else {
throw coreUtils.errP(localize("edge.debug.error.notAssociatedMsDebuggerPropertyId", "Cannot find msDebuggerPropertyId from returned Variable data."));
}

return variable;
}

protected createPropertyContainer(object: Crdp.Runtime.RemoteObject, evaluateName: string): variables.IVariableContainer {
return new MSPropertyContainer(object.objectId, evaluateName);
}
}

function getSourceMapPathOverrides(webRoot: string, sourceMapPathOverrides?: ISourceMapPathOverrides): ISourceMapPathOverrides {
Expand Down
60 changes: 60 additions & 0 deletions src/edgeVariablesContainer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {DebugProtocol} from 'vscode-debugprotocol';
import {logger, variables, Crdp, utils as coreUtils} from 'vscode-chrome-debug-core';
import {localize, EdgeDebugAdapter} from './edgeDebugAdapter';

interface EdgeDebugClient extends Crdp.DebuggerClient {
msSetDebuggerPropertyValue(payload: {
debuggerPropertyId: string,
newValue: string
}): Promise<{}>;
}

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

export class MSPropertyContainer extends variables.BaseVariableContainer {
private _childPropertiesMapping: {
[propertyName: string]: string
}

public constructor(objectId: string, evaluateName?: string) {
super(objectId, evaluateName);

this._childPropertiesMapping = {};
}

public async expand(adapter: EdgeDebugAdapter, filter?: string, start?: number, count?: number): Promise<DebugProtocol.Variable[]> {
let variables = await super.expand(adapter, filter, start, count);

for( let variable of variables) {
let extendedVarialbe = variable as ExtendedDebugProtocolVariable;

if (extendedVarialbe.msDebuggerPropertyId) {
this._childPropertiesMapping[variable.name] = extendedVarialbe.msDebuggerPropertyId;

// Also remove the additional field from `variable`, so it will not appear when report to PineZorro/VS Code
delete extendedVarialbe.msDebuggerPropertyId;
}
}
return variables;
}

public async setValue(adapter: EdgeDebugAdapter, name: string, value: string): Promise<string> {
const msDebuggerPropertyId = this._childPropertiesMapping[name];

if (!msDebuggerPropertyId) {
logger.error(`Cannot find msDebuggerPropertyId for {name}`);
throw coreUtils.errP(localize("edge.debug.error.notFoundMsDebuggerPropertyId", "Cannot find msDebuggerPropertyId for a property."));
}

const edgeDebugClient: EdgeDebugClient = adapter.chrome.Debugger as EdgeDebugClient;

let result = await edgeDebugClient.msSetDebuggerPropertyValue({
"debuggerPropertyId": msDebuggerPropertyId,
"newValue": value
});

return value;
}
}

0 comments on commit 6c242c1

Please sign in to comment.