Skip to content

Commit f6937f7

Browse files
committed
Some more refactoring for handling background projects
1 parent 69b3f4f commit f6937f7

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

src/server/editorServices.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ import {
154154
hasNoTypeScriptSource,
155155
InferredProject,
156156
InvalidateCachedTypings,
157+
isBackgroundProject,
157158
isConfiguredProject,
158159
isDynamicFileName,
159160
isInferredProject,
@@ -1326,15 +1327,14 @@ export class ProjectService {
13261327

13271328
private delayUpdateProjectGraph(project: Project) {
13281329
project.markAsDirty();
1329-
if (project.projectKind !== ProjectKind.AutoImportProvider && project.projectKind !== ProjectKind.Auxiliary) {
1330-
const projectName = project.getProjectName();
1331-
this.pendingProjectUpdates.set(projectName, project);
1332-
this.throttledOperations.schedule(projectName, /*delay*/ 250, () => {
1333-
if (this.pendingProjectUpdates.delete(projectName)) {
1334-
updateProjectIfDirty(project);
1335-
}
1336-
});
1337-
}
1330+
if (isBackgroundProject(project)) return;
1331+
const projectName = project.getProjectName();
1332+
this.pendingProjectUpdates.set(projectName, project);
1333+
this.throttledOperations.schedule(projectName, /*delay*/ 250, () => {
1334+
if (this.pendingProjectUpdates.delete(projectName)) {
1335+
updateProjectIfDirty(project);
1336+
}
1337+
});
13381338
}
13391339

13401340
/** @internal */

src/server/project.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
579579
this.disableLanguageService(lastFileExceededProgramSize);
580580
}
581581
this.markAsDirty();
582-
if (projectKind !== ProjectKind.AutoImportProvider) {
582+
if (!isBackgroundProject(this)) {
583583
this.projectService.pendingEnsureProjectForOpenFiles = true;
584584
}
585585
}
@@ -2996,3 +2996,8 @@ export function isConfiguredProject(project: Project): project is ConfiguredProj
29962996
export function isExternalProject(project: Project): project is ExternalProject {
29972997
return project.projectKind === ProjectKind.External;
29982998
}
2999+
3000+
/**@internal */
3001+
export function isBackgroundProject(project: Project): project is AutoImportProviderProject | AuxiliaryProject {
3002+
return project.projectKind === ProjectKind.AutoImportProvider || project.projectKind === ProjectKind.Auxiliary;
3003+
}

src/server/scriptInfo.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ import {
4040
Errors,
4141
ExternalProject,
4242
InferredProject,
43+
isBackgroundProject,
4344
isConfiguredProject,
4445
isExternalProject,
4546
isInferredProject,
4647
maxFileSize,
4748
NormalizedPath,
4849
Project,
49-
ProjectKind,
5050
ScriptVersionCache,
5151
ServerHost,
5252
} from "./_namespaces/ts.server";
@@ -682,7 +682,7 @@ export class ScriptInfo {
682682
isContainedByBackgroundProject() {
683683
return some(
684684
this.containingProjects,
685-
p => p.projectKind === ProjectKind.AutoImportProvider || p.projectKind === ProjectKind.Auxiliary,
685+
isBackgroundProject,
686686
);
687687
}
688688

@@ -730,7 +730,7 @@ export class ScriptInfo {
730730
* reported as the default project for a ScriptInfo.
731731
*/
732732
function ensurePrimaryProjectKind(project: Project | undefined) {
733-
if (!project || project.projectKind === ProjectKind.AutoImportProvider || project.projectKind === ProjectKind.Auxiliary) {
733+
if (!project || isBackgroundProject(project)) {
734734
return Errors.ThrowNoProject();
735735
}
736736
return project;

0 commit comments

Comments
 (0)