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)) {
|
if (this.logger.hasLevel(LogLevel.verbose)) {
|
||||||
try {
|
if (fileRequest) {
|
||||||
const { file, project } = this.getFileAndProject(fileRequest);
|
try {
|
||||||
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
|
const { file, project } = this.getFileAndProject(fileRequest);
|
||||||
if (scriptInfo) {
|
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
|
||||||
const text = getSnapshotText(scriptInfo.getSnapshot());
|
if (scriptInfo) {
|
||||||
msg += `\n\nFile text of ${fileRequest.file}:${indent(text)}\n`;
|
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);
|
this.logger.msg(msg, Msg.Err);
|
||||||
|
|
|
@ -1158,7 +1158,7 @@ namespace ts {
|
||||||
function getValidSourceFile(fileName: string): SourceFile {
|
function getValidSourceFile(fileName: string): SourceFile {
|
||||||
const sourceFile = program.getSourceFile(fileName);
|
const sourceFile = program.getSourceFile(fileName);
|
||||||
if (!sourceFile) {
|
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;
|
return sourceFile;
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,7 @@ namespace ts.projectSystem {
|
||||||
assert.isTrue(false, `should not find file '${imported.path}'`);
|
assert.isTrue(false, `should not find file '${imported.path}'`);
|
||||||
}
|
}
|
||||||
catch (e) {
|
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");
|
const f2Lookups = getLocationsForModuleLookup("f2");
|
||||||
callsTrackingHost.verifyCalledOnEachEntryNTimes(CalledMapsWithSingleArg.fileExists, f2Lookups, 1);
|
callsTrackingHost.verifyCalledOnEachEntryNTimes(CalledMapsWithSingleArg.fileExists, f2Lookups, 1);
|
||||||
|
|
Loading…
Reference in a new issue