Always default to using JSON and do not format it

This commit is contained in:
Mohamed Hegazy
2015-02-14 15:50:06 -08:00
parent a0b557e1e2
commit dfd8a0620d
3 changed files with 7 additions and 56 deletions

View File

@@ -583,7 +583,7 @@ module Harness.LanguageService {
// This host is just a proxy for the clientHost, it uses the client
// host to answer server queries about files on disk
var serverHost = new SessionServerHost(clientHost);
var server = new ts.server.Session(serverHost, serverHost, /*useProtocol*/ true, /*prettyJSON*/ false);
var server = new ts.server.Session(serverHost, serverHost);
// Fake the connection between the client and the server
serverHost.writeMessage = client.onMessage.bind(client);

View File

@@ -157,7 +157,7 @@ module ts.server {
immediateId: any;
changeSeq = 0;
constructor(private host: ServerHost, private logger: Logger, protected useProtocol: boolean, protected prettyJSON: boolean) {
constructor(private host: ServerHost, private logger: Logger) {
this.projectService = new ProjectService(host, logger);
}
@@ -178,13 +178,7 @@ module ts.server {
}
send(msg: NodeJS._debugger.Message) {
var json: string;
if (this.prettyJSON) {
json = JSON.stringify(msg, null, " ");
}
else {
json = JSON.stringify(msg);
}
var json = JSON.stringify(msg);
this.sendLineToClient('Content-Length: ' + (1 + Buffer.byteLength(json, 'utf8')) +
'\r\n\r\n' + json);
}
@@ -229,32 +223,7 @@ module ts.server {
}
output(info: any, cmdName: string, reqSeq = 0, errorMsg?: string) {
if (this.useProtocol) {
this.response(info, cmdName, reqSeq, errorMsg);
}
else if (this.prettyJSON) {
if (!errorMsg) {
this.sendLineToClient(JSON.stringify(info, null, " ").trim());
}
else {
this.sendLineToClient(JSON.stringify(errorMsg));
}
} else {
if (!errorMsg) {
var infoStr = JSON.stringify(info).trim();
// [8 digits of length,infoStr] + '\n'
var len = infoStr.length + paddedLength + 4;
var lenStr = len.toString();
var padLen = paddedLength - lenStr.length;
for (var i = 0; i < padLen; i++) {
lenStr = '0' + lenStr;
}
this.sendLineToClient("[" + lenStr + "," + infoStr + "]");
}
else {
this.sendLineToClient(JSON.stringify("error: " + errorMsg));
}
}
this.response(info, cmdName, reqSeq, errorMsg);
}
semanticCheck(file: string, project: Project) {

View File

@@ -73,26 +73,8 @@ module ts.server {
}
class IOSession extends Session {
protocol: NodeJS._debugger.Protocol;
constructor(host: ServerHost, logger: ts.server.Logger, useProtocol: boolean, prettyJSON: boolean) {
super(host, logger, useProtocol, prettyJSON);
if (useProtocol) {
this.initProtocol();
}
}
initProtocol() {
this.protocol = new nodeproto.Protocol();
// note: onResponse was named by nodejs authors; we are re-purposing the Protocol
// class in this case so that it supports a server instead of a client
this.protocol.onResponse = (pkt) => {
this.handleRequest(pkt);
};
}
handleRequest(req: NodeJS._debugger.Packet) {
this.projectService.log("Got JSON msg:\n" + req.raw);
constructor(host: ServerHost, logger: ts.server.Logger) {
super(host, logger);
}
listen() {
@@ -114,5 +96,5 @@ module ts.server {
var logger = new Logger(__dirname + "/.log" + process.pid.toString());
// Start listening
new IOSession(ts.sys, logger, /* useProtocol */ true, /* prettyJSON */ false).listen();
new IOSession(ts.sys, logger).listen();
}