ensure tsd cache directory exists

This commit is contained in:
Vladimir Matveev 2016-08-12 23:04:17 -07:00
parent 512ec04d29
commit d07261af4f
5 changed files with 18 additions and 21 deletions

View file

@ -77,7 +77,7 @@ namespace ts.server {
}); });
function compress(s: string): CompressedData { 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" }; return { data, length: data.length, compressionKind: "gzip" };
} }
@ -167,7 +167,7 @@ namespace ts.server {
constructor(private readonly logger: server.Logger) { constructor(private readonly logger: server.Logger) {
switch (process.platform) { switch (process.platform) {
case "win32": 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; break;
case "darwin": case "darwin":
case "linux": case "linux":
@ -177,6 +177,7 @@ namespace ts.server {
} }
bind(session: Session) { bind(session: Session) {
this.session = session;
if (this.logger.hasLevel(LogLevel.requestTime)) { if (this.logger.hasLevel(LogLevel.requestTime)) {
this.logger.info("Binding...") this.logger.info("Binding...")
} }
@ -202,15 +203,11 @@ namespace ts.server {
this.installer.send(request); this.installer.send(request);
} }
C = 1;
private handleMessage(response: InstallTypingsResponse) { private handleMessage(response: InstallTypingsResponse) {
if (this.logger.hasLevel(LogLevel.verbose)) { if (this.logger.hasLevel(LogLevel.verbose)) {
this.logger.info(`Received response: ${JSON.stringify(response)}`) 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); 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; 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 // This places log file in the directory containing editorServices.js
// TODO: check that this location is writable // TODO: check that this location is writable
@ -448,7 +445,7 @@ namespace ts.server {
const useSingleInferredProject = sys.args.some(arg => arg === "--useSingleInferredProject"); const useSingleInferredProject = sys.args.some(arg => arg === "--useSingleInferredProject");
const ioSession = new IOSession(sys, cancellationToken, useSingleInferredProject, logger); const ioSession = new IOSession(sys, cancellationToken, useSingleInferredProject, logger);
process.on("uncaughtException", function(err: Error) { process.on("uncaughtException", function (err: Error) {
ioSession.logError(err, "unknown"); ioSession.logError(err, "unknown");
}); });
// Start listening // Start listening

View file

@ -1459,6 +1459,7 @@ namespace ts.server {
} }
this.projectService.typingsCache.updateTypingsForProject(response.projectName, response.compilerOptions, response.typingOptions, response.typings); this.projectService.typingsCache.updateTypingsForProject(response.projectName, response.compilerOptions, response.typingOptions, response.typings);
project.updateGraph(); project.updateGraph();
} }
public onMessage(message: string) { public onMessage(message: string) {

View file

@ -33,5 +33,6 @@ declare namespace ts.server {
export interface InstallTypingHost extends JsTyping.TypingResolutionHost { export interface InstallTypingHost extends JsTyping.TypingResolutionHost {
writeFile(path: string, content: string): void; writeFile(path: string, content: string): void;
createDirectory(path: string): void;
} }
} }

View file

@ -42,12 +42,7 @@ namespace ts.server.typingsInstaller {
return sys; return sys;
} }
C = 1;
protected sendResponse(response: InstallTypingsResponse) { protected sendResponse(response: InstallTypingsResponse) {
(<any>response).___id = [this.C];
this.C++;
log("sendResponse::" + JSON.stringify(response));
process.send(response); process.send(response);
} }

View file

@ -2,9 +2,6 @@
/// <reference path="../types.d.ts"/> /// <reference path="../types.d.ts"/>
namespace ts.server.typingsInstaller { namespace ts.server.typingsInstaller {
export function log(s: string) {
require("fs").appendFileSync("E:\\sources\\git\\installer.txt", s + "\r\n");
}
const DefaultTsdSettings = JSON.stringify({ const DefaultTsdSettings = JSON.stringify({
version: "v4", version: "v4",
repo: "DefinitelyTyped/DefinitelyTyped", repo: "DefinitelyTyped/DefinitelyTyped",
@ -22,7 +19,6 @@ namespace ts.server.typingsInstaller {
if (!this.isTsdInstalled) { if (!this.isTsdInstalled) {
this.isTsdInstalled = this.installPackage("tsd"); this.isTsdInstalled = this.installPackage("tsd");
} }
log(`start ${this.isTsdInstalled}`);
} }
install(req: InstallTypingsRequest) { install(req: InstallTypingsRequest) {
@ -30,7 +26,6 @@ namespace ts.server.typingsInstaller {
return; return;
} }
log(`install ${JSON.stringify(req)}`);
const discoverTypingsResult = JsTyping.discoverTypings( const discoverTypingsResult = JsTyping.discoverTypings(
this.getInstallTypingHost(), this.getInstallTypingHost(),
req.fileNames, req.fileNames,
@ -40,7 +35,6 @@ namespace ts.server.typingsInstaller {
req.typingOptions, req.typingOptions,
req.compilerOptions); req.compilerOptions);
log(`install ${JSON.stringify(discoverTypingsResult)}`);
// respond with whatever cached typings we have now // respond with whatever cached typings we have now
this.sendResponse(this.createResponse(req, discoverTypingsResult.cachedTypingPaths)); this.sendResponse(this.createResponse(req, discoverTypingsResult.cachedTypingPaths));
// start watching files // start watching files
@ -51,7 +45,6 @@ namespace ts.server.typingsInstaller {
private installTypings(req: InstallTypingsRequest, currentlyCachedTypings: string[], typingsToInstall: string[]) { private installTypings(req: InstallTypingsRequest, currentlyCachedTypings: string[], typingsToInstall: string[]) {
typingsToInstall = filter(typingsToInstall, x => !hasProperty(this.missingTypings, x)); typingsToInstall = filter(typingsToInstall, x => !hasProperty(this.missingTypings, x));
log(`install ${JSON.stringify(typingsToInstall)}`);
if (typingsToInstall.length === 0) { if (typingsToInstall.length === 0) {
return; return;
} }
@ -60,6 +53,7 @@ namespace ts.server.typingsInstaller {
const host = this.getInstallTypingHost(); const host = this.getInstallTypingHost();
const tsdPath = combinePaths(req.cachePath, "tsd.json"); const tsdPath = combinePaths(req.cachePath, "tsd.json");
if (!host.fileExists(tsdPath)) { if (!host.fileExists(tsdPath)) {
this.ensureDirectoryExists(req.cachePath, host);
host.writeFile(tsdPath, DefaultTsdSettings); host.writeFile(tsdPath, DefaultTsdSettings);
} }
@ -67,11 +61,20 @@ namespace ts.server.typingsInstaller {
// TODO: record new missing package names // TODO: record new missing package names
// TODO: watch project directory // TODO: watch project directory
installedTypings = installedTypings.map(x => getNormalizedAbsolutePath(x, req.cachePath)); installedTypings = installedTypings.map(x => getNormalizedAbsolutePath(x, req.cachePath));
log(`include ${JSON.stringify(installedTypings)}`);
this.sendResponse(this.createResponse(req, currentlyCachedTypings.concat(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[]) { private watchFiles(files: string[]) {
// TODO: start watching files // TODO: start watching files
} }