From 1e389f6023f3a8f846c5a14b2469a21f5e55e191 Mon Sep 17 00:00:00 2001 From: Chance An Date: Mon, 5 Feb 2018 15:14:20 -0800 Subject: [PATCH] Override the variables retrieval and mutation logic for EDP. --- package.json | 2 +- src/edgeDebugAdapter.ts | 28 ++++++++++++++-- src/edgeVariablesContainer.ts | 60 +++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 src/edgeVariablesContainer.ts diff --git a/package.json b/package.json index 1288ad96..33f2b4b4 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ ], "license": "SEE LICENSE IN LICENSE.txt", "dependencies": { - "vscode-chrome-debug-core": "3.22.5", + "vscode-chrome-debug-core": "3.22.7", "vscode-debugadapter": "^1.24.0", "vscode-nls": "https://registry.npmjs.org/vscode-nls/-/vscode-nls-2.0.2.tgz" }, diff --git a/src/edgeDebugAdapter.ts b/src/edgeDebugAdapter.ts index 5cc32ff0..0b020494 100644 --- a/src/edgeDebugAdapter.ts +++ b/src/edgeDebugAdapter.ts @@ -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/*', @@ -192,7 +198,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)}`); @@ -283,6 +289,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 { diff --git a/src/edgeVariablesContainer.ts b/src/edgeVariablesContainer.ts new file mode 100644 index 00000000..b300e9e4 --- /dev/null +++ b/src/edgeVariablesContainer.ts @@ -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 { + 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 { + 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; + } +} \ No newline at end of file