Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch improvements in tsserver #17269

Merged
merged 128 commits into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from 125 commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
21ad26b
When opening a file, if it is using existing project, there is no nee…
sheetalkamat Jun 30, 2017
ae33ae8
Restructure updating the configured project from disk and actual proj…
sheetalkamat Jul 1, 2017
75698a8
Add project roots in the list of root files even if they arent presen…
sheetalkamat Jul 6, 2017
f154910
Move the server file system to handle watches on file/folder create, …
sheetalkamat Jul 7, 2017
0e44367
Remove the functions to trigger watch callbacks now that it is auto o…
sheetalkamat Jul 7, 2017
2a63827
Update the todo list
sheetalkamat Jul 7, 2017
96ffd53
Reload the configured project only once even though there are multipl…
sheetalkamat Jul 7, 2017
6bd42b8
When config file is deleted, apart from removing the projecty, reload…
sheetalkamat Jul 7, 2017
df6f75b
Optimize wildcard watchers and config directory watching as now we ha…
sheetalkamat Jul 7, 2017
9ff9476
Handle the deleted file in update graph better, so that in next updat…
sheetalkamat Jul 10, 2017
62871cc
Only update file list when there are changes in the watched directories
sheetalkamat Jul 11, 2017
48c6513
Update types instantly when the type root changes.
sheetalkamat Jul 11, 2017
19a6a00
Cache the read directory results so that it doesnt end up reading it …
sheetalkamat Jul 11, 2017
68def1b
Use the cached file exists/directory exists for configured project si…
sheetalkamat Jul 11, 2017
029b1f2
Fixes the fourslash runner tests by handling hosts that cannot suppor…
sheetalkamat Jul 12, 2017
f338a70
Remove the done TODO
sheetalkamat Jul 12, 2017
8fedcf7
TODOs for the scheduling update graph and referesh projects
sheetalkamat Jul 13, 2017
e568976
Allows the delayed update graph and project structure which helps in …
sheetalkamat Jul 13, 2017
048e67c
Merge branch 'master' into watchImprovements
sheetalkamat Jul 13, 2017
0365901
use single instance of getCanonicalFileName
sheetalkamat Jul 13, 2017
404aa8f
Logging of the watch add/remove/event
sheetalkamat Jul 14, 2017
71d79c6
Some refactoring to combine files removal from inferred project
sheetalkamat Jul 15, 2017
f12980d
Remove the duplcate error about no input files found
sheetalkamat Jul 15, 2017
00011a5
Refactor root files addition/update for non inferred project
sheetalkamat Jul 15, 2017
0572b15
Instead of watching directories, watch tsconfig files of inferred pro…
sheetalkamat Jul 16, 2017
62663a1
Use map for configured project instead of the array
sheetalkamat Jul 16, 2017
dcbd7b1
Combine the logic to find config file as well as the watch.
sheetalkamat Jul 16, 2017
62ef6b1
Added another todo as now we are watching too many files
sheetalkamat Jul 17, 2017
2439e7a
Reduce the number of watched config files by watching the chain only …
sheetalkamat Jul 17, 2017
ff34a77
Merge branch 'master' into watchImprovements
sheetalkamat Jul 17, 2017
1155c37
Merge branch 'master' into watchImprovements
sheetalkamat Jul 20, 2017
ae87838
Merge branch 'master' into watchImprovements
sheetalkamat Aug 7, 2017
802e283
Refactoring of the builder
sheetalkamat Jul 19, 2017
499fabc
Do not update graph in builder if compile on save is not on
sheetalkamat Jul 19, 2017
273569f
Make the host cache store the fileName instead of undefined for the m…
sheetalkamat Jul 19, 2017
94a589b
Program cannot be reused if the missing file is now present
sheetalkamat Jul 21, 2017
ef5935b
Initial refactoring so that watch from tsc follows the tsserver projects
sheetalkamat Jul 24, 2017
e068475
Refactor so that builder handles only source files and program
sheetalkamat Jul 24, 2017
6237b22
Move the builder to compiler directory
sheetalkamat Jul 24, 2017
9b18f7b
Use builder to emit the files from the tsc.js
sheetalkamat Jul 24, 2017
85b9254
Refactor out the tsc logic into another file so we can use that to te…
sheetalkamat Jul 26, 2017
69e5abd
Refactor watched system from tsserver tests so that tscLib watch can …
sheetalkamat Jul 26, 2017
c814d8e
Add tests for the tsc --watch
sheetalkamat Jul 26, 2017
2dd6aed
Emit tests
sheetalkamat Jul 29, 2017
89c61e7
Modify the api in builder so that it tracks changed files
sheetalkamat Aug 3, 2017
bb91b32
Add tests to verify emitted files
sheetalkamat Aug 3, 2017
46e3d1c
Refactoring so that instead of just using from tsc --watch the new ap…
sheetalkamat Aug 4, 2017
031a637
Switch back to have tsc.ts the only file thats different in tsc.js ge…
sheetalkamat Aug 4, 2017
0d5e6c9
Use cache for module resolution even in watch mode
sheetalkamat Aug 4, 2017
2762232
Test for the module resolution caching
sheetalkamat Aug 4, 2017
65a6ee0
Add test that fails because we dont watch module resolutions failed p…
sheetalkamat Aug 5, 2017
d55150c
Implementation of watching the failed lookup locations
sheetalkamat Aug 5, 2017
8dc6248
Partial implementation for invalidating the program (instead of sourc…
sheetalkamat Aug 5, 2017
7474ba7
Implementation for invalidating source file containing possibly chang…
sheetalkamat Aug 5, 2017
6385f7e
Get semantic diagnostics for the program from builder so that it cach…
sheetalkamat Aug 7, 2017
65521bc
Feedback from the PR
sheetalkamat Aug 7, 2017
27988bf
More updates based on PR feedback
sheetalkamat Aug 7, 2017
02b8a7d
More work on PR feedback
sheetalkamat Aug 7, 2017
f723beb
More updates per PR feedback
sheetalkamat Aug 7, 2017
b071a86
More work on feedback from PR
sheetalkamat Aug 7, 2017
8db05c2
More work on PR feedback update
sheetalkamat Aug 11, 2017
594482d
Merge branch 'master' into watchImprovements
sheetalkamat Aug 12, 2017
d0a23bb
Merge branch 'watchImprovements' into builder
sheetalkamat Aug 12, 2017
59d07dc
Simplified mutate map options
sheetalkamat Aug 14, 2017
9895082
Updating according to feedback from PR
sheetalkamat Aug 14, 2017
f1b1b12
More work based on feedback
sheetalkamat Aug 14, 2017
136b091
Update based on feedback
sheetalkamat Aug 14, 2017
6bf9133
Update to PR feedback
sheetalkamat Aug 14, 2017
a99c04e
Make the failedLookuplocations to be readonly array
sheetalkamat Aug 14, 2017
b66b752
Update based on feedback
sheetalkamat Aug 18, 2017
da0d374
Made updates to not expose methods/types that arent needed.
sheetalkamat Aug 18, 2017
e639ceb
Merge branch 'watchImprovements' into builder
sheetalkamat Aug 18, 2017
8deef58
Remove the unused function from the Project since builder has this lo…
sheetalkamat Aug 18, 2017
c425128
When getting default project from session, get it only if the script …
sheetalkamat Aug 18, 2017
d217bec
Merge branch 'master' into watchImprovements
sheetalkamat Aug 18, 2017
60e2e68
Merge branch 'watchImprovements' into builder
sheetalkamat Aug 18, 2017
84b2e23
More PR feedback work
sheetalkamat Aug 21, 2017
3908325
Merge branch 'watchImprovements' into builder
sheetalkamat Aug 21, 2017
7173da2
Adding test for #16329 to verify the caching of file system when open…
sheetalkamat Aug 18, 2017
e500be2
Adding test for #16456 to verify watched directories in case-sensitiv…
sheetalkamat Aug 19, 2017
6227a36
In Server when polling the file stat's do not send changed event in c…
sheetalkamat Aug 21, 2017
55931c4
Update the failed lookup watches without doing lookups.
sheetalkamat Aug 21, 2017
e65df12
Add test for #16955 which simulates npm install
sheetalkamat Aug 22, 2017
e711238
Add api in builder to get changed files and use it to send project ch…
sheetalkamat Aug 15, 2017
3b85f3f
Add tests to verify project changed event sent
sheetalkamat Aug 22, 2017
ea95f3b
Merge pull request #17820 from Microsoft/tsserverEventChangedFiles
sheetalkamat Aug 31, 2017
9e570c3
Merge pull request #17669 from Microsoft/builder
sheetalkamat Aug 31, 2017
4c79033
Refactoring to watches and caching of system such that we minimize fu…
sheetalkamat Aug 23, 2017
5aafd3f
Reduce number of watches for failed lookup locations as part of modul…
sheetalkamat Aug 23, 2017
17565d8
Handle watches of missing directories and make project the module res…
sheetalkamat Aug 24, 2017
10ea5bf
Script infos while opening/closing shouldnt mark project as dirty if …
sheetalkamat Aug 26, 2017
254e393
Watch failed lookups recursively to reduce number of directory watches
sheetalkamat Aug 28, 2017
a3b9467
Resolve only once in the given directory for name
sheetalkamat Aug 29, 2017
16cf7c4
Watch for the automatic types that included as part of type resolution
sheetalkamat Aug 30, 2017
d7ce95d
Watch node_modules if possible
sheetalkamat Aug 31, 2017
345f36d
Update tests
sheetalkamat Aug 31, 2017
2b97b2c
Print number of files in the project when printing project
sheetalkamat Aug 31, 2017
8d5d4c2
Reduce storage of maps/sets for failed lookups
sheetalkamat Aug 31, 2017
9e5e20c
Remove the configured project if on next open file if it has no open …
sheetalkamat Sep 1, 2017
13aafa2
Update tests
sheetalkamat Sep 1, 2017
6c61293
Test to verify calls to isProgramUptoDate return true when there is n…
sheetalkamat Sep 1, 2017
7b2bab5
Revert to use refcount to keep track of directory watchers for failed…
sheetalkamat Sep 5, 2017
54f64a1
Resolution is valid unless it is invalidated
sheetalkamat Sep 6, 2017
0ff160f
Add files to change set instead of delay reloading project on "change…
sheetalkamat Sep 6, 2017
e6eede1
Update how we get project/script info so that it doesnt start unneces…
sheetalkamat Sep 6, 2017
2a5d954
Reduce the file size for npm install test
sheetalkamat Sep 6, 2017
680994e
Better log for update graph and delay operations
sheetalkamat Sep 6, 2017
c8e711c
Invalidate resolution of the failed lookup only if its one of the def…
sheetalkamat Sep 7, 2017
29e93c3
Update the test cases for project changed event since it doesnt apply…
sheetalkamat Sep 7, 2017
b179cd1
Return configured project being closed by config file
sheetalkamat Sep 7, 2017
67f9533
Limit the resolution invalidation to max number of files as invalidat…
sheetalkamat Sep 8, 2017
de28d02
Add test case to verify correct resolution file is picked when curren…
sheetalkamat Sep 8, 2017
5739b68
Do not create map just to store empty reference files. Also update fi…
sheetalkamat Sep 9, 2017
fdb104b
Merge branch 'master' into watchImprovements
sheetalkamat Sep 11, 2017
aea8630
Merge branch 'master' into watchImprovements
sheetalkamat Sep 12, 2017
b536f9d
Should not remove the reused resolutions in the file when file conten…
sheetalkamat Sep 12, 2017
4f7c0e5
Simplify event sent on background project update since its anyways ju…
sheetalkamat Sep 13, 2017
cf72f2a
Merge branch 'master' into watchImprovements
sheetalkamat Sep 14, 2017
23acff5
Merge branch 'master' into watchImprovements
sheetalkamat Sep 25, 2017
14febe2
Rename watchedProgram.ts to watch.ts
sheetalkamat Sep 26, 2017
38f3a2b
Renamed PartialSystem as DirectoryStructureHost and CachedPartialSyst…
sheetalkamat Sep 26, 2017
68d3605
PR feedback
sheetalkamat Sep 26, 2017
9e08cae
Merge branch 'master' into watchImprovements
sheetalkamat Sep 29, 2017
835153b
PR feedback
sheetalkamat Oct 2, 2017
898559b
Merge branch 'master' into watchImprovements
sheetalkamat Oct 2, 2017
7f969e8
Making APIs as internal so that we can enable them after we have figu…
sheetalkamat Oct 2, 2017
4bb4711
Merge branch 'master' into watchImprovements
sheetalkamat Oct 2, 2017
8ac01d7
Separate namespace declarations in builder of intenal and exported in…
sheetalkamat Oct 3, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ var typesMapOutputPath = path.join(builtLocalDirectory, 'typesMap.json');
var harnessCoreSources = [
"harness.ts",
"virtualFileSystem.ts",
"virtualFileSystemWithWatch.ts",
"sourceMapRecorder.ts",
"harnessLanguageService.ts",
"fourslash.ts",
Expand Down Expand Up @@ -125,14 +126,14 @@ var harnessSources = harnessCoreSources.concat([
"transpile.ts",
"reuseProgramStructure.ts",
"textStorage.ts",
"cachingInServerLSHost.ts",
"moduleResolution.ts",
"tsconfigParsing.ts",
"commandLineParsing.ts",
"configurationExtension.ts",
"convertCompilerOptionsFromJson.ts",
"convertTypeAcquisitionFromJson.ts",
"tsserverProjectSystem.ts",
"tscWatchMode.ts",
"compileOnSave.ts",
"typingsInstaller.ts",
"projectErrors.ts",
Expand All @@ -157,7 +158,6 @@ var harnessSources = harnessCoreSources.concat([
"utilities.ts",
"scriptVersionCache.ts",
"scriptInfo.ts",
"lsHost.ts",
"project.ts",
"typingsCache.ts",
"editorServices.ts",
Expand Down
528 changes: 528 additions & 0 deletions src/compiler/builder.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ namespace ts {
}

function diagnosticName(nameArg: __String | Identifier) {
return typeof nameArg === "string" ? unescapeLeadingUnderscores(nameArg as __String) : declarationNameToString(nameArg as Identifier);
return isString(nameArg) ? unescapeLeadingUnderscores(nameArg as __String) : declarationNameToString(nameArg as Identifier);
}

function isTypeParameterSymbolDeclaredInContainer(symbol: Symbol, container: Node) {
Expand Down
142 changes: 87 additions & 55 deletions src/compiler/commandLineParser.ts

Large diffs are not rendered by default.

257 changes: 245 additions & 12 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,20 @@ namespace ts {
return result;
}

export function flatMapIter<T, U>(iter: Iterator<T>, mapfn: (x: T) => U[] | undefined): U[] {
export function flatMapIter<T, U>(iter: Iterator<T>, mapfn: (x: T) => U | U[] | undefined): U[] {
const result: U[] = [];
while (true) {
const { value, done } = iter.next();
if (done) break;
const res = mapfn(value);
if (res) result.push(...res);
if (res) {
if (isArray(res)) {
result.push(...res);
}
else {
result.push(res);
}
}
}
return result;
}
Expand Down Expand Up @@ -523,6 +530,19 @@ namespace ts {
return result;
}

export function mapDefinedIter<T, U>(iter: Iterator<T>, mapFn: (x: T) => U | undefined): U[] {
const result: U[] = [];
while (true) {
const { value, done } = iter.next();
if (done) break;
const res = mapFn(value);
if (res !== undefined) {
result.push(res);
}
}
return result;
}

/**
* Computes the first matching span of elements and returns a tuple of the first span
* and the remaining elements.
Expand Down Expand Up @@ -766,7 +786,7 @@ namespace ts {
* @param end The offset in `from` at which to stop copying values (non-inclusive).
*/
export function addRange<T>(to: T[] | undefined, from: ReadonlyArray<T> | undefined, start?: number, end?: number): T[] | undefined {
if (from === undefined) return to;
if (from === undefined || from.length === 0) return to;
if (to === undefined) return from.slice(start, end);
start = start === undefined ? 0 : toOffset(from, start);
end = end === undefined ? from.length : toOffset(from, end);
Expand Down Expand Up @@ -1222,6 +1242,13 @@ namespace ts {
return Array.isArray ? Array.isArray(value) : value instanceof Array;
}

/**
* Tests whether a value is string
*/
export function isString(text: any): text is string {
return typeof text === "string";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely a minor slow-down, for no benefit to readability.

Functions that are called with polymorphic arguments are quickly de-optimised. This one is specifically intended to be called with polymorphic arguments, so it's very likely to be de-optimised and become slower than conventional idiomatic typeof === 'string'.

Worth checking with a timed run.

}

export function tryCast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut | undefined {
return value !== undefined && test(value) ? value : undefined;
}
Expand All @@ -1232,7 +1259,13 @@ namespace ts {
}

/** Does nothing. */
export function noop(): void {}
export function noop(): void { }

/** Do nothing and return false */
export function returnFalse(): false { return false; }

/** Do nothing and return true */
export function returnTrue(): true { return true; }

/** Returns its argument. */
export function identity<T>(x: T) { return x; }
Expand Down Expand Up @@ -1476,16 +1509,16 @@ namespace ts {
function compareMessageText(text1: string | DiagnosticMessageChain, text2: string | DiagnosticMessageChain): Comparison {
while (text1 && text2) {
// We still have both chains.
const string1 = typeof text1 === "string" ? text1 : text1.messageText;
const string2 = typeof text2 === "string" ? text2 : text2.messageText;
const string1 = isString(text1) ? text1 : text1.messageText;
const string2 = isString(text2) ? text2 : text2.messageText;

const res = compareValues(string1, string2);
if (res) {
return res;
}

text1 = typeof text1 === "string" ? undefined : text1.next;
text2 = typeof text2 === "string" ? undefined : text2.next;
text1 = isString(text1) ? undefined : text1.next;
text2 = isString(text2) ? undefined : text2.next;
}

if (!text1 && !text2) {
Expand Down Expand Up @@ -1811,6 +1844,8 @@ namespace ts {
* Removes a trailing directory separator from a path.
* @param path The path.
*/
export function removeTrailingDirectorySeparator(path: Path): Path;
export function removeTrailingDirectorySeparator(path: string): string;
export function removeTrailingDirectorySeparator(path: string) {
if (path.charAt(path.length - 1) === directorySeparator) {
return path.substr(0, path.length - 1);
Expand Down Expand Up @@ -2073,8 +2108,8 @@ namespace ts {
}

export interface FileSystemEntries {
files: ReadonlyArray<string>;
directories: ReadonlyArray<string>;
readonly files: ReadonlyArray<string>;
readonly directories: ReadonlyArray<string>;
}

export interface FileMatcherPatterns {
Expand Down Expand Up @@ -2227,7 +2262,7 @@ namespace ts {
return ScriptKind.TS;
case Extension.Tsx:
return ScriptKind.TSX;
case ".json":
case Extension.Json:
return ScriptKind.JSON;
default:
return ScriptKind.Unknown;
Expand Down Expand Up @@ -2631,5 +2666,203 @@ namespace ts {
return (arg: T) => f(arg) && g(arg);
}

export function assertTypeIsNever(_: never): void {}
export function assertTypeIsNever(_: never): void { }

export interface CachedDirectoryStructureHost extends DirectoryStructureHost {
addOrDeleteFileOrDirectory(fileOrDirectory: string, fileOrDirectoryPath: Path): void;
addOrDeleteFile(fileName: string, filePath: Path, eventKind: FileWatcherEventKind): void;
clearCache(): void;
}

interface MutableFileSystemEntries {
readonly files: string[];
readonly directories: string[];
}

export function createCachedDirectoryStructureHost(host: DirectoryStructureHost): CachedDirectoryStructureHost {
const cachedReadDirectoryResult = createMap<MutableFileSystemEntries>();
const getCurrentDirectory = memoize(() => host.getCurrentDirectory());
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames);
return {
useCaseSensitiveFileNames: host.useCaseSensitiveFileNames,
newLine: host.newLine,
readFile: (path, encoding) => host.readFile(path, encoding),
write: s => host.write(s),
writeFile,
fileExists,
directoryExists,
createDirectory,
getCurrentDirectory,
getDirectories,
readDirectory,
addOrDeleteFileOrDirectory,
addOrDeleteFile,
clearCache,
exit: code => host.exit(code)
};

function toPath(fileName: string) {
return ts.toPath(fileName, getCurrentDirectory(), getCanonicalFileName);
}

function getCachedFileSystemEntries(rootDirPath: Path): MutableFileSystemEntries | undefined {
return cachedReadDirectoryResult.get(rootDirPath);
}

function getCachedFileSystemEntriesForBaseDir(path: Path): MutableFileSystemEntries | undefined {
return getCachedFileSystemEntries(getDirectoryPath(path));
}

function getBaseNameOfFileName(fileName: string) {
return getBaseFileName(normalizePath(fileName));
}

function createCachedFileSystemEntries(rootDir: string, rootDirPath: Path) {
const resultFromHost: MutableFileSystemEntries = {
files: map(host.readDirectory(rootDir, /*extensions*/ undefined, /*exclude*/ undefined, /*include*/["*.*"]), getBaseNameOfFileName) || [],
directories: host.getDirectories(rootDir) || []
};

cachedReadDirectoryResult.set(rootDirPath, resultFromHost);
return resultFromHost;
}

/**
* If the readDirectory result was already cached, it returns that
* Otherwise gets result from host and caches it.
* The host request is done under try catch block to avoid caching incorrect result
*/
function tryReadDirectory(rootDir: string, rootDirPath: Path): MutableFileSystemEntries | undefined {
const cachedResult = getCachedFileSystemEntries(rootDirPath);
if (cachedResult) {
return cachedResult;
}

try {
return createCachedFileSystemEntries(rootDir, rootDirPath);
}
catch (_e) {
// If there is exception to read directories, dont cache the result and direct the calls to host
Debug.assert(!cachedReadDirectoryResult.has(rootDirPath));
return undefined;
}
}

function fileNameEqual(name1: string, name2: string) {
return getCanonicalFileName(name1) === getCanonicalFileName(name2);
}

function hasEntry(entries: ReadonlyArray<string>, name: string) {
return some(entries, file => fileNameEqual(file, name));
}

function updateFileSystemEntry(entries: string[], baseName: string, isValid: boolean) {
if (hasEntry(entries, baseName)) {
if (!isValid) {
return filterMutate(entries, entry => !fileNameEqual(entry, baseName));
}
}
else if (isValid) {
return entries.push(baseName);
}
}

function writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void {
const path = toPath(fileName);
const result = getCachedFileSystemEntriesForBaseDir(path);
if (result) {
updateFilesOfFileSystemEntry(result, getBaseNameOfFileName(fileName), /*fileExists*/ true);
}
return host.writeFile(fileName, data, writeByteOrderMark);
}

function fileExists(fileName: string): boolean {
const path = toPath(fileName);
const result = getCachedFileSystemEntriesForBaseDir(path);
return result && hasEntry(result.files, getBaseNameOfFileName(fileName)) ||
host.fileExists(fileName);
}

function directoryExists(dirPath: string): boolean {
const path = toPath(dirPath);
return cachedReadDirectoryResult.has(path) || host.directoryExists(dirPath);
}

function createDirectory(dirPath: string) {
const path = toPath(dirPath);
const result = getCachedFileSystemEntriesForBaseDir(path);
const baseFileName = getBaseNameOfFileName(dirPath);
if (result) {
updateFileSystemEntry(result.directories, baseFileName, /*isValid*/ true);
}
host.createDirectory(dirPath);
}

function getDirectories(rootDir: string): string[] {
const rootDirPath = toPath(rootDir);
const result = tryReadDirectory(rootDir, rootDirPath);
if (result) {
return result.directories.slice();
}
return host.getDirectories(rootDir);
}

function readDirectory(rootDir: string, extensions?: ReadonlyArray<string>, excludes?: ReadonlyArray<string>, includes?: ReadonlyArray<string>, depth?: number): string[] {
const rootDirPath = toPath(rootDir);
const result = tryReadDirectory(rootDir, rootDirPath);
if (result) {
return matchFiles(rootDir, extensions, excludes, includes, host.useCaseSensitiveFileNames, getCurrentDirectory(), depth, getFileSystemEntries);
}
return host.readDirectory(rootDir, extensions, excludes, includes, depth);

function getFileSystemEntries(dir: string) {
const path = toPath(dir);
if (path === rootDirPath) {
return result;
}
return getCachedFileSystemEntries(path) || createCachedFileSystemEntries(dir, path);
}
}

function addOrDeleteFileOrDirectory(fileOrDirectory: string, fileOrDirectoryPath: Path) {
const existingResult = getCachedFileSystemEntries(fileOrDirectoryPath);
if (existingResult) {
// This was a folder already present, remove it if this doesnt exist any more
if (!host.directoryExists(fileOrDirectory)) {
cachedReadDirectoryResult.delete(fileOrDirectoryPath);
}
}
else {
// This was earlier a file (hence not in cached directory contents)
// or we never cached the directory containing it
const parentResult = getCachedFileSystemEntriesForBaseDir(fileOrDirectoryPath);
if (parentResult) {
const baseName = getBaseNameOfFileName(fileOrDirectory);
if (parentResult) {
updateFilesOfFileSystemEntry(parentResult, baseName, host.fileExists(fileOrDirectoryPath));
updateFileSystemEntry(parentResult.directories, baseName, host.directoryExists(fileOrDirectoryPath));
}
}
}
}

function addOrDeleteFile(fileName: string, filePath: Path, eventKind: FileWatcherEventKind) {
if (eventKind === FileWatcherEventKind.Changed) {
return;
}

const parentResult = getCachedFileSystemEntriesForBaseDir(filePath);
if (parentResult) {
updateFilesOfFileSystemEntry(parentResult, getBaseNameOfFileName(fileName), eventKind === FileWatcherEventKind.Created);
}
}

function updateFilesOfFileSystemEntry(parentResult: MutableFileSystemEntries, baseName: string, fileExists: boolean) {
updateFileSystemEntry(parentResult.files, baseName, fileExists);
}

function clearCache() {
cachedReadDirectoryResult.clear();
}
}
}
4 changes: 0 additions & 4 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3090,10 +3090,6 @@
"category": "Message",
"code": 6128
},
"The config file '{0}' found doesn't contain any source files.": {
"category": "Error",
"code": 6129
},
"Resolving real path for '{0}', result '{1}'.": {
"category": "Message",
"code": 6130
Expand Down
Loading