-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Live development #1418
Live development #1418
Changes from all commits
f5e0f88
45c7602
6d8f543
acda640
818a175
909bf81
cfef069
1671a25
4a49d9f
8454fdc
c2eab82
0322966
feed872
c971dce
6b7c951
009928e
afb1398
08c903d
0d045ec
2d750f6
8f36b0c
32b2c30
bbeead1
4c10e24
efe6806
7ec6bed
b4e5ffc
1067c9e
e986c0d
b5fb39f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,13 @@ define(function GotoAgent(require, exports, module) { | |
for (i in node.trace) { | ||
_makeJSTarget(targets, node.trace[i]); | ||
} | ||
for (i in res.matchedCSSRules) { | ||
for (i in node.events) { | ||
var trace = node.events[i]; | ||
if (trace.children.length > 0) { | ||
_makeJSTarget(targets, trace.children[0].callFrames[0]); | ||
} | ||
} | ||
for (i in res.matchedCSSRules.reverse()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line reverses the order of CSS rules in the browser menu, which represents the natural order of CSS rules from most to least precise. |
||
_makeCSSTarget(targets, res.matchedCSSRules[i]); | ||
} | ||
RemoteAgent.call("showGoto", targets); | ||
|
@@ -158,7 +164,7 @@ define(function GotoAgent(require, exports, module) { | |
console.assert(url.substr(0, 7) === "file://", "Cannot open non-file URLs"); | ||
|
||
var result = new $.Deferred(); | ||
|
||
url = _urlWithoutQueryString(url); | ||
// Extract the path, also strip the third slash when on Windows | ||
var path = url.slice(brackets.platform === "win" ? 8 : 7); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,9 @@ define(function HTMLDocumentModule(require, exports, module) { | |
* @param Document the source document from Brackets | ||
*/ | ||
var HTMLDocument = function HTMLDocument(doc, editor) { | ||
if (!editor) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes a crash caused by the editor not being set |
||
return; | ||
} | ||
this.doc = doc; | ||
this.editor = editor; | ||
this.onHighlight = this.onHighlight.bind(this); | ||
|
@@ -66,6 +69,9 @@ define(function HTMLDocumentModule(require, exports, module) { | |
|
||
/** Close the document */ | ||
HTMLDocument.prototype.close = function close() { | ||
if (!this.editor) { | ||
return; | ||
} | ||
$(HighlightAgent).off("highlight", this.onHighlight); | ||
$(this.editor).off("change", this.onChange); | ||
$(this.editor).off("cursorActivity", this.onCursorActivity); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,9 +54,11 @@ define(function JSDocumentModule(require, exports, module) { | |
* @param {Document} the source document | ||
*/ | ||
var JSDocument = function JSDocument(doc, editor) { | ||
if (!editor) { | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the script ID can change if the page is reloaded, we must not store it in the document. Instead, we resolve it as needed using the function defined below. |
||
this.doc = doc; | ||
this.editor = editor; | ||
this.script = ScriptAgent.scriptForURL(this.doc.url); | ||
this.onHighlight = this.onHighlight.bind(this); | ||
this.onChange = this.onChange.bind(this); | ||
this.onCursorActivity = this.onCursorActivity.bind(this); | ||
|
@@ -68,12 +70,19 @@ define(function JSDocumentModule(require, exports, module) { | |
|
||
/** Close the document */ | ||
JSDocument.prototype.close = function close() { | ||
if (!this.editor) { | ||
return; | ||
} | ||
$(HighlightAgent).off("highlight", this.onHighlight); | ||
$(this.editor).off("change", this.onChange); | ||
$(this.editor).off("cursorActivity", this.onCursorActivity); | ||
this.onHighlight(); | ||
}; | ||
|
||
JSDocument.prototype.script = function script() { | ||
return ScriptAgent.scriptForURL(this.doc.url); | ||
}; | ||
|
||
|
||
/** Event Handlers *******************************************************/ | ||
|
||
|
@@ -84,7 +93,7 @@ define(function JSDocumentModule(require, exports, module) { | |
/** Triggered on change by the editor */ | ||
JSDocument.prototype.onChange = function onChange(event, editor, change) { | ||
var src = this.doc.getText(); | ||
Inspector.Debugger.setScriptSource(this.script.scriptId, src, function onSetScriptSource(res) { | ||
Inspector.Debugger.setScriptSource(this.script().scriptId, src, function onSetScriptSource(res) { | ||
Inspector.Runtime.evaluate("if($)$(\"canvas\").each(function(i,e){if(e.rerender)e.rerender()})"); | ||
}.bind(this)); | ||
}; | ||
|
@@ -103,10 +112,11 @@ define(function JSDocumentModule(require, exports, module) { | |
} | ||
|
||
// go through the trace and find highlight the lines of this script | ||
var scriptId = this.script().scriptId; | ||
var callFrame, line; | ||
for (i in node.trace) { | ||
callFrame = node.trace[i]; | ||
if (callFrame.location && callFrame.location.scriptId === this.script.scriptId) { | ||
if (callFrame.location && callFrame.location.scriptId === scriptId) { | ||
line = callFrame.location.lineNumber; | ||
codeMirror.setLineClass(line, "highlight"); | ||
this._highlight.push(line); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,18 +151,14 @@ define(function LiveDevelopment(require, exports, module) { | |
switch (doc.extension) { | ||
case "css": | ||
return CSSDocument; | ||
/* FUTURE: | ||
case "js": | ||
return JSDocument; | ||
return exports.config.experimental ? JSDocument : null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JSDocument & HTMLDocument are only returned if the experimental flag is set. |
||
case "html": | ||
case "htm": | ||
return HTMLDocument; | ||
return exports.config.experimental ? HTMLDocument : null; | ||
default: | ||
throw "Invalid document type: " + doc.extension; | ||
*/ | ||
return null; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
|
@@ -251,8 +247,16 @@ define(function LiveDevelopment(require, exports, module) { | |
/** Load the agents */ | ||
function loadAgents() { | ||
var name, promises = []; | ||
for (name in _enabledAgentNames) { | ||
if (_enabledAgentNames.hasOwnProperty(name) && agents[name].load) { | ||
var agentsToLoad; | ||
if (exports.config.experimental) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the experimental flag is set, _enabledAgentNames is replaced by agents, which in effect loads all agents. |
||
// load all agents | ||
agentsToLoad = agents; | ||
} else { | ||
// load only enabled agents | ||
agentsToLoad = _enabledAgentNames; | ||
} | ||
for (name in agentsToLoad) { | ||
if (agentsToLoad.hasOwnProperty(name) && agents[name] && agents[name].load) { | ||
promises.push(agents[name].load()); | ||
_loadedAgentNames.push(name); | ||
} | ||
|
@@ -294,6 +298,11 @@ define(function LiveDevelopment(require, exports, module) { | |
function _onError(event, error) { | ||
var message = error.message; | ||
|
||
// Remove "Uncaught" from the beginning to avoid the inspector popping up | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Console messages starting with "Uncaught" make Bracket's inspector pop up, which is very annoying. That is why we remove the undesirable "Uncaught" prefix here. |
||
if (message.substr(0, 8) === "Uncaught") { | ||
message = message.substr(9); | ||
} | ||
|
||
// Additional information, like exactly which parameter could not be processed. | ||
var data = error.data; | ||
if (Array.isArray(data)) { | ||
|
@@ -352,7 +361,8 @@ define(function LiveDevelopment(require, exports, module) { | |
// For Sprint 6, we only open live development connections for HTML files | ||
// FUTURE: Remove this test when we support opening connections for different | ||
// file types. | ||
if (!doc.extension || doc.extension.indexOf("htm") !== 0) { | ||
|
||
if (!exports.config.experimental && (!doc.extension || doc.extension.indexOf('htm') !== 0)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only complain about the file not being an HTM(L) file if experimental features are turned off. |
||
showWrongDocError(); | ||
return promise; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
|
||
|
||
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, forin: true, maxerr: 50, regexp: true */ | ||
/*global define, $, less, window, XMLHttpRequest */ | ||
/*global brackets, define, $, less, window, XMLHttpRequest */ | ||
|
||
/** | ||
* main integrates LiveDevelopment into Brackets | ||
|
@@ -40,12 +40,14 @@ define(function main(require, exports, module) { | |
|
||
var DocumentManager = require("document/DocumentManager"), | ||
Commands = require("command/Commands"), | ||
AppInit = require("utils/AppInit"), | ||
LiveDevelopment = require("LiveDevelopment/LiveDevelopment"), | ||
Inspector = require("LiveDevelopment/Inspector/Inspector"), | ||
CommandManager = require("command/CommandManager"), | ||
Strings = require("strings"); | ||
|
||
var config = { | ||
experimental: false, // enable experimental features | ||
debug: true, // enable debug output and helpers | ||
autoconnect: false, // go live automatically after startup? | ||
highlight: false, // enable highlighting? | ||
|
@@ -128,6 +130,9 @@ define(function main(require, exports, module) { | |
// See the comments at the top of LiveDevelopment.js for details on the | ||
// various status codes. | ||
_setLabel(_$btnGoLive, null, _statusStyle[status + 1], _statusTooltip[status + 1]); | ||
if (config.autoconnect) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line stores the autoconnect status in the session storage. |
||
window.sessionStorage.setItem("live.enabled", status === 3); | ||
} | ||
}); | ||
|
||
// Initialize tooltip for 'not connected' state | ||
|
@@ -170,6 +175,15 @@ define(function main(require, exports, module) { | |
if (config.debug) { | ||
_setupDebugHelpers(); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Autoconnect is triggered if it is enabled and the session storage (see above) is set. |
||
// trigger autoconnect | ||
if (config.autoconnect && window.sessionStorage.getItem("live.enabled") === "true") { | ||
AppInit.appReady(function () { | ||
if (DocumentManager.getCurrentDocument()) { | ||
_handleGoLiveCommand(); | ||
} | ||
}); | ||
} | ||
} | ||
window.setTimeout(init); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines add events stored in the node to the browser menu. These events are generated in the debugger-extension.
This has no effect if no events are set (the debugger extension is not loaded).