Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rework file requesting protocol

  • Loading branch information...
commit fda671dec2b2ae6ea64a4c0c853e7262735af929 1 parent d1ce34c
@lennartcl lennartcl authored
View
1  plugins-client/ext.codecomplete/snippets/javascript.json
@@ -5,6 +5,7 @@
"if": "if (^^) {\n \n}",
"while": "while (^^) {\n \n}",
"switch": "switch (^^) {\n default:\n}",
+ "try": "try {\n ^^\n} catch (e) {\n throw e; // TODO\n}",
"fora": "for (var i = 0; i < ^^.length; i++) {\n \n}",
"log": "console.log(^^);",
"setTimeout": "setTimeout(function() {\n ^^\n}, 0);"
View
14 plugins-client/ext.language/base_handler.js
@@ -98,16 +98,24 @@ module.exports = {
},
/**
- * Invoked when a file in the project has been added, removed, or changed.
+ * Invoked when files in the project have been added, removed, or changed.
*
- * @param the affected files; a list of objects with a path and eventType property
- * @param eventType a string describing the type of event, if available
+ * @param files the affected files; a list of objects with a path and eventType property
+ * @param callback a callback that expects a list of files to retrieve and submit to onRequestedFileUpdate()
*/
onFileUpdates: function(files, callback) {
callback();
},
/**
+ * Invoked when a requested file has been loaded for analysis,
+ * using worker.requestFileUpdate() or onFileUpdates().
+ */
+ onRequestedFileUpdate: function(path, contents, callback) {
+ callback();
+ },
+
+ /**
* Invoked when the cursor has been moved inside to a different AST node
* @param doc the Document object repersenting the source
* @param fullAst the entire AST of the current file (if exists)
View
8 plugins-client/ext.language/project.js
@@ -7,6 +7,7 @@
var ide = require("core/ide");
var filelist = require("ext/filelist/filelist");
+var filesystem = require("ext/filesystem/filesystem");
define(function(require, exports, module) {
@@ -34,6 +35,13 @@ define(function(require, exports, module) {
ide.addEventListener("beforewatcherchange", function(){
_self.dirty = true;
});
+
+ worker.on("requestFileUpdate", function(event) {
+ // TODO: throttle read file requests?
+ filesystem.readFile(event.data.path, function(contents, response) {
+ worker.emit("onRequestedFileUpdate", { path: event.data.path, contents: contents });
+ });
+ });
};
var initTree = module.exports.initTree = function() {
View
25 plugins-client/ext.language/worker.js
@@ -131,6 +131,9 @@ var LanguageWorker = exports.LanguageWorker = function(sender) {
sender.on("onFileUpdates", function(event) {
_self.onFileUpdates(event);
});
+ sender.on("onRequestedFileUpdate", function(event) {
+ _self.onRequestedFileUpdate(event);
+ });
sender.on("serverProxy", function(event) {
_self.serverProxy.onMessage(event.data);
});
@@ -679,16 +682,34 @@ function asyncParForEach(array, fn, callback) {
};
this.onFileUpdates = function(event) {
- this.scheduledUpdate = false;
var _self = this;
asyncForEach(this.handlers, function(handler, next) {
if (handler.onFileUpdates)
- handler.onFileUpdates(event.data.paths, next);
+ handler.onFileUpdates(event.data.paths, function(toUpdate) {
+ if (!toUpdate)
+ next();
+ for (var i = 0; i < toUpdate.length; i++)
+ _self.requestFileUpdate(toUpdate[i]);
+ next();
+ });
else
next();
});
};
+ this.onRequestedFileUpdate = function(event) {
+ asyncForEach(this.handlers, function(handler, next) {
+ if (handler.onRequestedFileUpdate)
+ handler.onRequestedFileUpdate(event.data.path, event.data.contents, next);
+ else
+ next();
+ });
+ };
+
+ this.requestFileUpdate = function(path) {
+ this.sender.emit("requestFileUpdate", { path: path });
+ };
+
// TODO: BUG open an XML file and switch between, language doesn't update soon enough
this.switchFile = function(path, language, code, project) {
var _self = this;
Please sign in to comment.
Something went wrong with that request. Please try again.