Skip to content

Commit

Permalink
feat(frontend): restart last run configuration by shortcut (GoogleChr…
Browse files Browse the repository at this point in the history
…omeLabs#81)


drive-by: fix sourcemap.

Fixes GoogleChromeLabs#77
Fixes GoogleChromeLabs#40
  • Loading branch information
alexkozy authored Jul 30, 2018
1 parent 7ecae39 commit f947569
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
61 changes: 61 additions & 0 deletions front_end/ndb/NdbMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ Ndb.NodeProcessManager = class extends Common.Object {
this._idToInstance = new Map();
this._idToConnection = new Map();

this._lastDebugId = 0;
this._lastStarted = null;

this._targetManager.addModelListener(
SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._onExecutionContextDestroyed, this);
}
Expand Down Expand Up @@ -438,9 +441,12 @@ Ndb.NodeProcessManager = class extends Common.Object {
}

debug(execPath, args) {
const debugId = String(++this._lastDebugId);
this._lastStarted = {execPath, args, debugId};
return this._nddService.call('debug', {
execPath, args, options: {
waitAtStart: true,
data: debugId,
cwd: NdbProcessInfo.cwd
}
});
Expand All @@ -459,6 +465,19 @@ Ndb.NodeProcessManager = class extends Common.Object {
instanceId: instance.id()
});
}

async restartLast() {
if (!this._lastStarted)
return;
for (const instance of this._idToInstance.values()) {
if (instance.debugId() === this._lastStarted.debugId) {
await this.kill(instance);
break;
}
}
const {execPath, args} = this._lastStarted;
this.debug(execPath, args);
}
};

/** @enum {symbol} */
Expand Down Expand Up @@ -508,6 +527,7 @@ Ndb.NodeProcess = class {
this._groupId = data.groupId;
this._instanceId = data.instanceId;
this._url = data.url;
this._debugId = data.data || null;

this._parent = parent;
this._target = null;
Expand All @@ -533,6 +553,10 @@ Ndb.NodeProcess = class {
return this._parent;
}

debugId() {
return this._debugId;
}

userFriendlyName() {
return this.argv().map(arg => {
const index1 = arg.lastIndexOf('/');
Expand All @@ -557,6 +581,27 @@ Ndb.NodeProcess = class {
}
};

/**
* @implements {UI.ActionDelegate}
* @unrestricted
*/
Ndb.RestartActionDelegate = class {
/**
* @override
* @param {!UI.Context} context
* @param {string} actionId
* @return {boolean}
*/
handleAction(context, actionId) {
switch (actionId) {
case 'ndb.restart':
Ndb.NodeProcessManager.instance().then(manager => manager.restartLast());
return true;
}
return false;
}
};

SDK.DebuggerModel.prototype.scheduleStepIntoAsync = function() {
this._agent.scheduleStepIntoAsync();
this._agent.invoke_stepInto({breakOnAsyncCall: true});
Expand Down Expand Up @@ -612,3 +657,19 @@ DOMTokenList.prototype.toggle = function(token, force) {
force = !this.contains(token);
return originalToggle.call(this, token, !!force);
};

Bindings.CompilerScriptMapping.prototype._sourceMapDetached = function(event) {
const script = /** @type {!SDK.Script} */ (event.data.client);
const frameId = script[Bindings.CompilerScriptMapping._frameIdSymbol];
const sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap);
const bindings = script.isContentScript() ? this._contentScriptsBindings : this._regularBindings;
for (const sourceURL of sourceMap.sourceURLs()) {
const binding = bindings.get(sourceURL);
if (!binding)
continue;
binding.removeSourceMap(sourceMap, frameId);
if (!binding._uiSourceCode)
bindings.delete(sourceURL);
}
this._debuggerWorkspaceBinding.updateLocations(script);
};
16 changes: 16 additions & 0 deletions front_end/ndb/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@
"settingType": "boolean",
"defaultValue": true
},
{
"type": "action",
"actionId": "ndb.restart",
"className": "Ndb.RestartActionDelegate",
"title": "Restart last run configuration",
"bindings": [
{
"platform": "windows,linux",
"shortcut": "F5 Ctrl+R"
},
{
"platform": "mac",
"shortcut": "Meta+R"
}
]
},
{
"type": "@UI.ContextMenu.Provider",
"contextTypes": [
Expand Down
2 changes: 2 additions & 0 deletions node_debug_demon/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ try {
};
if (parentProcessId)
state.parentId = parentProcessId;
if (process.env.NDD_DATA)
state.data = process.env.NDD_DATA;
fs.writeFileSync(stateFileName, JSON.stringify(state));

const readyFileName = path.join(nddStore, `${nodePid}-ready`);
Expand Down
2 changes: 2 additions & 0 deletions services/ndd_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class NddService extends ServiceBase {
env.NDD_WAIT_AT_START = 1;
if (options && options.groupId)
env.NDD_GROUP_ID = options.groupId;
if (options && options.data)
env.NDD_DATA = options.data;
const p = spawn(execPath, args, {
cwd: options.cwd,
env: { ...process.env, ...env },
Expand Down

0 comments on commit f947569

Please sign in to comment.