Skip to content

Commit 9df8831

Browse files
authored
Merge pull request #26137 from Microsoft/updateGraphIfDirty
Use updateGraphIfDirty to do quick check if project update is needed
2 parents 2ea0d16 + d74d861 commit 9df8831

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/server/editorServices.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ namespace ts.server {
337337
return `Project: ${project ? project.getProjectName() : ""} WatchType: ${watchType}`;
338338
}
339339

340-
function updateProjectIfDirty(project: Project) {
340+
/*@internal*/
341+
export function updateProjectIfDirty(project: Project) {
341342
return project.dirty && project.updateGraph();
342343
}
343344

@@ -617,7 +618,7 @@ namespace ts.server {
617618
this.pendingProjectUpdates.set(projectName, project);
618619
this.throttledOperations.schedule(projectName, /*delay*/ 250, () => {
619620
if (this.pendingProjectUpdates.delete(projectName)) {
620-
project.updateGraph();
621+
updateProjectIfDirty(project);
621622
}
622623
});
623624
}
@@ -2148,7 +2149,7 @@ namespace ts.server {
21482149
private findExternalProjectContainingOpenScriptInfo(info: ScriptInfo): ExternalProject | undefined {
21492150
return find(this.externalProjects, proj => {
21502151
// Ensure project structure is up-to-date to check if info is present in external project
2151-
proj.updateGraph();
2152+
updateProjectIfDirty(proj);
21522153
return proj.containsScriptInfo(info);
21532154
});
21542155
}

src/server/project.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ namespace ts.server {
164164
private readonly cancellationToken: ThrottledCancellationToken;
165165

166166
public isNonTsProject() {
167-
this.updateGraph();
167+
updateProjectIfDirty(this);
168168
return allFilesAreJsOrDts(this);
169169
}
170170

171171
public isJsOnlyProject() {
172-
this.updateGraph();
172+
updateProjectIfDirty(this);
173173
return hasOneOrMoreJsAndNoTsFiles(this);
174174
}
175175

@@ -459,7 +459,7 @@ namespace ts.server {
459459

460460
getLanguageService(ensureSynchronized = true): LanguageService {
461461
if (ensureSynchronized) {
462-
this.updateGraph();
462+
updateProjectIfDirty(this);
463463
}
464464
return this.languageService;
465465
}
@@ -477,7 +477,7 @@ namespace ts.server {
477477
if (!this.languageServiceEnabled) {
478478
return [];
479479
}
480-
this.updateGraph();
480+
updateProjectIfDirty(this);
481481
this.builderState = BuilderState.create(this.program, this.projectService.toCanonicalFileName, this.builderState);
482482
return mapDefined(BuilderState.getFilesAffectedBy(this.builderState, this.program, scriptInfo.path, this.cancellationToken, data => this.projectService.host.createHash!(data)), // TODO: GH#18217
483483
sourceFile => this.shouldEmitFile(this.projectService.getScriptInfoForPath(sourceFile.path)!) ? sourceFile.fileName : undefined);
@@ -1025,7 +1025,7 @@ namespace ts.server {
10251025

10261026
/* @internal */
10271027
getChangesSinceVersion(lastKnownVersion?: number): ProjectFilesWithTSDiagnostics {
1028-
this.updateGraph();
1028+
updateProjectIfDirty(this);
10291029

10301030
const info: protocol.ProjectVersionInfo = {
10311031
projectName: this.getProjectName(),

src/server/session.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ namespace ts.server {
695695
const { fileName, project } = checkList[index];
696696
index++;
697697
// Ensure the project is upto date before checking if this file is present in the project
698-
project.updateGraph();
698+
updateProjectIfDirty(project);
699699
if (!project.containsFile(fileName, requireOpen)) {
700700
return;
701701
}
@@ -1084,7 +1084,7 @@ namespace ts.server {
10841084

10851085
private getProjectInfoWorker(uncheckedFileName: string, projectFileName: string | undefined, needFileNameList: boolean, excludeConfigFiles: boolean) {
10861086
const { project } = this.getFileAndProjectWorker(uncheckedFileName, projectFileName);
1087-
project.updateGraph();
1087+
updateProjectIfDirty(project);
10881088
const projectInfo = {
10891089
configFileName: project.getProjectName(),
10901090
languageServiceDisabled: !project.languageServiceEnabled,

0 commit comments

Comments
 (0)