From d15381682b40ec9f9f6aaddb3d159e9eed629ed9 Mon Sep 17 00:00:00 2001 From: Jason Ramsay Date: Tue, 30 Aug 2016 15:51:43 -0700 Subject: [PATCH] - invalidate typings fix - update gc timer --- src/server/project.ts | 18 +++--------------- src/server/session.ts | 2 +- src/server/typingsCache.ts | 6 +++--- .../typingsInstaller/nodeTypingsInstaller.ts | 8 ++++---- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/server/project.ts b/src/server/project.ts index baf759c75ce..448b956e440 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -283,7 +283,7 @@ namespace ts.server { return true; } let hasChanges = this.updateGraphWorker(); - const cachedTypings = this.projectService.typingsCache.getTypingsForProject(this); + const cachedTypings = this.projectService.typingsCache.getTypingsForProject(this, hasChanges); if (this.setTypings(cachedTypings)) { hasChanges = this.updateGraphWorker() || hasChanges; } @@ -312,7 +312,6 @@ namespace ts.server { // - newProgram is different from the old program and structure of the old program was not reused. if (!oldProgram || (this.program !== oldProgram && !oldProgram.structureIsReused)) { hasChanges = true; - //this.projectService.typingsCache.invalidateCachedTypingsForProject(this); if (oldProgram) { for (const f of oldProgram.getSourceFiles()) { if (this.program.getSourceFileByPath(f.path)) { @@ -405,27 +404,16 @@ namespace ts.server { const added: string[] = []; const removed: string[] = []; - let invalidateTypings = false; for (const id in currentFiles) { - if (hasProperty(currentFiles, id) && !hasProperty(lastReportedFileNames, id)) { + if (!hasProperty(lastReportedFileNames, id)) { added.push(id); - if (this.typingFiles.indexOf(id) < 0) { - invalidateTypings = true; - break; - } } } for (const id in lastReportedFileNames) { - if (hasProperty(lastReportedFileNames, id) && !hasProperty(currentFiles, id)) { + if (!hasProperty(currentFiles, id)) { removed.push(id); - invalidateTypings = true; } } - if (invalidateTypings) { - this.projectService.typingsCache.invalidateCachedTypingsForProject(this); - } - this.lastReportedFileNames = currentFiles; - this.lastReportedFileNames = currentFiles; this.lastReportedVersion = this.projectStructureVersion; return { info, changes: { added, removed }, projectErrors: this.projectErrors }; diff --git a/src/server/session.ts b/src/server/session.ts index 3da87f40631..2ab51b21985 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -168,7 +168,7 @@ namespace ts.server { : undefined; this.projectService = new ProjectService(host, logger, cancellationToken, useSingleInferredProject, typingsInstaller, eventHandler); - this.gcTimer = new GcTimer(host, /*delay*/ 15000, logger); + this.gcTimer = new GcTimer(host, /*delay*/ 7000, logger); } private handleEvent(event: ProjectServiceEvent) { diff --git a/src/server/typingsCache.ts b/src/server/typingsCache.ts index fd5b3149511..889cfe1fb8f 100644 --- a/src/server/typingsCache.ts +++ b/src/server/typingsCache.ts @@ -76,7 +76,7 @@ namespace ts.server { constructor(private readonly installer: ITypingsInstaller) { } - getTypingsForProject(project: Project): TypingsArray { + getTypingsForProject(project: Project, forceRefresh: boolean): TypingsArray { const typingOptions = project.getTypingOptions(); if (!typingOptions || !typingOptions.enableAutoDiscovery) { @@ -84,8 +84,8 @@ namespace ts.server { } const entry = this.perProjectCache[project.getProjectName()]; - const result: TypingsArray = entry && entry.typings.length > 0 ? entry.typings : toTypingsArray(typingOptions.include); - if (!entry || typingOptionsChanged(typingOptions, entry.typingOptions) || compilerOptionsChanged(project.getCompilerOptions(), entry.compilerOptions)) { + const result: TypingsArray = entry ? entry.typings : emptyArray; + if (forceRefresh || !entry || typingOptionsChanged(typingOptions, entry.typingOptions) || compilerOptionsChanged(project.getCompilerOptions(), entry.compilerOptions)) { // Note: entry is now poisoned since it does not really contain typings for a given combination of compiler options\typings options. // instead it acts as a placeholder to prevent issuing multiple requests this.perProjectCache[project.getProjectName()] = { diff --git a/src/server/typingsInstaller/nodeTypingsInstaller.ts b/src/server/typingsInstaller/nodeTypingsInstaller.ts index 6931b647a82..278d8d63026 100644 --- a/src/server/typingsInstaller/nodeTypingsInstaller.ts +++ b/src/server/typingsInstaller/nodeTypingsInstaller.ts @@ -92,7 +92,7 @@ namespace ts.server.typingsInstaller { protected runInstall(cachePath: string, typingsToInstall: string[], postInstallAction: (installedTypings: string[]) => void): void { const id = this.installRunCount; this.installRunCount++; - let installCount = 0; + let execInstallCmdCount = 0; const installedTypings: string[] = []; const expr = /^.*(@types\/\w+)\S*\s*$/gm; let match: RegExpExecArray; @@ -102,7 +102,7 @@ namespace ts.server.typingsInstaller { this.log.writeLine(`Running npm install @types ${id}, command '${command}'. cache path '${cachePath}'`); } this.exec(command, { cwd: cachePath }, (err, stdout, stderr) => { - installCount++; + execInstallCmdCount++; if (this.log.isEnabled()) { this.log.writeLine(`npm install @types ${id} stdout: ${stdout}`); this.log.writeLine(`npm install @types ${id} stderr: ${stderr}`); @@ -110,7 +110,7 @@ namespace ts.server.typingsInstaller { while (match = expr.exec(stdout)) { installedTypings.push(`node_modules/${match[1]}`); } - if (installCount >= typingsToInstall.length) { + if (execInstallCmdCount >= typingsToInstall.length) { postInstallAction(installedTypings); } }); @@ -121,7 +121,7 @@ namespace ts.server.typingsInstaller { function findArgument(argumentName: string) { const index = sys.args.indexOf(argumentName); return index >= 0 && index < sys.args.length - 1 - ? sys.args[index] + ? sys.args[index + 1] : undefined; }