diff --git a/src/server/server.ts b/src/server/server.ts index 020b2d3a34..fa26de2e07 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -77,7 +77,7 @@ namespace ts.server { }); function compress(s: string): CompressedData { - const data = zlib.gzipSync(new Buffer(s, "utf8")); + const data = zlib.gzipSync(new Buffer(s, "utf8")); return { data, length: data.length, compressionKind: "gzip" }; } @@ -167,7 +167,7 @@ namespace ts.server { constructor(private readonly logger: server.Logger) { switch (process.platform) { case "win32": - this.cachePath = normalizeSlashes(combinePaths(process.env.LOCALAPPDATA || process.env.APPDATA, "Microsoft/TypeScript")); + this.cachePath = normalizeSlashes(combinePaths(process.env.LOCALAPPDATA || process.env.APPDATA, "Microsoft/TypeScript")); break; case "darwin": case "linux": @@ -177,6 +177,7 @@ namespace ts.server { } bind(session: Session) { + this.session = session; if (this.logger.hasLevel(LogLevel.requestTime)) { this.logger.info("Binding...") } @@ -202,15 +203,11 @@ namespace ts.server { this.installer.send(request); } - C = 1; private handleMessage(response: InstallTypingsResponse) { if (this.logger.hasLevel(LogLevel.verbose)) { this.logger.info(`Received response: ${JSON.stringify(response)}`) } - require("fs").appendFileSync("E:\\sources\\git\\tss.txt", this.C + " !!!::" + JSON.stringify(response) + "\r\n"); - this.C++; this.session.onTypingsInstalled(response); - require("fs").appendFileSync("E:\\sources\\git\\tss.txt", this.C + " !!!::" + "done" + "\r\n"); } } @@ -293,7 +290,7 @@ namespace ts.server { } traceToConsole = logEnv.traceToConsole; } - return new Logger(fileName, traceToConsole, detailLevel); + return new Logger(fileName, traceToConsole, detailLevel); } // This places log file in the directory containing editorServices.js // TODO: check that this location is writable @@ -448,7 +445,7 @@ namespace ts.server { const useSingleInferredProject = sys.args.some(arg => arg === "--useSingleInferredProject"); const ioSession = new IOSession(sys, cancellationToken, useSingleInferredProject, logger); - process.on("uncaughtException", function(err: Error) { + process.on("uncaughtException", function (err: Error) { ioSession.logError(err, "unknown"); }); // Start listening diff --git a/src/server/session.ts b/src/server/session.ts index 4319f5031c..6c4deef2e7 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1459,6 +1459,7 @@ namespace ts.server { } this.projectService.typingsCache.updateTypingsForProject(response.projectName, response.compilerOptions, response.typingOptions, response.typings); project.updateGraph(); + } public onMessage(message: string) { diff --git a/src/server/types.d.ts b/src/server/types.d.ts index 252b52bbcf..503bba1f9d 100644 --- a/src/server/types.d.ts +++ b/src/server/types.d.ts @@ -33,5 +33,6 @@ declare namespace ts.server { export interface InstallTypingHost extends JsTyping.TypingResolutionHost { writeFile(path: string, content: string): void; + createDirectory(path: string): void; } } \ No newline at end of file diff --git a/src/server/typingsInstaller/nodeTypingsInstaller.ts b/src/server/typingsInstaller/nodeTypingsInstaller.ts index 32a7cfd680..fe1f372fa7 100644 --- a/src/server/typingsInstaller/nodeTypingsInstaller.ts +++ b/src/server/typingsInstaller/nodeTypingsInstaller.ts @@ -42,12 +42,7 @@ namespace ts.server.typingsInstaller { return sys; } - C = 1; - protected sendResponse(response: InstallTypingsResponse) { - (response).___id = [this.C]; - this.C++; - log("sendResponse::" + JSON.stringify(response)); process.send(response); } diff --git a/src/server/typingsInstaller/typingsInstaller.ts b/src/server/typingsInstaller/typingsInstaller.ts index 012053544e..cb9c5e0b23 100644 --- a/src/server/typingsInstaller/typingsInstaller.ts +++ b/src/server/typingsInstaller/typingsInstaller.ts @@ -2,9 +2,6 @@ /// namespace ts.server.typingsInstaller { - export function log(s: string) { - require("fs").appendFileSync("E:\\sources\\git\\installer.txt", s + "\r\n"); - } const DefaultTsdSettings = JSON.stringify({ version: "v4", repo: "DefinitelyTyped/DefinitelyTyped", @@ -22,7 +19,6 @@ namespace ts.server.typingsInstaller { if (!this.isTsdInstalled) { this.isTsdInstalled = this.installPackage("tsd"); } - log(`start ${this.isTsdInstalled}`); } install(req: InstallTypingsRequest) { @@ -30,7 +26,6 @@ namespace ts.server.typingsInstaller { return; } - log(`install ${JSON.stringify(req)}`); const discoverTypingsResult = JsTyping.discoverTypings( this.getInstallTypingHost(), req.fileNames, @@ -40,7 +35,6 @@ namespace ts.server.typingsInstaller { req.typingOptions, req.compilerOptions); - log(`install ${JSON.stringify(discoverTypingsResult)}`); // respond with whatever cached typings we have now this.sendResponse(this.createResponse(req, discoverTypingsResult.cachedTypingPaths)); // start watching files @@ -51,7 +45,6 @@ namespace ts.server.typingsInstaller { private installTypings(req: InstallTypingsRequest, currentlyCachedTypings: string[], typingsToInstall: string[]) { typingsToInstall = filter(typingsToInstall, x => !hasProperty(this.missingTypings, x)); - log(`install ${JSON.stringify(typingsToInstall)}`); if (typingsToInstall.length === 0) { return; } @@ -60,6 +53,7 @@ namespace ts.server.typingsInstaller { const host = this.getInstallTypingHost(); const tsdPath = combinePaths(req.cachePath, "tsd.json"); if (!host.fileExists(tsdPath)) { + this.ensureDirectoryExists(req.cachePath, host); host.writeFile(tsdPath, DefaultTsdSettings); } @@ -67,11 +61,20 @@ namespace ts.server.typingsInstaller { // TODO: record new missing package names // TODO: watch project directory installedTypings = installedTypings.map(x => getNormalizedAbsolutePath(x, req.cachePath)); - log(`include ${JSON.stringify(installedTypings)}`); this.sendResponse(this.createResponse(req, currentlyCachedTypings.concat(installedTypings))); }); } + private ensureDirectoryExists(directory: string, host: InstallTypingHost): void { + const directoryName = getDirectoryPath(directory); + if (!host.directoryExists(directoryName)) { + this.ensureDirectoryExists(directoryName, host); + } + if (!host.directoryExists(directory)) { + host.createDirectory(directory); + } + } + private watchFiles(files: string[]) { // TODO: start watching files }