Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1483)

Unified Diff: Source/devtools/front_end/sdk/RuntimeModel.js

Issue 1264133002: Devtools: [WIP] Implement enhanced devtools extension language APIs Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Modify override dropdown to apply to console completions & transpile Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/devtools/front_end/sdk/RuntimeModel.js
diff --git a/Source/devtools/front_end/sdk/RuntimeModel.js b/Source/devtools/front_end/sdk/RuntimeModel.js
index 44f8c32c01b7ee86eb0fe3153e64c7d3c95c310e..f402b5a95a147a0d09f312d28fdff537f69c3f80 100644
--- a/Source/devtools/front_end/sdk/RuntimeModel.js
+++ b/Source/devtools/front_end/sdk/RuntimeModel.js
@@ -37,6 +37,19 @@ WebInspector.RuntimeModel = function(target)
{
WebInspector.SDKModel.call(this, WebInspector.RuntimeModel, target);
+ /**
+ * @param {!WebInspector.DebuggerModel.Location} raw
+ * @suppress {missingProperties}
+ */
+ this._locationResolver = raw => {
pfeldman 2015/08/13 21:15:46 SDK can't depend on the bindings, source mappings
wes 2015/08/14 00:55:05 This was literally a hack I threw in the other day
pfeldman 2015/08/17 21:15:52 Your _locationResolver looks very similar to the s
wes 2015/08/25 18:13:18 Already gone. :3
+ if (!WebInspector.debuggerWorkspaceBinding) return;
+ var loc = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(raw);
+ return {
+ source: loc.uiSourceCode.contentURL(),
+ line: loc.lineNumber,
+ column: loc.columnNumber
+ };
+ };
this._agent = target.runtimeAgent();
this.target().registerRuntimeDispatcher(new WebInspector.RuntimeDispatcher(this));
if (target.hasJSContext())
@@ -81,7 +94,7 @@ WebInspector.RuntimeModel.prototype = {
if (context.name == WebInspector.RuntimeModel._privateScript && !context.origin && !Runtime.experiments.isEnabled("privateScriptInspection")) {
return;
}
- var executionContext = new WebInspector.ExecutionContext(this.target(), context.id, context.name, context.origin, !!context.isPageContext, context.frameId);
+ var executionContext = new WebInspector.ExecutionContext(this.target(), this._locationResolver, context.id, context.name, context.origin, !!context.isPageContext, context.frameId);
this._executionContextById[executionContext.id] = executionContext;
this.dispatchEventToListeners(WebInspector.RuntimeModel.Events.ExecutionContextCreated, executionContext);
},
@@ -200,15 +213,17 @@ WebInspector.RuntimeDispatcher.prototype = {
* @constructor
* @extends {WebInspector.SDKObject}
* @param {!WebInspector.Target} target
+ * @param {function(!WebInspector.DebuggerModel.Location): ({source: string, line: number, column: number}|undefined)} locationResolver
* @param {number|undefined} id
* @param {string} name
* @param {string} origin
* @param {boolean} isPageContext
* @param {string=} frameId
*/
-WebInspector.ExecutionContext = function(target, id, name, origin, isPageContext, frameId)
+WebInspector.ExecutionContext = function(target, locationResolver, id, name, origin, isPageContext, frameId)
{
WebInspector.SDKObject.call(this, target);
+ this._locationResolver = locationResolver;
this.id = id;
this.name = name;
this.origin = origin;
@@ -322,15 +337,55 @@ WebInspector.ExecutionContext.prototype = {
}
this.target().runtimeAgent().evaluate(expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, this.id, returnByValue, generatePreview, evalCallback.bind(this));
},
+
+ /**
+ * @return {({source: string, line: number, column: number}|undefined)}
+ */
+ pauseLocation: function() {
+ var frame = this.debuggerModel.selectedCallFrame();
+ var raw;
+ if (frame && (raw = frame.location())) {
+ return this._locationResolver(raw);
+ }
+ return;
+ },
/**
* @param {string} expressionString
+ * @param {string} text
+ * @param {number} cursorOffset
* @param {string} prefix
* @param {boolean} force
* @param {function(!Array.<string>, number=)} completionsReadyCallback
*/
- completionsForExpression: function(expressionString, prefix, force, completionsReadyCallback)
+ completionsForExpression: function(expressionString, text, cursorOffset, prefix, force, completionsReadyCallback)
{
+ var location = this.pauseLocation();
pfeldman 2015/08/13 21:15:46 You should transpile expressionString prior to get
wes 2015/08/14 00:55:05 Is expressionString supposed to be an identifier f
pfeldman 2015/08/17 21:15:52 This would also go into your module
wes 2015/08/25 18:13:18 And so it has.
+
+ function handleDebuggerCompletionsComplete(vals) {
+ if (!vals) {
+ completionsReadyCallback([]);
+ }
+ completionsReadyCallback(vals.map(function(v) { return v.text; }));
+ }
+
+ //If possible, ceede to the language service
+ if (location) { //paused - get active mime from pause location
+ var mime = WebInspector.ResourceType.mimeFromUrl(location.source);
+
+ if (WebInspector.languageService.handles.debuggerCompletions(mime)) {
+ WebInspector.languageService.debuggerCompletions(mime, text, cursorOffset, prefix, location).then(handleDebuggerCompletionsComplete);
+ return;
+ }
+ } else { //not paused - get active mime from source pane
+ var activeDocMime = WebInspector.ResourceType.fromActivePanel();
+
+ if (WebInspector.languageService.handles.debuggerCompletions(activeDocMime)) {
+ WebInspector.languageService.debuggerCompletions(activeDocMime, text, cursorOffset, prefix, undefined).then(handleDebuggerCompletionsComplete);
+ return;
+ }
+ }
+
var lastIndex = expressionString.length - 1;
var dotNotation = (expressionString[lastIndex] === ".");
@@ -350,8 +405,9 @@ WebInspector.ExecutionContext.prototype = {
return;
}
- if (!expressionString && this.debuggerModel.selectedCallFrame())
- this.debuggerModel.selectedCallFrame().variableNames(receivedPropertyNames.bind(this));
+ var frame = this.debuggerModel.selectedCallFrame();
+ if (!expressionString && frame)
+ frame.variableNames(receivedPropertyNames.bind(this));
else
this.evaluate(expressionString, "completion", true, true, false, false, evaluated.bind(this));

Powered by Google App Engine
This is Rietveld 408576698