Several bug fixes.

This commit is contained in:
2014-11-03 23:37:34 +01:00
parent 1414d634fd
commit b1ab5822a7
4 changed files with 91 additions and 36 deletions

View File

@@ -0,0 +1,6 @@
### KNOWN BUGS
* startAtomic behaves like startDocumentListen
* endAtomic does nothing (maybe because startAtomic don't works)
* unguard does nothing (but guard works)
* setExitDelay
* controler seems attached to the first socket, even if already ended

View File

@@ -13,23 +13,62 @@ server.createServer(3219, "127.0.0.1", function (password) {
console.log("Ready to serve"); console.log("Ready to serve");
process.stdin.on("data", function(data) { process.stdin.on("data", function(data) {
if (data.toString() !== "exit"){ var cmd = data.toString();
try { console.log("CMD "+cmd);
try
{
switch(cmd) {
case "exit\n" :
controler.detach();
process.exit();
break;
case "getCursor\n" :
controler.getCursor(function (buffer, lnum, col, pos) {
console.log("=> id:"+buffer+" l:"+lnum+" c:"+col+" off:"+pos);
});
break;
case "getLength\n" :
controler.getBuffer(1).getLength(function (length) {
console.log("=> length:"+length);
});
break;
case "getAnno\n" :
controler.getBuffer(1).getAnno(1, function(line){
console.log("=> line:"+line);
});
break;
case "getModified\n" :
controler.getModified(function (flag) {
console.log("=> modified:"+flag);
});
break;
case "getText\n" :
controler.getBuffer(1).getText(function (text){
console.log("=> "+text);
});
break;
case "insert\n" :
controler.getBuffer(1).insert(5, "Insert Test\nInsert Test",
function (error){
console.log("=> "+error);
});
break;
case "remove\n" :
controler.getBuffer(1).remove(2,4,function(error){
console.log("=> "+error);
});
break;
default :
console.log("CMD : "+data.toString()); console.log("CMD : "+data.toString());
console.log("RETURNED : "+eval(data.toString())); console.log("RETURNED : "+eval(data.toString()));
} break;
catch (ex) {
console.log("Erreur : "+ex.message)
} }
} }
else { catch (ex) {
console.log("Erreur : "+ex.message);
controler.detach();
} }
}); });
}); });

View File

