Skip to content

Commit 8c899a6

Browse files
committed
An elegant weapon for a more civilized age
1 parent 2dfcafe commit 8c899a6

4 files changed

Lines changed: 12 additions & 27 deletions

File tree

src/server/editorServices.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ namespace ts.server {
365365

366366
private onTypeRootFileChanged(project: ConfiguredProject, fileName: string) {
367367
this.logger.info(`Type root file ${fileName} changed`);
368-
this.throttledOperations.schedule(project.configFileName, /*delay*/ 250, () => {
368+
this.throttledOperations.schedule(project.configFileName + ' * type root', /*delay*/ 250, () => {
369+
project.updateTypes();
369370
this.updateConfiguredProject(project);
370371
this.refreshInferredProjects();
371372
});
@@ -391,20 +392,15 @@ namespace ts.server {
391392
() => this.handleChangeInSourceFileForConfiguredProject(project));
392393
}
393394

394-
getTypeRootsVersion(project: ConfiguredProject) {
395-
return server.getLatestDirectoryChangeTime(project.getEffectiveTypeRoots(), this.host);
396-
}
397-
398395
private handleChangeInSourceFileForConfiguredProject(project: ConfiguredProject) {
399396
const { projectOptions, configFileErrors } = this.convertConfigFileContentToProjectOptions(project.configFileName);
400397
this.reportConfigFileDiagnostics(project.getProjectName(), configFileErrors);
401398

402399
const newRootFiles = projectOptions.files.map((f => this.getCanonicalFileName(f)));
403400
const currentRootFiles = project.getRootFiles().map((f => this.getCanonicalFileName(f)));
404-
const lastUpdateTypesRoot: number = this.getTypeRootsVersion(project);
405401

406402
// We check if the project file list has changed. If so, we update the project.
407-
if (!arrayIsEqualTo(currentRootFiles.sort(), newRootFiles.sort()) || (lastUpdateTypesRoot > project.lastUpdatedTypesRootTime)) {
403+
if (!arrayIsEqualTo(currentRootFiles.sort(), newRootFiles.sort())) {
408404
// For configured projects, the change is made outside the tsconfig file, and
409405
// it is not likely to affect the project for other files opened by the client. We can
410406
// just update the current project.
@@ -415,8 +411,6 @@ namespace ts.server {
415411
// Call refreshInferredProjects to clean up inferred projects we may have
416412
// created for the new files
417413
this.refreshInferredProjects();
418-
419-
project.lastUpdatedTypesRootTime = lastUpdateTypesRoot;
420414
}
421415
}
422416

src/server/lsHost.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ namespace ts.server {
146146
}
147147

148148
getTypeRootsVersion() {
149-
const roots = ts.getEffectiveTypeRoots(this.project.getCompilerOptions(), this);
150-
return server.getLatestDirectoryChangeTime(roots, this.host);
149+
return this.project.typesVersion;
151150
}
152151

153152
getScriptKind(fileName: string) {

src/server/project.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ namespace ts.server {
6969

7070
protected projectErrors: Diagnostic[];
7171

72+
public typesVersion = 0;
73+
7274
public isJsOnlyProject() {
7375
this.updateGraph();
7476
return allFilesAreJsOrDts(this);
@@ -153,6 +155,12 @@ namespace ts.server {
153155
return this.program.getSourceFileByPath(path);
154156
}
155157

158+
updateTypes() {
159+
this.typesVersion++;
160+
this.markAsDirty();
161+
this.updateGraph();
162+
}
163+
156164
close() {
157165
if (this.program) {
158166
// if we have a program - release all files that are enlisted in program
@@ -573,7 +581,6 @@ namespace ts.server {
573581

574582
/** Used for configured projects which may have multiple open roots */
575583
openRefCount = 0;
576-
lastUpdatedTypesRootTime = 0;
577584

578585
constructor(readonly configFileName: NormalizedPath,
579586
projectService: ProjectService,

src/server/utilities.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,6 @@ namespace ts.server {
9090
};
9191
}
9292

93-
export function getLatestDirectoryChangeTime(paths: string[] | undefined, host: System) {
94-
if (!host.getModifiedTime || !host.directoryExists || !paths) {
95-
return 0;
96-
}
97-
98-
return Math.max(...paths.map(path => {
99-
if (host.directoryExists(path)) {
100-
return +host.getModifiedTime(path);
101-
}
102-
else {
103-
return 0;
104-
}
105-
}));
106-
}
107-
10893
export function mergeMaps(target: MapLike<any>, source: MapLike <any>): void {
10994
for (const key in source) {
11095
if (hasProperty(source, key)) {

0 commit comments

Comments
 (0)