Skip to content

Commit d153816

Browse files
committed
- invalidate typings fix
- update gc timer
1 parent ba50c6e commit d153816

4 files changed

Lines changed: 11 additions & 23 deletions

File tree

src/server/project.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ namespace ts.server {
283283
return true;
284284
}
285285
let hasChanges = this.updateGraphWorker();
286-
const cachedTypings = this.projectService.typingsCache.getTypingsForProject(this);
286+
const cachedTypings = this.projectService.typingsCache.getTypingsForProject(this, hasChanges);
287287
if (this.setTypings(cachedTypings)) {
288288
hasChanges = this.updateGraphWorker() || hasChanges;
289289
}
@@ -312,7 +312,6 @@ namespace ts.server {
312312
// - newProgram is different from the old program and structure of the old program was not reused.
313313
if (!oldProgram || (this.program !== oldProgram && !oldProgram.structureIsReused)) {
314314
hasChanges = true;
315-
//this.projectService.typingsCache.invalidateCachedTypingsForProject(this);
316315
if (oldProgram) {
317316
for (const f of oldProgram.getSourceFiles()) {
318317
if (this.program.getSourceFileByPath(f.path)) {
@@ -405,27 +404,16 @@ namespace ts.server {
405404

406405
const added: string[] = [];
407406
const removed: string[] = [];
408-
let invalidateTypings = false;
409407
for (const id in currentFiles) {
410-
if (hasProperty(currentFiles, id) && !hasProperty(lastReportedFileNames, id)) {
408+
if (!hasProperty(lastReportedFileNames, id)) {
411409
added.push(id);
412-
if (this.typingFiles.indexOf(id) < 0) {
413-
invalidateTypings = true;
414-
break;
415-
}
416410
}
417411
}
418412
for (const id in lastReportedFileNames) {
419-
if (hasProperty(lastReportedFileNames, id) && !hasProperty(currentFiles, id)) {
413+
if (!hasProperty(currentFiles, id)) {
420414
removed.push(id);
421-
invalidateTypings = true;
422415
}
423416
}
424-
if (invalidateTypings) {
425-
this.projectService.typingsCache.invalidateCachedTypingsForProject(this);
426-
}
427-
this.lastReportedFileNames = currentFiles;
428-
429417
this.lastReportedFileNames = currentFiles;
430418
this.lastReportedVersion = this.projectStructureVersion;
431419
return { info, changes: { added, removed }, projectErrors: this.projectErrors };

src/server/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ namespace ts.server {
168168
: undefined;
169169

170170
this.projectService = new ProjectService(host, logger, cancellationToken, useSingleInferredProject, typingsInstaller, eventHandler);
171-
this.gcTimer = new GcTimer(host, /*delay*/ 15000, logger);
171+
this.gcTimer = new GcTimer(host, /*delay*/ 7000, logger);
172172
}
173173

174174
private handleEvent(event: ProjectServiceEvent) {

src/server/typingsCache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ namespace ts.server {
7676
constructor(private readonly installer: ITypingsInstaller) {
7777
}
7878

79-
getTypingsForProject(project: Project): TypingsArray {
79+
getTypingsForProject(project: Project, forceRefresh: boolean): TypingsArray {
8080
const typingOptions = project.getTypingOptions();
8181

8282
if (!typingOptions || !typingOptions.enableAutoDiscovery) {
8383
return <any>emptyArray;
8484
}
8585

8686
const entry = this.perProjectCache[project.getProjectName()];
87-
const result: TypingsArray = entry && entry.typings.length > 0 ? entry.typings : toTypingsArray(typingOptions.include);
88-
if (!entry || typingOptionsChanged(typingOptions, entry.typingOptions) || compilerOptionsChanged(project.getCompilerOptions(), entry.compilerOptions)) {
87+
const result: TypingsArray = entry ? entry.typings : <any>emptyArray;
88+
if (forceRefresh || !entry || typingOptionsChanged(typingOptions, entry.typingOptions) || compilerOptionsChanged(project.getCompilerOptions(), entry.compilerOptions)) {
8989
// Note: entry is now poisoned since it does not really contain typings for a given combination of compiler options\typings options.
9090
// instead it acts as a placeholder to prevent issuing multiple requests
9191
this.perProjectCache[project.getProjectName()] = {

src/server/typingsInstaller/nodeTypingsInstaller.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace ts.server.typingsInstaller {
9292
protected runInstall(cachePath: string, typingsToInstall: string[], postInstallAction: (installedTypings: string[]) => void): void {
9393
const id = this.installRunCount;
9494
this.installRunCount++;
95-
let installCount = 0;
95+
let execInstallCmdCount = 0;
9696
const installedTypings: string[] = [];
9797
const expr = /^.*(@types\/\w+)\S*\s*$/gm;
9898
let match: RegExpExecArray;
@@ -102,15 +102,15 @@ namespace ts.server.typingsInstaller {
102102
this.log.writeLine(`Running npm install @types ${id}, command '${command}'. cache path '${cachePath}'`);
103103
}
104104
this.exec(command, { cwd: cachePath }, (err, stdout, stderr) => {
105-
installCount++;
105+
execInstallCmdCount++;
106106
if (this.log.isEnabled()) {
107107
this.log.writeLine(`npm install @types ${id} stdout: ${stdout}`);
108108
this.log.writeLine(`npm install @types ${id} stderr: ${stderr}`);
109109
}
110110
while (match = expr.exec(stdout)) {
111111
installedTypings.push(`node_modules/${match[1]}`);
112112
}
113-
if (installCount >= typingsToInstall.length) {
113+
if (execInstallCmdCount >= typingsToInstall.length) {
114114
postInstallAction(installedTypings);
115115
}
116116
});
@@ -121,7 +121,7 @@ namespace ts.server.typingsInstaller {
121121
function findArgument(argumentName: string) {
122122
const index = sys.args.indexOf(argumentName);
123123
return index >= 0 && index < sys.args.length - 1
124-
? sys.args[index]
124+
? sys.args[index + 1]
125125
: undefined;
126126
}
127127

0 commit comments

Comments
 (0)