@@ -59,10 +59,22 @@ function Buffer (client, buffId) {
}; };
//Tell Vim that the buffer is owned by the controler //Tell Vim that the buffer is owned by the controler
//Réception d'événéments si vrai
this.netbeansBuffer = function (isNetBeansBuffer) { this.netbeansBuffer = function (isNetBeansBuffer) {
client.sendCommand("netbeansBuffer", buffId, Types.bool(isNetBeansBuffer)); client.sendCommand("netbeansBuffer", buffId, Types.bool(isNetBeansBuffer));
}; };
//Start an atomic opperation. Vim screen is not updated untill endAtomic is called
//BUG : Interprété comme un startDocumentListen
this.startAtomic = function () {
client.sendCommand("startAtomic", buffId);
};
//End an atomic opperation.
//BUG : Ne fais rien du tout
this.endAtomic = function() {
client.sendCommand("endAtmoic", buffId );
};
//Remove and anno //Remove and anno
this.removeAnno = function (serNum) { this.removeAnno = function (serNum) {
client.sendCommand("removeAnno",buffId,serNum); client.sendCommand("removeAnno",buffId,serNum);
@@ -119,6 +131,7 @@ function Buffer (client, buffId) {
}; };
//Ungard the text. off is the starting position, len the length of the text //Ungard the text. off is the starting position, len the length of the text
//BUG : Doesn't works at all, text area keeps guard
this.unguard = function (off, len) { this.unguard = function (off, len) {
client.sendCommand("unguard", buffId, Types.position(off), len); client.sendCommand("unguard", buffId, Types.position(off), len);
}; };
@@ -128,23 +141,10 @@ function Buffer (client, buffId) {
client.sendCommand("editFile", buffId, Types.string(pathName)); client.sendCommand("editFile", buffId, Types.string(pathName));
}; };
//Start an atomic opperation. Vim screen is not updated untill endAtomic is called
this.startAtomic = function () {
client.sendCommand("startAtomic", buffId);
};
//End an atomic opperation.
this.endAtomic = function() {
client.sendCommand("endAtmoic", buffId);
};
/* FUNCTIONS */ /* FUNCTIONS */
//Get cursor position. Callback function get the line, column and offset
this.getCursor = function (callback) {
client.callFunction("getCursor", buffId, callback);
};
//Get the length of current buffer. //Get the length of current buffer.
this.getLength = function (callback) { this.getLength = function (callback) {

View File

@@ -114,7 +114,7 @@ function NetbeansClient(socket, authentication, onEvent, onError, onDisconnected
if (message[i] === "\\") { if (message[i] === "\\") {
i += 1; i += 1;
if (i < message.length) { if (i === message.length) {
throw "Unfinished string in message"; throw "Unfinished string in message";
} }
else { else {
@@ -155,11 +155,11 @@ function NetbeansClient(socket, authentication, onEvent, onError, onDisconnected
i += 1; i += 1;
} }
if (i - argStartOffset === 1 && (message[i] === "T" || message[i] === "F")) { if (i - argStartOffset === 1 && (message[i - 1] === "T" || message[i - 1] === "F")) {
args.push(message[i] === "T"); args.push(message[i - 1] === "T");
} }
else { else {
var argument = message.substr(argStartOffset, i); var argument = message.substring(argStartOffset, i);
if (Number.isNaN(argument)) { if (Number.isNaN(argument)) {
if (argument.contains("/")) { if (argument.contains("/")) {
@@ -170,10 +170,13 @@ function NetbeansClient(socket, authentication, onEvent, onError, onDisconnected
} }
} }
else { else {
console.log("ARG : "+argument);
args.push(parseInt(argument)); args.push(parseInt(argument));
} }
} }
} }
argStartOffset = ++i;
} }
if (isEvent) { if (isEvent) {
@@ -237,18 +240,20 @@ function NetbeansClient(socket, authentication, onEvent, onError, onDisconnected
var lastArg = arguments.length - 1; var lastArg = arguments.length - 1;
if (typeof(arguments[lastArg]) === "function") { if (typeof(arguments[lastArg]) === "function") {
Object.defineProperty(callbacks, currentSeqno, {value: arguments[lastArg]}); Object.defineProperty(callbacks, seqno, {value: arguments[lastArg], configurable: true});
lastArg -= 1; lastArg -= 1;
} }
var data = buffer + ":" + name + "/" + seqno; var data = buffer + ":" + name + "/" + seqno;
for (var i = 2 ; i < lastArg ; ++i) { for (var i = 2 ; i <= lastArg ; ++i) {
data += " " + arguments[i]; data += " " + arguments[i];
} }
data += "\n"; data += "\n";
console.log("CALL : "+data);
socket.write(data); socket.write(data);
}; };
@@ -303,10 +308,10 @@ function Controler(socket, authentication) {
var buffId = 0; var buffId = 0;
var buffers = {}; var buffers = {};
function getBuffer() { function newBuffer() {
buffId += 1; buffId += 1;
var buffer = new Buffer(client, buffId); var buffer = new Buffer(client, buffId);
Object.defineProperty(buffers, buffId, {value: buffer}); Object.defineProperty(buffers, buffId, {value: buffer, configurable: true});
return buffer; return buffer;
} }
@@ -330,7 +335,7 @@ function Controler(socket, authentication) {
//Create a new buffer. Return the buffer created //Create a new buffer. Return the buffer created
this.create = function() { this.create = function() {
var buffer = getBuffer(); var buffer = newBuffer();
client.sendCommand("create", buffId); client.sendCommand("create", buffId);
return buffer; return buffer;
}; };
@@ -338,7 +343,7 @@ function Controler(socket, authentication) {
//Associate already opened buffer on Vim to a controler owned buffer //Associate already opened buffer on Vim to a controler owned buffer
//Return the newly created buffer //Return the newly created buffer
this.putBufferNumber = function (pathname) { this.putBufferNumber = function (pathname) {
var buffer = getBuffer(); var buffer = newBuffer();
client.sendCommand("putBufferNumber", buffId, Types.string(pathname)); //TODO : May be better on the buffer client.sendCommand("putBufferNumber", buffId, Types.string(pathname)); //TODO : May be better on the buffer
return buffer; return buffer;
}; };
@@ -346,11 +351,12 @@ function Controler(socket, authentication) {
//Associate already opened buffer on Vim to a controler owned buffer and bring it to front //Associate already opened buffer on Vim to a controler owned buffer and bring it to front
//Return the newly created buffer //Return the newly created buffer
this.setBufferNumber = function (pathname) { this.setBufferNumber = function (pathname) {
var buffer = getBuffer(); var buffer = newBuffer();
client.sendCommand("setBufferNumber", buffId, Types.string(pathname)); client.sendCommand("setBufferNumber", buffId, Types.string(pathname));
return buffer; return buffer;
}; };
/* GLOBAL FUNCTIONS */ /* GLOBAL FUNCTIONS */
//Ask Vim to save and exit //Ask Vim to save and exit
@@ -363,6 +369,10 @@ function Controler(socket, authentication) {
client.callFunction("getModified", 0, callback); client.callFunction("getModified", 0, callback);
}; };
//Get cursor position. Callback function get the line, column and offset
this.getCursor = function (callback) {
client.callFunction("getCursor", 0, callback);
};
/* CONNTROLER CONTROL */ /* CONNTROLER CONTROL */