Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ namespace ts.server {
return `Project: ${project ? project.getProjectName() : ""} WatchType: ${watchType}`;
}

function updateProjectIfDirty(project: Project) {
/*@internal*/
export function updateProjectIfDirty(project: Project) {
return project.dirty && project.updateGraph();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not put this check directly in updateGraph? Are there cases where we want to force an update regardless?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are cases we already know that project is dirty..
Updategraph is also overridden to do extra things depending on project type so update graph is not place where you want to do this check

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a caller, how do I know whether I should call updateProjectIfDirty or updateGraph?

}

Expand Down Expand Up @@ -617,7 +618,7 @@ namespace ts.server {
this.pendingProjectUpdates.set(projectName, project);
this.throttledOperations.schedule(projectName, /*delay*/ 250, () => {
if (this.pendingProjectUpdates.delete(projectName)) {
project.updateGraph();
updateProjectIfDirty(project);
}
});
}
Expand Down Expand Up @@ -2148,7 +2149,7 @@ namespace ts.server {
private findExternalProjectContainingOpenScriptInfo(info: ScriptInfo): ExternalProject | undefined {
return find(this.externalProjects, proj => {
// Ensure project structure is up-to-date to check if info is present in external project
proj.updateGraph();
updateProjectIfDirty(proj);
return proj.containsScriptInfo(info);
});
}
Expand Down
10 changes: 5 additions & 5 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ namespace ts.server {
private readonly cancellationToken: ThrottledCancellationToken;

public isNonTsProject() {
this.updateGraph();
updateProjectIfDirty(this);
return allFilesAreJsOrDts(this);
}

public isJsOnlyProject() {
this.updateGraph();
updateProjectIfDirty(this);
return hasOneOrMoreJsAndNoTsFiles(this);
}

Expand Down Expand Up @@ -459,7 +459,7 @@ namespace ts.server {

getLanguageService(ensureSynchronized = true): LanguageService {
if (ensureSynchronized) {
this.updateGraph();
updateProjectIfDirty(this);
}
return this.languageService;
}
Expand All @@ -477,7 +477,7 @@ namespace ts.server {
if (!this.languageServiceEnabled) {
return [];
}
this.updateGraph();
updateProjectIfDirty(this);
this.builderState = BuilderState.create(this.program, this.projectService.toCanonicalFileName, this.builderState);
return mapDefined(BuilderState.getFilesAffectedBy(this.builderState, this.program, scriptInfo.path, this.cancellationToken, data => this.projectService.host.createHash!(data)), // TODO: GH#18217
sourceFile => this.shouldEmitFile(this.projectService.getScriptInfoForPath(sourceFile.path)!) ? sourceFile.fileName : undefined);
Expand Down Expand Up @@ -1025,7 +1025,7 @@ namespace ts.server {

/* @internal */
getChangesSinceVersion(lastKnownVersion?: number): ProjectFilesWithTSDiagnostics {
this.updateGraph();
updateProjectIfDirty(this);

const info: protocol.ProjectVersionInfo = {
projectName: this.getProjectName(),
Expand Down
4 changes: 2 additions & 2 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ namespace ts.server {
const { fileName, project } = checkList[index];
index++;
// Ensure the project is upto date before checking if this file is present in the project
project.updateGraph();
updateProjectIfDirty(project);
if (!project.containsFile(fileName, requireOpen)) {
return;
}
Expand Down Expand Up @@ -1084,7 +1084,7 @@ namespace ts.server {

private getProjectInfoWorker(uncheckedFileName: string, projectFileName: string | undefined, needFileNameList: boolean, excludeConfigFiles: boolean) {
const { project } = this.getFileAndProjectWorker(uncheckedFileName, projectFileName);
project.updateGraph();
updateProjectIfDirty(project);
const projectInfo = {
configFileName: project.getProjectName(),
languageServiceDisabled: !project.languageServiceEnabled,
Expand Down