Skip to content

Commit ffdeb28

Browse files
author
Andy Hanson
committed
Include both fileName and path, and use in more places
1 parent e69736e commit ffdeb28

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/server/editorServices.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,13 @@ namespace ts.server {
867867
private doEnsureDefaultProjectForFile(fileName: NormalizedPath): Project {
868868
this.ensureProjectStructuresUptoDate();
869869
const scriptInfo = this.getScriptInfoForNormalizedPath(fileName);
870-
return scriptInfo ? scriptInfo.getDefaultProject() : Errors.ThrowNoProject();
870+
if (scriptInfo) {
871+
return scriptInfo.getDefaultProject();
872+
}
873+
else {
874+
this.logger.msg(`Cannot find ${fileName} in ${JSON.stringify(this.allScriptInfoFileNamesForDebug)}`, Msg.Err);
875+
return Errors.ThrowNoProject();
876+
}
871877
}
872878

873879
getScriptInfoEnsuringProjectsUptoDate(uncheckedFileName: string) {
@@ -1967,8 +1973,12 @@ namespace ts.server {
19671973
}
19681974

19691975
/* @internal */
1970-
allScriptInfoFileNamesForDebug(): ReadonlyArray<string> {
1971-
return arrayFrom(this.filenameToScriptInfo.keys());
1976+
allScriptInfoFileNamesForDebug(): ReadonlyArray<{ readonly path: string, readonly fileName: string }> {
1977+
const out: { readonly path: string, readonly fileName: string }[] = [];
1978+
this.filenameToScriptInfo.forEach((scriptInfo, path) => {
1979+
out.push({ path, fileName: scriptInfo.fileName });
1980+
});
1981+
return out;
19721982
}
19731983

19741984
/**

src/server/session.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,19 +1157,27 @@ namespace ts.server {
11571157
this.projectService.getScriptInfoEnsuringProjectsUptoDate(args.file) :
11581158
this.projectService.getScriptInfo(args.file);
11591159
if (!scriptInfo) {
1160-
return ignoreNoProjectError ? emptyArray : Errors.ThrowNoProject();
1160+
if (ignoreNoProjectError) return emptyArray;
1161+
this.logErrorForScriptInfoNotFound(args.file);
1162+
return Errors.ThrowNoProject();
11611163
}
11621164
projects = scriptInfo.containingProjects;
11631165
symLinkedProjects = this.projectService.getSymlinkedProjects(scriptInfo);
11641166
}
11651167
// filter handles case when 'projects' is undefined
11661168
projects = filter(projects, p => p.languageServiceEnabled && !p.isOrphan());
11671169
if (!ignoreNoProjectError && (!projects || !projects.length) && !symLinkedProjects) {
1170+
this.logErrorForScriptInfoNotFound(args.file);
11681171
return Errors.ThrowNoProject();
11691172
}
11701173
return symLinkedProjects ? { projects: projects!, symLinkedProjects } : projects!; // TODO: GH#18217
11711174
}
11721175

1176+
private logErrorForScriptInfoNotFound(fileName: string): void {
1177+
this.logger.msg(`Could not find file ${JSON.stringify(fileName)}.\n` +
1178+
`All files are: ${JSON.stringify(this.projectService.allScriptInfoFileNamesForDebug())}`, Msg.Err);
1179+
}
1180+
11731181
private getDefaultProject(args: protocol.FileRequestArgs) {
11741182
if (args.projectFileName) {
11751183
const project = this.getProject(args.projectFileName);
@@ -1912,8 +1920,7 @@ namespace ts.server {
19121920
const scriptInfo = this.projectService.getScriptInfoOrConfig(textChanges.fileName);
19131921
if (!!textChanges.isNewFile === !!scriptInfo) {
19141922
if (!scriptInfo) { // and !isNewFile
1915-
this.logger.msg(`Could not find file ${JSON.stringify(textChanges.fileName)} and 'isNewFile' not set.\n` +
1916-
`All files are: ${JSON.stringify(this.projectService.allScriptInfoFileNamesForDebug())}`, Msg.Err);
1923+
this.logErrorForScriptInfoNotFound(textChanges.fileName);
19171924
}
19181925
Debug.fail("Expected isNewFile for (only) new files. " + JSON.stringify({ isNewFile: !!textChanges.isNewFile, hasScriptInfo: !!scriptInfo }));
19191926
}

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8826,6 +8826,7 @@ declare namespace ts.server {
88268826
private getProjectInfoWorker;
88278827
private getRenameInfo;
88288828
private getProjects;
8829+
private logErrorForScriptInfoNotFound;
88298830
private getDefaultProject;
88308831
private getRenameLocations;
88318832
private mapRenameInfo;

0 commit comments

Comments
 (0)