8000 Watch improvements in tsserver by sheetalkamat · Pull Request #17269 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

Watch improvements in tsserver #17269

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

Merged
merged 128 commits into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Resolve only once in the given directory for name
  • Loading branch information
sheetalkamat committed Aug 31, 2017
commit a3b9467d4159ac0d3ff833149ad1517e249598c8
104 changes: 81 additions & 23 deletions src/compiler/resolutionCache.ts
< 8000 td id="diff-cb9561c40fa7f1bbefdfa8fa029b8e3d8e07908806ddcb1518f2b69be43e45ceL14" data-line-number="14" class="blob-num blob-num-context js-linkable-line-number">
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace ts {
invalidateResolutionOfFile(filePath: Path): void;
createHasInvalidatedResolution(): HasInvalidatedResolution;

startCachingPerDirectoryResolution(): void;
Copy link

Choose a reason for hiding this comment

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

I would prefer a singe method taking a callback, using try-finally to ensure that needed cleanup happens.

finishCachingPerDirectoryResolution(): void;

setRootDirectory(dir: string): void;

clear(): void;
Expand All @@ -28,7 +31,7 @@ namespace ts {
/** watcher for the directory of failed lookup */
watcher: FileWatcher;
/** map with key being the failed lookup location path and value being the actual location */
mapLocations: MultiMap<string>;
mapLocations: Map<number>;
}

export interface ResolutionCacheHost extends ModuleResolutionHost {
Expand All @@ -39,6 +42,7 @@ namespace ts {
getCachedPartialSystem?(): CachedPartialSystem;
projectName?: string;
getGlobalCache?(): string | undefined;
writeLog(s: string): void;
}

const MAX_DIRPATHS_TO_RECURSE = 5;
Expand All @@ -51,7 +55,9 @@ namespace ts {
// The key in the map is source file's path.
// The values are Map of resolutions with key being name lookedup.
const resolvedModuleNames = createMap<Map<ResolvedModuleWithFailedLookupLocations>>();
const perDirectoryResolvedModuleNames = createMap<Map<ResolvedModuleWithFailedLookupLocations>>();
const resolvedTypeReferenceDirectives = createMap<Map<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>>();
const perDirectoryResolvedTypeReferenceDirectives = createMap<Map<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>>();

const directoryWatchesOfFailedLookups = createMap<DirectoryWatchesOfFailedLookup>();
const failedLookupLocationToDirPath = createMap<Path>();
Expand All @@ -60,6 +66,8 @@ namespace ts {
return {
startRecordingFilesWithChangedResolutions,
finishRecordingFilesWithChangedResolutions,
startCachingPerDirectoryResolution,
finishCachingPerDirectoryResolution,
resolveModuleNames,
resolveTypeReferenceDirectives,
invalidateResolutionOfFile,
Expand Down Expand Up @@ -87,6 +95,7 @@ namespace ts {
failedLookupLocationToDirPath.clear();
resolvedModuleNames.clear();
resolvedTypeReferenceDirectives.clear();
Debug.assert(perDirectoryResolvedModuleNames.size === 0 && perDirectoryResolvedTypeReferenceDirectives.size === 0);
}

function startRecordingFilesWithChangedResolutions() {
Expand All @@ -105,6 +114,15 @@ namespace ts {
return path => collected && collected.has(path);
}

function startCachingPerDirectoryResolution() {
Debug.assert(perDirectoryResolvedModuleNames.size === 0 && perDirectoryResolvedTypeReferenceDirectives.size === 0);
}

function finishCachingPerDirectoryResolution() {
perDirectoryResolvedModuleNames.clear();
perDirectoryResolvedTypeReferenceDirectives.clear();
}

function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations {
const primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host 6D40 );
// return result immediately only if global cache support is not enabled or if it is .ts, .tsx or .d.ts
Expand All @@ -131,13 +149,20 @@ namespace ts {
names: string[],
containingFile: string,
cache: Map<Map<T>>,
perDirectoryCache: Map<Map<T>>,
loader: (name: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost) => T,
getResult: (s: T) => R,
getResultFileName: (result: R) => string | undefined,
logChanges: boolean): R[] {

const path = resolutionHost.toPath(containingFile);
const currentResolutionsInFile = cache.get(path);
const dirPath = getDirectoryPath(path);
let perDirectoryResolution = perDirectoryCache.get(dirPath);
if (!perDirectoryResolution) {
perDirectoryResolution = createMap();
perDirectoryCache.set(dirPath, perDirectoryResolution);
}

const newResolutions: Map<T> = createMap<T>();
const resolvedModules: R[] = [];
Expand All @@ -148,12 +173,24 @@ namespace ts {
let resolution = newResolutions.get(name);
if (!resolution) {
const existingResolution = currentResolutionsInFile && currentResolutionsInFile.get(name);
if (existingResolution) {
// Remove from the cache since we would update the resolution in new file ourselves
currentResolutionsInFile.delete(name);
}

if (moduleResolutionIsValid(existingResolution)) {
// ok, it is safe to use existing name resolution results
resolution = existingResolution;
}
else {
resolution = loader(name, containingFile, compilerOptions, resolutionHost);
const resolutionInDirectory = perDirectoryResolution && perDirectoryResolution.get(name);
if (resolutionInDirectory) {
resolution = resolutionInDirectory;
}
else {
resolution = loader(name, containingFile, compilerOptions, resolutionHost);
perDirectoryResolution.set(name, resolution);
}
updateFailedLookupLocationWatches(resolution.failedLookupLocations, existingResolution && existingResolution.failedLookupLocations);
}
newResolutions.set(name, resolution);
Expand All @@ -169,6 +206,11 @@ namespace ts {
resolvedModules.push(getResult(resolution));
}

// Close all the file watchers for the names that arent required any more
if (currentResolutionsInFile) {
clearMap(currentResolutionsInFile, resolution => withFailedLookupLocations(resolution.failedLookupLocations, closeFailedLookupLocationWatcher));
}

// replace old results with a new one
cache.set(path, newResolutions);
return resolvedModules;
Expand Down Expand Up @@ -208,25 +250,35 @@ namespace ts {
}

function resolveTypeReferenceDirectives(typeDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[] {
return resolveNamesWithLocalCache(typeDirectiveNames, containingFile, resolvedTypeReferenceDirectives, resolveTypeReferenceDirective,
m => m.resolvedTypeReferenceDirective, r => r.resolvedFileName, /*logChanges*/ false);
resolutionHost.writeLog(`resolveTypeReferenceDirectives: ${typeDirectiveNames} in ${containingFile}`);
return resolveNamesWithLocalCache(
typeDirectiveNames, containingFile,
resolvedTypeReferenceDirectives, perDirectoryResolvedTypeReferenceDirectives,
resolveTypeReferenceDirective, m => m.resolvedTypeReferenceDirective, r => r.resolvedFileName,
/*logChanges*/ false
);
}

function resolveModuleNames(moduleNames: string[], containingFile: string, logChanges: boolean): ResolvedModuleFull[] {
return resolveNamesWithLocalCache(moduleNames, containingFile, resolvedModuleNames, resolveModuleName,
m => m.resolvedModule, r => r.resolvedFileName, logChanges);
resolutionHost.writeLog(`resolveModuleNames: ${moduleNames} in ${containingFile}`);
return resolveNamesWithLocalCache(
moduleNames, containingFile,
resolvedModuleNames, perDirectoryResolvedModuleNames,
resolveModuleName, m => m.resolvedModule, r => r.resolvedFileName,
logChanges
);
}

function watchFailedLookupLocation(failedLookupLocation: string, failedLookupLocationPath: Path) {
const cachedDir = failedLookupLocationToDirPath.get(failedLookupLocationPath);
if (cachedDir) {
watchFailedLookupLocationInDirectory(cachedDir, failedLookupLocation, failedLookupLocationPath, /*dir*/ undefined);
watchFailedLookupLocationInDirectory(cachedDir, failedLookupLocationPath, /*dir*/ undefined);
return;
}

if (isInDirectoryPath(rootPath, failedLookupLocationPath)) {
// Watch in directory of rootPath
watchFailedLookupLocationInDirectory(rootPath, failedLookupLocation, failedLookupLocationPath, rootDir);
watchFailedLookupLocationInDirectory(rootPath, failedLookupLocationPath, rootDir);
return;
}

Expand All @@ -235,7 +287,7 @@ namespace ts {
for (let i = 0; i < MAX_DIRPATHS_TO_RECURSE; i++) {
const parentPath = getDirectoryPath(dirPath);
if (directoryWatchesOfFailedLookups.has(dirPath) || parentPath === dirPath) {
watchFailedLookupLocationInDirectory(dirPath, failedLookupLocation, failedLookupLocationPath, dir);
watchFailedLookupLocationInDirectory(dirPath, failedLookupLocationPath, dir);
return;
}
dirPath = parentPath;
Expand All @@ -245,7 +297,7 @@ namespace ts {
// Verify there are no watches in parent directory
const ancestorDirPath = getAncestorDirectoryWithWatches(dirPath);
// We wont need directory if we are using ancestor since its already cached
watchFailedLookupLocationInDirectory(ancestorDirPath || dirPath, failedLookupLocation, failedLookupLocationPath, dir);
watchFailedLookupLocationInDirectory(ancestorDirPath || dirPath, failedLookupLocationPath, dir);
}

function getAncestorDirectoryWithWatches(dirPath: Path) {
Expand All @@ -258,16 +310,17 @@ namespace ts {
return undefined;
}

function watchFailedLookupLocationInDirectory(dirPath: Path, failedLookupLocation: string, failedLookupLocationPath: Path, dir: string | undefined) {
function watchFailedLookupLocationInDirectory(dirPath: Path, failedLookupLocationPath: Path, dir: string | undefined) {
failedLookupLocationToDirPath.set(failedLookupLocationPath, dirPath);
const watches = directoryWatchesOfFailedLookups.get(dirPath);
if (watches) {
watches.mapLocations.add(failedLookupLocationPath, failedLookupLocation);
const existingCount = watches.mapLocations.get(failedLookupLocationPath) || 0;
watches.mapLocations.set(failedLookupLocationPath, existingCount + 1);
}
else {
Debug.assert(dir !== undefined);
const mapLocations = createMultiMap<string>();
mapLocations.add(failedLookupLocationPath, failedLookupLocation);
const mapLocations = createMap<number>();
mapLocations.set(failedLookupLocationPath, 1);
directoryWatchesOfFailedLookups.set(dirPath, {
watcher: createDirectoryWatcher(dir, dirPath),
mapLocations
Expand All @@ -294,19 +347,24 @@ namespace ts {
}, WatchDirectoryFlags.Recursive);
}

function closeFailedLookupLocationWatcher(failedLookupLocation: string, failedLookupLocationPath: Path) {
function closeFailedLookupLocationWatcher(_failedLookupLocation: string, failedLookupLocationPath: Path) {
const dirPath = failedLookupLocationToDirPath.get(failedLookupLocationPath);
const watches = directoryWatchesOfFailedLookups.get(dirPath);
watches.mapLocations.remove(failedLookupLocationPath, failedLookupLocation);
// If this was last failed lookup location being tracked by the dir watcher,
// remove the failed lookup location path to dir Path entry
if (!watches.mapLocations.has(failedLookupLocationPath)) {
const refCount = watches.mapLocations.get(failedLookupLocationPath);
if (refCount === 1) {
// If this was last failed lookup location being tracked by the dir watcher,
// remove the failed lookup location path to dir Path entry
watches.mapLocations.delete(failedLookupLocationPath);
failedLookupLocationToDirPath.delete(failedLookupLocationPath);

// If there are no more files that need this watcher alive, close the watcher
if (watches.mapLocations.size === 0) {
watches.watcher.close();
directoryWatchesOfFailedLookups.delete(dirPath);
}
}
// If there are no more files that need this watcher alive, close the watcher
if (watches.mapLocations.size === 0) {
watches.watcher.close();
directoryWatchesOfFailedLookups.delete(dirPath);
else {
watches.mapLocations.set(failedLookupLocationPath, refCount - 1);
Copy link

Choose a reason for hiding this comment

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

Might want to Debug.assert(refCount > 1);.

}
}

Expand Down
5 changes: 4 additions & 1 deletion src/compiler/watchedProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ namespace ts {
getCompilationSettings: () => compilerOptions,
watchDirectoryOfFailedLookupLocation,
getCachedPartialSystem,
onInvalidatedResolution: scheduleProgramUpdate
onInvalidatedResolution: scheduleProgramUpdate,
writeLog
};
// Cache for the module resolution
const resolutionCache = createResolutionCache(compilerHost);
Expand Down Expand Up @@ -330,8 +331,10 @@ namespace ts {
beforeCompile(compilerOptions);

// Compile the program
resolutionCache.startCachingPerDirectoryResolution();
compilerHost.hasInvalidatedResolution = hasInvalidatedResolution;
program = createProgram(rootFileNames, compilerOptions, compilerHost, program);
resolutionCache.finishCachingPerDirectoryResolution();
builder.onProgramUpdateGraph(program, hasInvalidatedResolution);

// Update watches
Expand Down
12 changes: 12 additions & 0 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ namespace ts.server {
return this.getTypeAcquisition().enable ? this.projectService.typingsInstaller.globalTypingsCacheLocation : undefined;
}

/*@internal*/
writeLog(s: string) {
this.projectService.logger.info(s);
}

private setInternalCompilerOptionsForEmittingJsFiles() {
if (this.projectKind === ProjectKind.Inferred || this.projectKind === ProjectKind.External) {
this.compilerOptions.noEmitForJsFiles = true;
Expand Do 8777 wn Expand Up @@ -767,7 +772,10 @@ namespace ts.server {

private updateGraphWorker() {
const oldProgram = this.program;

this.resolutionCache.startCachingPerDirectoryResolution();
this.program = this.languageService.getProgram();
this.resolutionCache.finishCachingPerDirectoryResolution();

// bump up the version if
// - oldProgram is not set - this is a first time updateGraph is called
Expand Down Expand Up @@ -795,6 +803,10 @@ namespace ts.server {
// Watch the missing files
missingFilePath => this.addMissingFileWatcher(missingFilePath)
);

// Update typeRoots watch
// Watch the type locations that would be added to program as part of automatic type resolutions
// TODO
}

const oldExternalFiles = this.externalFiles || emptyArray as SortedReadonlyArray<string>;
Expand Down
0