Skip to content

Commit c9c3792

Browse files
author
Ben Lichtman
committed
Produce redirect info about files when requested
1 parent 517d6ee commit c9c3792

File tree

4 files changed

+59
-14
lines changed

4 files changed

+59
-14
lines changed

src/server/editorServices.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,19 +3116,24 @@ namespace ts.server {
31163116
return result;
31173117
}
31183118

3119-
private collectChanges(lastKnownProjectVersions: protocol.ProjectVersionInfo[], currentProjects: Project[], result: ProjectFilesWithTSDiagnostics[]): void {
3119+
private collectChanges(
3120+
lastKnownProjectVersions: protocol.ProjectVersionInfo[],
3121+
currentProjects: Project[],
3122+
includeProjectReferenceRedirectInfo: boolean | undefined,
3123+
result: ProjectFilesWithTSDiagnostics[]
3124+
): void {
31203125
for (const proj of currentProjects) {
31213126
const knownProject = find(lastKnownProjectVersions, p => p.projectName === proj.getProjectName());
3122-
result.push(proj.getChangesSinceVersion(knownProject && knownProject.version));
3127+
result.push(proj.getChangesSinceVersion(knownProject && knownProject.version, includeProjectReferenceRedirectInfo));
31233128
}
31243129
}
31253130

31263131
/* @internal */
3127-
synchronizeProjectList(knownProjects: protocol.ProjectVersionInfo[]): ProjectFilesWithTSDiagnostics[] {
3132+
synchronizeProjectList(knownProjects: protocol.ProjectVersionInfo[], includeProjectReferenceRedirectInfo?: boolean): ProjectFilesWithTSDiagnostics[] {
31283133
const files: ProjectFilesWithTSDiagnostics[] = [];
3129-
this.collectChanges(knownProjects, this.externalProjects, files);
3130-
this.collectChanges(knownProjects, arrayFrom(this.configuredProjects.values()), files);
3131-
this.collectChanges(knownProjects, this.inferredProjects, files);
3134+
this.collectChanges(knownProjects, this.externalProjects, includeProjectReferenceRedirectInfo, files);
3135+
this.collectChanges(knownProjects, arrayFrom(this.configuredProjects.values()), includeProjectReferenceRedirectInfo, files);
3136+
this.collectChanges(knownProjects, this.inferredProjects, includeProjectReferenceRedirectInfo, files);
31323137
return files;
31333138
}
31343139

src/server/project.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,18 @@ namespace ts.server {
13001300
}
13011301

13021302
/* @internal */
1303-
getChangesSinceVersion(lastKnownVersion?: number): ProjectFilesWithTSDiagnostics {
1303+
getChangesSinceVersion(lastKnownVersion?: number, includeProjectReferenceRedirectInfo?: boolean): ProjectFilesWithTSDiagnostics {
1304+
const includeProjectReferenceRedirectInfoIfRequested = (files: string[]) => {
1305+
if (includeProjectReferenceRedirectInfo) {
1306+
return files.map((fileName: string): protocol.FileWithProjectReferenceRedirectInfo => ({
1307+
fileName,
1308+
isSourceOfProjectReferenceRedirect: this.program?.isSourceOfProjectReferenceRedirect(fileName) ?? false
1309+
}));
1310+
}
1311+
1312+
return files;
1313+
};
1314+
13041315
// Update the graph only if initial configured project load is not pending
13051316
if (!this.isInitialLoadPending()) {
13061317
updateProjectIfDirty(this);
@@ -1343,7 +1354,15 @@ namespace ts.server {
13431354
});
13441355
this.lastReportedFileNames = currentFiles;
13451356
this.lastReportedVersion = this.projectProgramVersion;
1346-
return { info, changes: { added, removed, updated }, projectErrors: this.getGlobalProjectErrors() };
1357+
return {
1358+
info,
1359+
changes: {
1360+
added: includeProjectReferenceRedirectInfoIfRequested(added),
1361+
removed: includeProjectReferenceRedirectInfoIfRequested(removed),
1362+
updated: includeProjectReferenceRedirectInfoIfRequested(updated)
1363+
},
1364+
projectErrors: this.getGlobalProjectErrors()
1365+
};
13471366
}
13481367
else {
13491368
// unknown version - return everything
@@ -1352,7 +1371,11 @@ namespace ts.server {
13521371
const allFiles = projectFileNames.concat(externalFiles);
13531372
this.lastReportedFileNames = arrayToSet(allFiles);
13541373
this.lastReportedVersion = this.projectProgramVersion;
1355-
return { info, files: allFiles, projectErrors: this.getGlobalProjectErrors() };
1374+
return {
1375+
info,
1376+
files: includeProjectReferenceRedirectInfoIfRequested(allFiles),
1377+
projectErrors: this.getGlobalProjectErrors()
1378+
};
13561379
}
13571380
}
13581381

src/server/protocol.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,22 +1319,34 @@ namespace ts.server.protocol {
13191319
lastFileExceededProgramSize?: string;
13201320
}
13211321

1322+
export interface FileWithProjectReferenceRedirectInfo {
1323+
/**
1324+
* Name of file
1325+
*/
1326+
fileName: string;
1327+
1328+
/**
1329+
* True if the file is primarily included in a referenced project
1330+
*/
1331+
isSourceOfProjectReferenceRedirect: boolean;
1332+
}
1333+
13221334
/**
13231335
* Represents a set of changes that happen in project
13241336
*/
13251337
export interface ProjectChanges {
13261338
/**
13271339
* List of added files
13281340
*/
1329-
added: string[];
1341+
added: string[] | FileWithProjectReferenceRedirectInfo[];
13301342
/**
13311343
* List of removed files
13321344
*/
1333-
removed: string[];
1345+
removed: string[] | FileWithProjectReferenceRedirectInfo[];
13341346
/**
13351347
* List of updated files
13361348
*/
1337-
updated: string[];
1349+
updated: string[] | FileWithProjectReferenceRedirectInfo[];
13381350
}
13391351

13401352
/**
@@ -1353,7 +1365,7 @@ namespace ts.server.protocol {
13531365
/**
13541366
* List of files in project (might be omitted if current state of project can be computed using only information from 'changes')
13551367
*/
1356-
files?: string[];
1368+
files?: string[] | FileWithProjectReferenceRedirectInfo[];
13571369
/**
13581370
* Set of changes in project (omitted if the entire set of files in project should be replaced)
13591371
*/
@@ -1616,6 +1628,11 @@ namespace ts.server.protocol {
16161628
* List of last known projects
16171629
*/
16181630
knownProjects: ProjectVersionInfo[];
1631+
/**
1632+
* If true, response specifies whether or not each file in each project
1633+
* is the result of a project reference redirect
1634+
*/
1635+
includeProjectReferenceRedirectInfo?: boolean;
16191636
}
16201637

16211638
/**

src/server/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,7 @@ namespace ts.server {
22542254
return this.requiredResponse(/*response*/ true);
22552255
},
22562256
[CommandNames.SynchronizeProjectList]: (request: protocol.SynchronizeProjectListRequest) => {
2257-
const result = this.projectService.synchronizeProjectList(request.arguments.knownProjects);
2257+
const result = this.projectService.synchronizeProjectList(request.arguments.knownProjects, request.arguments.includeProjectReferenceRedirectInfo);
22582258
if (!result.some(p => p.projectErrors && p.projectErrors.length !== 0)) {
22592259
return this.requiredResponse(result);
22602260
}

0 commit comments

Comments
 (0)