Merge pull request #30437 from Microsoft/validSourceFile
Add more information when getValidSourceFile cant find the file in question.
This commit is contained in:
commit
3b607df658
3 changed files with 26 additions and 10 deletions
|
@ -659,16 +659,32 @@ namespace ts.server {
|
|||
}
|
||||
}
|
||||
|
||||
if (fileRequest && this.logger.hasLevel(LogLevel.verbose)) {
|
||||
try {
|
||||
const { file, project } = this.getFileAndProject(fileRequest);
|
||||
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
|
||||
if (scriptInfo) {
|
||||
const text = getSnapshotText(scriptInfo.getSnapshot());
|
||||
msg += `\n\nFile text of ${fileRequest.file}:${indent(text)}\n`;
|
||||
if (this.logger.hasLevel(LogLevel.verbose)) {
|
||||
if (fileRequest) {
|
||||
try {
|
||||
const { file, project } = this.getFileAndProject(fileRequest);
|
||||
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
|
||||
if (scriptInfo) {
|
||||
const text = getSnapshotText(scriptInfo.getSnapshot());
|
||||
msg += `\n\nFile text of ${fileRequest.file}:${indent(text)}\n`;
|
||||
}
|
||||
}
|
||||
catch { } // tslint:disable-line no-empty
|
||||
}
|
||||
|
||||
if (err.message && err.message.indexOf(`Could not find sourceFile:`) !== -1) {
|
||||
msg += `\n\nProjects::\n`;
|
||||
let counter = 0;
|
||||
const addProjectInfo = (project: Project) => {
|
||||
msg += `\nProject '${project.projectName}' (${ProjectKind[project.projectKind]}) ${counter}\n`;
|
||||
msg += project.filesToString(/*writeProjectFileNames*/ true);
|
||||
msg += "\n-----------------------------------------------\n";
|
||||
counter++;
|
||||
};
|
||||
this.projectService.externalProjects.forEach(addProjectInfo);
|
||||
this.projectService.configuredProjects.forEach(addProjectInfo);
|
||||
this.projectService.inferredProjects.forEach(addProjectInfo);
|
||||
}
|
||||
catch {} // tslint:disable-line no-empty
|
||||
}
|
||||
|
||||
this.logger.msg(msg, Msg.Err);
|
||||
|
|
|
@ -1158,7 +1158,7 @@ namespace ts {
|
|||
function getValidSourceFile(fileName: string): SourceFile {
|
||||
const sourceFile = program.getSourceFile(fileName);
|
||||
if (!sourceFile) {
|
||||
throw new Error("Could not find file: '" + fileName + "'.");
|
||||
throw new Error(`Could not find sourceFile: '${fileName}' in ${program && JSON.stringify(program.getSourceFiles().map(f => f.fileName))}.`);
|
||||
}
|
||||
return sourceFile;
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ namespace ts.projectSystem {
|
|||
assert.isTrue(false, `should not find file '${imported.path}'`);
|
||||
}
|
||||
catch (e) {
|
||||
assert.isTrue(e.message.indexOf(`Could not find file: '${imported.path}'.`) === 0);
|
||||
assert.isTrue(e.message.indexOf(`Could not find sourceFile: '${imported.path}' in ["${root.path}"].`) === 0, `Actual: ${e.message}`);
|
||||
}
|
||||
const f2Lookups = getLocationsForModuleLookup("f2");
|
||||
callsTrackingHost.verifyCalledOnEachEntryNTimes(CalledMapsWithSingleArg.fileExists, f2Lookups, 1);
|
||||
|
|
Loading…
Reference in a new issue