Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Live development #1418

Merged
merged 30 commits into from
Aug 28, 2012
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f5e0f88
Enabled the remaining agents
jdiehl Jul 26, 2012
45c7602
re-enabled live-development
jdiehl Jul 26, 2012
6d8f543
do not cache the script as it changes when the browser reloads
jdiehl Jul 26, 2012
acda640
Merge pull request #1286 from jdiehl/live-development
joelrbrandt Jul 26, 2012
818a175
fix jslint error
joelrbrandt Jul 26, 2012
909bf81
Merge branch 'master-up' into live-development
jdiehl Jul 27, 2012
cfef069
wait for the proper event to auto connect live
jdiehl Jul 27, 2012
1671a25
Made GotoAgent focus the editor
DennisKehrig Jul 27, 2012
4a49d9f
Merge pull request #2 from DennisKehrig/live-development
jdiehl Jul 27, 2012
8454fdc
Merge remote-tracking branch 'jdiehl/live-development' into live-deve…
joelrbrandt Jul 27, 2012
c2eab82
fix one jslint error, and re-fix one earlier jslint fix better
joelrbrandt Jul 27, 2012
0322966
Made GotoAgent.open return a deferred
DennisKehrig Jul 28, 2012
feed872
Made GotoAgent's flash optional (allows to use a different line class…
DennisKehrig Jul 28, 2012
c971dce
Merge pull request #3 from DennisKehrig/live-development
jdiehl Jul 28, 2012
6b7c951
Merge branch 'master-up' into live-development
jdiehl Jul 31, 2012
009928e
updated to latest Inspector.json
jdiehl Jul 31, 2012
afb1398
updated documentation
jdiehl Jul 31, 2012
08c903d
Merge branch 'live-development' of https://github.com/jdiehl/brackets…
jdiehl Aug 3, 2012
0d045ec
jslint cleanup
joelrbrandt Aug 19, 2012
2d750f6
Merge branch 'master-up' into live-development
jdiehl Aug 22, 2012
8f36b0c
simplified the changes
jdiehl Aug 22, 2012
32b2c30
Remove "Uncaught" from error messages
jdiehl Aug 22, 2012
bbeead1
made auto connect & experimental features optional
jdiehl Aug 22, 2012
4c10e24
add node events
jdiehl Aug 3, 2012
efe6806
Merge branch 'live-development' of https://github.com/jdiehl/brackets…
jdiehl Aug 22, 2012
7ec6bed
removed trailing spaces
jdiehl Aug 22, 2012
b4e5ffc
Merge branch 'master-up' into live-development
jdiehl Aug 28, 2012
1067c9e
made all agent loading more secure
jdiehl Aug 28, 2012
e986c0d
switched to AppInit.appReady
jdiehl Aug 28, 2012
b5fb39f
disabled the experimental features
jdiehl Aug 28, 2012
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
10 changes: 8 additions & 2 deletions src/LiveDevelopment/Agents/GotoAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,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) {
Copy link
Contributor Author

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).

var trace = node.events[i];
if (trace.children.length > 0) {
_makeJSTarget(targets, trace.children[0].callFrames[0]);
}
}
for (i in res.matchedCSSRules.reverse()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
Expand Down Expand Up @@ -156,7 +162,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);
Expand Down
6 changes: 6 additions & 0 deletions src/LiveDevelopment/Documents/HTMLDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
Expand All @@ -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);
Expand Down
16 changes: 13 additions & 3 deletions src/LiveDevelopment/Documents/JSDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ define(function JSDocumentModule(require, exports, module) {
* @param {Document} the source document
*/
var JSDocument = function JSDocument(doc, editor) {
if (!editor) {
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
Expand All @@ -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 *******************************************************/

Expand All @@ -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));
};
Expand All @@ -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);
Expand Down
22 changes: 14 additions & 8 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}

/**
Expand Down Expand Up @@ -249,6 +245,10 @@ define(function LiveDevelopment(require, exports, module) {
/** Load the agents */
function loadAgents() {
var name, promises = [];
if (exports.config.experimental) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
This might have side-effects if, in the future, _enabledAgentNames is used somewhere else.

// load all agents
_enabledAgentNames = agents;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will lead to unexpected behavior. _enabledAgentNames becomes an alias for agents, so any time enableAgent() or disableAgent() is called, it will be changing the agents objects in addition to the _enabledAgentNames object. It would be better to iterate through the agents object and make sure all entries in the agents object have a corresponding entry in _enabledAgentNames.

}
for (name in _enabledAgentNames) {
if (_enabledAgentNames.hasOwnProperty(name) && agents[name].load) {
promises.push(agents[name].load());
Expand Down Expand Up @@ -292,6 +292,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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)) {
Expand Down Expand Up @@ -350,7 +355,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)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}
Expand Down
15 changes: 14 additions & 1 deletion src/LiveDevelopment/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,6 +46,7 @@ define(function main(require, exports, module) {
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?
Expand Down Expand Up @@ -128,6 +129,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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -170,6 +174,15 @@ define(function main(require, exports, module) {
if (config.debug) {
_setupDebugHelpers();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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") {
brackets.ready(function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brackets.ready() has been replaced with AppInit.appReady(). See #1425 (remove brackets.ready()) and #1464 (final naming) for details.

if (DocumentManager.getCurrentDocument()) {
_handleGoLiveCommand();
}
});
}
}
window.setTimeout(init);

Expand Down