Fix the invalid file/directory location when getting file system entry for caching read directory results

Fixes #20607
This commit is contained in:
Sheetal Nandi 2018-01-17 14:51:31 -08:00
parent e248d08e4c
commit 8281c7a137
4 changed files with 33 additions and 3 deletions

View file

@ -20,6 +20,7 @@ namespace ts {
/* @internal */
namespace ts {
export const emptyArray: never[] = [] as never[];
/** Create a MapLike with good performance. */
function createDictionaryObject<T>(): MapLike<T> {
const map = Object.create(/*prototype*/ null); // tslint:disable-line:no-null-keyword
@ -3069,6 +3070,10 @@ namespace ts {
readonly directories: string[];
}
export const emptyFileSystemEntries: FileSystemEntries = {
files: emptyArray,
directories: emptyArray
};
export function createCachedDirectoryStructureHost(host: DirectoryStructureHost): CachedDirectoryStructureHost {
const cachedReadDirectoryResult = createMap<MutableFileSystemEntries>();
const getCurrentDirectory = memoize(() => host.getCurrentDirectory());
@ -3210,7 +3215,7 @@ namespace ts {
if (path === rootDirPath) {
return result;
}
return getCachedFileSystemEntries(path) || createCachedFileSystemEntries(dir, path);
return tryReadDirectory(dir, path) || emptyFileSystemEntries;
}
}

View file

@ -398,7 +398,7 @@ namespace ts {
return { files, directories };
}
catch (e) {
return { files: [], directories: [] };
return emptyFileSystemEntries;
}
}

View file

@ -2,7 +2,6 @@
/* @internal */
namespace ts {
export const emptyArray: never[] = [] as never[];
export const resolvingEmptyArray: never[] = [] as never[];
export const emptyMap: ReadonlyMap<never> = createMap<never>();
export const emptyUnderscoreEscapedMap: ReadonlyUnderscoreEscapedMap<never> = emptyMap as ReadonlyUnderscoreEscapedMap<never>;

View file

@ -4168,6 +4168,32 @@ namespace ts.projectSystem {
// Since no file from the configured project is open, it would be closed immediately
projectService.checkNumberOfProjects({ configuredProjects: 0, inferredProjects: 1 });
});
it("should tolerate invalid include files that start in subDirectory", () => {
const projectFolder = "/user/username/projects/myproject";
const f = {
path: `${projectFolder}/src/server/index.ts`,
content: "let x = 1"
};
const config = {
path: `${projectFolder}/src/server/tsconfig.json`,
content: JSON.stringify({
compiler: {
module: "commonjs",
outDir: "../../build"
},
include: [
"../src/**/*.ts"
]
})
};
const host = createServerHost([f, config, libFile], { useCaseSensitiveFileNames: true });
const projectService = createProjectService(host);
projectService.openClientFile(f.path);
// Since no file from the configured project is open, it would be closed immediately
projectService.checkNumberOfProjects({ configuredProjects: 0, inferredProjects: 1 });
});
});
describe("tsserverProjectSystem reload", () => {