Skip to content

Commit 199d496

Browse files
authored
Merge pull request #26716 from Microsoft/lazyConfiguredProjectsFromExternalProject
Add option --lazyConfiguredProjectsFromExternalProject to enable lazy load of configured projects referenced by external project
2 parents 9106fdb + 03bb5d1 commit 199d496

File tree

7 files changed

+375
-234
lines changed

7 files changed

+375
-234
lines changed

src/server/editorServices.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,15 @@ namespace ts.server {
218218
}
219219
}
220220

221+
/*@internal*/
222+
export function convertUserPreferences(preferences: protocol.UserPreferences): UserPreferences {
223+
const { lazyConfiguredProjectsFromExternalProject, ...userPreferences } = preferences;
224+
return userPreferences;
225+
}
226+
221227
export interface HostConfiguration {
222228
formatCodeOptions: FormatCodeSettings;
223-
preferences: UserPreferences;
229+
preferences: protocol.UserPreferences;
224230
hostInfo: string;
225231
extraFileExtensions?: FileExtensionInfo[];
226232
}
@@ -802,7 +808,7 @@ namespace ts.server {
802808
return info && info.getFormatCodeSettings() || this.hostConfiguration.formatCodeOptions;
803809
}
804810

805-
getPreferences(file: NormalizedPath): UserPreferences {
811+
getPreferences(file: NormalizedPath): protocol.UserPreferences {
806812
const info = this.getScriptInfoForNormalizedPath(file);
807813
return info && info.getPreferences() || this.hostConfiguration.preferences;
808814
}
@@ -811,7 +817,7 @@ namespace ts.server {
811817
return this.hostConfiguration.formatCodeOptions;
812818
}
813819

814-
getHostPreferences(): UserPreferences {
820+
getHostPreferences(): protocol.UserPreferences {
815821
return this.hostConfiguration.preferences;
816822
}
817823

@@ -1561,6 +1567,13 @@ namespace ts.server {
15611567
return project;
15621568
}
15631569

1570+
/* @internal */
1571+
private createLoadAndUpdateConfiguredProject(configFileName: NormalizedPath) {
1572+
const project = this.createAndLoadConfiguredProject(configFileName);
1573+
project.updateGraph();
1574+
return project;
1575+
}
1576+
15641577
/**
15651578
* Read the config file of the project, and update the project root file names.
15661579
*/
@@ -1979,7 +1992,19 @@ namespace ts.server {
19791992
this.logger.info("Format host information updated");
19801993
}
19811994
if (args.preferences) {
1995+
const { lazyConfiguredProjectsFromExternalProject } = this.hostConfiguration.preferences;
19821996
this.hostConfiguration.preferences = { ...this.hostConfiguration.preferences, ...args.preferences };
1997+
if (lazyConfiguredProjectsFromExternalProject && !this.hostConfiguration.preferences.lazyConfiguredProjectsFromExternalProject) {
1998+
// Load configured projects for external projects that are pending reload
1999+
this.configuredProjects.forEach(project => {
2000+
if (project.hasExternalProjectRef() &&
2001+
project.pendingReload === ConfigFileProgramReloadLevel.Full &&
2002+
!this.pendingProjectUpdates.has(project.getProjectName())) {
2003+
this.loadConfiguredProject(project);
2004+
project.updateGraph();
2005+
}
2006+
});
2007+
}
19832008
}
19842009
if (args.extraFileExtensions) {
19852010
this.hostConfiguration.extraFileExtensions = args.extraFileExtensions;
@@ -2192,8 +2217,7 @@ namespace ts.server {
21922217
if (configFileName) {
21932218
project = this.findConfiguredProjectByProjectName(configFileName);
21942219
if (!project) {
2195-
project = this.createAndLoadConfiguredProject(configFileName);
2196-
project.updateGraph();
2220+
project = this.createLoadAndUpdateConfiguredProject(configFileName);
21972221
// Send the event only if the project got created as part of this open request and info is part of the project
21982222
if (info.isOrphan()) {
21992223
// Since the file isnt part of configured project, do not send config file info
@@ -2633,7 +2657,9 @@ namespace ts.server {
26332657
let project = this.findConfiguredProjectByProjectName(tsconfigFile);
26342658
if (!project) {
26352659
// errors are stored in the project, do not need to update the graph
2636-
project = this.createConfiguredProjectWithDelayLoad(tsconfigFile);
2660+
project = this.getHostPreferences().lazyConfiguredProjectsFromExternalProject ?
2661+
this.createConfiguredProjectWithDelayLoad(tsconfigFile) :
2662+
this.createLoadAndUpdateConfiguredProject(tsconfigFile);
26372663
}
26382664
if (project && !contains(exisingConfigFiles, tsconfigFile)) {
26392665
// keep project alive even if no documents are opened - its lifetime is bound to the lifetime of containing external project

src/server/project.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,11 @@ namespace ts.server {
15201520
) || false;
15211521
}
15221522

1523+
/*@internal*/
1524+
hasExternalProjectRef() {
1525+
return !!this.externalProjectRefCount;
1526+
}
1527+
15231528
getEffectiveTypeRoots() {
15241529
return getEffectiveTypeRoots(this.getCompilationSettings(), this.directoryStructureHost) || [];
15251530
}

src/server/protocol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,6 +2823,7 @@ namespace ts.server.protocol {
28232823
readonly includeCompletionsWithInsertText?: boolean;
28242824
readonly importModuleSpecifierPreference?: "relative" | "non-relative";
28252825
readonly allowTextChangesInNewFiles?: boolean;
2826+
readonly lazyConfiguredProjectsFromExternalProject?: boolean;
28262827
}
28272828

28282829
export interface CompilerOptions {

src/server/scriptInfo.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ namespace ts.server {
234234
*/
235235
readonly containingProjects: Project[] = [];
236236
private formatSettings: FormatCodeSettings | undefined;
237-
private preferences: UserPreferences | undefined;
237+
private preferences: protocol.UserPreferences | undefined;
238238

239239
/* @internal */
240240
fileWatcher: FileWatcher | undefined;
@@ -333,7 +333,7 @@ namespace ts.server {
333333
}
334334

335335
getFormatCodeSettings(): FormatCodeSettings | undefined { return this.formatSettings; }
336-
getPreferences(): UserPreferences | undefined { return this.preferences; }
336+
getPreferences(): protocol.UserPreferences | undefined { return this.preferences; }
337337

338338
attachToProject(project: Project): boolean {
339339
const isNew = !this.isAttached(project);
@@ -432,7 +432,7 @@ namespace ts.server {
432432
}
433433
}
434434

435-
setOptions(formatSettings: FormatCodeSettings, preferences: UserPreferences | undefined): void {
435+
setOptions(formatSettings: FormatCodeSettings, preferences: protocol.UserPreferences | undefined): void {
436436
if (formatSettings) {
437437
if (!this.formatSettings) {
438438
this.formatSettings = getDefaultFormatCodeSettings(this.host);

src/server/session.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ namespace ts.server {
14231423
const position = this.getPosition(args, scriptInfo);
14241424

14251425
const completions = project.getLanguageService().getCompletionsAtPosition(file, position, {
1426-
...this.getPreferences(file),
1426+
...convertUserPreferences(this.getPreferences(file)),
14271427
triggerCharacter: args.triggerCharacter,
14281428
includeExternalModuleExports: args.includeExternalModuleExports,
14291429
includeInsertTextCompletions: args.includeInsertTextCompletions
@@ -2352,15 +2352,15 @@ namespace ts.server {
23522352
return this.projectService.getFormatCodeOptions(file);
23532353
}
23542354

2355-
private getPreferences(file: NormalizedPath): UserPreferences {
2355+
private getPreferences(file: NormalizedPath): protocol.UserPreferences {
23562356
return this.projectService.getPreferences(file);
23572357
}
23582358

23592359
private getHostFormatOptions(): FormatCodeSettings {
23602360
return this.projectService.getHostFormatCodeOptions();
23612361
}
23622362

2363-
private getHostPreferences(): UserPreferences {
2363+
private getHostPreferences(): protocol.UserPreferences {
23642364
return this.projectService.getHostPreferences();
23652365
}
23662366
}

0 commit comments

Comments
 (0)