Produce redirect info about files when requested

This commit is contained in:
Ben Lichtman 2020-01-23 12:32:36 -08:00
parent 517d6eea28
commit c9c3792747
4 changed files with 59 additions and 14 deletions

View File

@ -3116,19 +3116,24 @@ namespace ts.server {
return result;
}
private collectChanges(lastKnownProjectVersions: protocol.ProjectVersionInfo[], currentProjects: Project[], result: ProjectFilesWithTSDiagnostics[]): void {
private collectChanges(
lastKnownProjectVersions: protocol.ProjectVersionInfo[],
currentProjects: Project[],
includeProjectReferenceRedirectInfo: boolean | undefined,
result: ProjectFilesWithTSDiagnostics[]
): void {
for (const proj of currentProjects) {
const knownProject = find(lastKnownProjectVersions, p => p.projectName === proj.getProjectName());
result.push(proj.getChangesSinceVersion(knownProject && knownProject.version));
result.push(proj.getChangesSinceVersion(knownProject && knownProject.version, includeProjectReferenceRedirectInfo));
}
}
/* @internal */
synchronizeProjectList(knownProjects: protocol.ProjectVersionInfo[]): ProjectFilesWithTSDiagnostics[] {
synchronizeProjectList(knownProjects: protocol.ProjectVersionInfo[], includeProjectReferenceRedirectInfo?: boolean): ProjectFilesWithTSDiagnostics[] {
const files: ProjectFilesWithTSDiagnostics[] = [];
this.collectChanges(knownProjects, this.externalProjects, files);
this.collectChanges(knownProjects, arrayFrom(this.configuredProjects.values()), files);
this.collectChanges(knownProjects, this.inferredProjects, files);
this.collectChanges(knownProjects, this.externalProjects, includeProjectReferenceRedirectInfo, files);
this.collectChanges(knownProjects, arrayFrom(this.configuredProjects.values()), includeProjectReferenceRedirectInfo, files);
this.collectChanges(knownProjects, this.inferredProjects, includeProjectReferenceRedirectInfo, files);
return files;
}

View File

@ -1300,7 +1300,18 @@ namespace ts.server {
}
/* @internal */
getChangesSinceVersion(lastKnownVersion?: number): ProjectFilesWithTSDiagnostics {
getChangesSinceVersion(lastKnownVersion?: number, includeProjectReferenceRedirectInfo?: boolean): ProjectFilesWithTSDiagnostics {
const includeProjectReferenceRedirectInfoIfRequested = (files: string[]) => {
if (includeProjectReferenceRedirectInfo) {
return files.map((fileName: string): protocol.FileWithProjectReferenceRedirectInfo => ({
fileName,
isSourceOfProjectReferenceRedirect: this.program?.isSourceOfProjectReferenceRedirect(fileName) ?? false
}));
}
return files;
};
// Update the graph only if initial configured project load is not pending
if (!this.isInitialLoadPending()) {
updateProjectIfDirty(this);
@ -1343,7 +1354,15 @@ namespace ts.server {
});
this.lastReportedFileNames = currentFiles;
this.lastReportedVersion = this.projectProgramVersion;
return { info, changes: { added, removed, updated }, projectErrors: this.getGlobalProjectErrors() };
return {
info,
changes: {
added: includeProjectReferenceRedirectInfoIfRequested(added),
removed: includeProjectReferenceRedirectInfoIfRequested(removed),
updated: includeProjectReferenceRedirectInfoIfRequested(updated)
},
projectErrors: this.getGlobalProjectErrors()
};
}
else {
// unknown version - return everything
@ -1352,7 +1371,11 @@ namespace ts.server {
const allFiles = projectFileNames.concat(externalFiles);
this.lastReportedFileNames = arrayToSet(allFiles);
this.lastReportedVersion = this.projectProgramVersion;
return { info, files: allFiles, projectErrors: this.getGlobalProjectErrors() };
return {
info,
files: includeProjectReferenceRedirectInfoIfRequested(allFiles),
projectErrors: this.getGlobalProjectErrors()
};
}
}

View File

@ -1319,6 +1319,18 @@ namespace ts.server.protocol {
lastFileExceededProgramSize?: string;
}
export interface FileWithProjectReferenceRedirectInfo {
/**
* Name of file
*/
fileName: string;
/**
* True if the file is primarily included in a referenced project
*/
isSourceOfProjectReferenceRedirect: boolean;
}
/**
* Represents a set of changes that happen in project
*/
@ -1326,15 +1338,15 @@ namespace ts.server.protocol {
/**
* List of added files
*/
added: string[];
added: string[] | FileWithProjectReferenceRedirectInfo[];
/**
* List of removed files
*/
removed: string[];
removed: string[] | FileWithProjectReferenceRedirectInfo[];
/**
* List of updated files
*/
updated: string[];
updated: string[] | FileWithProjectReferenceRedirectInfo[];
}
/**
@ -1353,7 +1365,7 @@ namespace ts.server.protocol {
/**
* List of files in project (might be omitted if current state of project can be computed using only information from 'changes')
*/
files?: string[];
files?: string[] | FileWithProjectReferenceRedirectInfo[];
/**
* Set of changes in project (omitted if the entire set of files in project should be replaced)
*/
@ -1616,6 +1628,11 @@ namespace ts.server.protocol {
* List of last known projects
*/
knownProjects: ProjectVersionInfo[];
/**
* If true, response specifies whether or not each file in each project
* is the result of a project reference redirect
*/
includeProjectReferenceRedirectInfo?: boolean;
}
/**

View File

@ -2254,7 +2254,7 @@ namespace ts.server {
return this.requiredResponse(/*response*/ true);
},
[CommandNames.SynchronizeProjectList]: (request: protocol.SynchronizeProjectListRequest) => {
const result = this.projectService.synchronizeProjectList(request.arguments.knownProjects);
const result = this.projectService.synchronizeProjectList(request.arguments.knownProjects, request.arguments.includeProjectReferenceRedirectInfo);
if (!result.some(p => p.projectErrors && p.projectErrors.length !== 0)) {
return this.requiredResponse(result);
}