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

Override the variables retrieval and mutation logic for EDP. #6

Merged
merged 1 commit into from
Feb 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
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 @@ -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)}`);
Expand Down Expand Up @@ -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 {
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;
}
}