Skip to content

Commit 435270e

Browse files
authored
reduce set of files being watched, increase polling interval (#12054)
1 parent 7c92057 commit 435270e

File tree

8 files changed

+27
-11
lines changed

8 files changed

+27
-11
lines changed

src/compiler/program.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ namespace ts {
596596
getTypeCount: () => getDiagnosticsProducingTypeChecker().getTypeCount(),
597597
getFileProcessingDiagnostics: () => fileProcessingDiagnostics,
598598
getResolvedTypeReferenceDirectives: () => resolvedTypeReferenceDirectives,
599+
isSourceFileFromExternalLibrary,
599600
dropDiagnosticsProducingTypeChecker
600601
};
601602

@@ -781,13 +782,17 @@ namespace ts {
781782
getSourceFile: program.getSourceFile,
782783
getSourceFileByPath: program.getSourceFileByPath,
783784
getSourceFiles: program.getSourceFiles,
784-
isSourceFileFromExternalLibrary: (file: SourceFile) => !!sourceFilesFoundSearchingNodeModules[file.path],
785+
isSourceFileFromExternalLibrary,
785786
writeFile: writeFileCallback || (
786787
(fileName, data, writeByteOrderMark, onError, sourceFiles) => host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles)),
787788
isEmitBlocked,
788789
};
789790
}
790791

792+
function isSourceFileFromExternalLibrary(file: SourceFile): boolean {
793+
return sourceFilesFoundSearchingNodeModules[file.path];
794+
}
795+
791796
function getDiagnosticsProducingTypeChecker() {
792797
return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ true));
793798
}

src/compiler/sys.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ namespace ts {
1717
readFile(path: string, encoding?: string): string;
1818
getFileSize?(path: string): number;
1919
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
20-
watchFile?(path: string, callback: FileWatcherCallback): FileWatcher;
20+
/**
21+
* @pollingInterval - this parameter is used in polling-based watchers and ignored in watchers that
22+
* use native OS file watching
23+
*/
24+
watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher;
2125
watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher;
2226
resolvePath(path: string): string;
2327
fileExists(path: string): boolean;
@@ -444,15 +448,15 @@ namespace ts {
444448
},
445449
readFile,
446450
writeFile,
447-
watchFile: (fileName, callback) => {
451+
watchFile: (fileName, callback, pollingInterval) => {
448452
if (useNonPollingWatchers) {
449453
const watchedFile = watchedFileSet.addFile(fileName, callback);
450454
return {
451455
close: () => watchedFileSet.removeFile(watchedFile)
452456
};
453457
}
454458
else {
455-
_fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged);
459+
_fs.watchFile(fileName, { persistent: true, interval: pollingInterval || 250 }, fileChanged);
456460
return {
457461
close: () => _fs.unwatchFile(fileName, fileChanged)
458462
};

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,7 @@ namespace ts {
17881788

17891789
/* @internal */ getFileProcessingDiagnostics(): DiagnosticCollection;
17901790
/* @internal */ getResolvedTypeReferenceDirectives(): Map<ResolvedTypeReferenceDirective>;
1791+
/* @internal */ isSourceFileFromExternalLibrary(file: SourceFile): boolean;
17911792
// For testing purposes only.
17921793
/* @internal */ structureIsReused?: boolean;
17931794
}

src/server/project.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ namespace ts.server {
225225
return this.getLanguageService().getEmitOutput(info.fileName, emitOnlyDtsFiles);
226226
}
227227

228-
getFileNames() {
228+
getFileNames(excludeFilesFromExternalLibraries?: boolean) {
229229
if (!this.program) {
230230
return [];
231231
}
@@ -241,8 +241,14 @@ namespace ts.server {
241241
}
242242
return rootFiles;
243243
}
244-
const sourceFiles = this.program.getSourceFiles();
245-
return sourceFiles.map(sourceFile => asNormalizedPath(sourceFile.fileName));
244+
const result: NormalizedPath[] = [];
245+
for (const f of this.program.getSourceFiles()) {
246+
if (excludeFilesFromExternalLibraries && this.program.isSourceFileFromExternalLibrary(f)) {
247+
continue;
248+
}
249+
result.push(asNormalizedPath(f.fileName));
250+
}
251+
return result;
246252
}
247253

248254
getAllEmittableFiles() {

src/server/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ declare namespace ts.server {
6767
export interface InstallTypingHost extends JsTyping.TypingResolutionHost {
6868
writeFile(path: string, content: string): void;
6969
createDirectory(path: string): void;
70-
watchFile?(path: string, callback: FileWatcherCallback): FileWatcher;
70+
watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher;
7171
}
7272
}

src/server/typingsInstaller/typingsInstaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ namespace ts.server.typingsInstaller {
361361
this.sendResponse({ projectName: projectName, kind: server.ActionInvalidate });
362362
isInvoked = true;
363363
}
364-
});
364+
}, /*pollingInterval*/ 2000);
365365
watchers.push(w);
366366
}
367367
this.projectWatchers[projectName] = watchers;

src/server/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace ts.server {
5050
export function createInstallTypingsRequest(project: Project, typingOptions: TypingOptions, cachePath?: string): DiscoverTypings {
5151
return {
5252
projectName: project.getProjectName(),
53-
fileNames: project.getFileNames(),
53+
fileNames: project.getFileNames(/*excludeFilesFromExternalLibraries*/ true),
5454
compilerOptions: project.getCompilerOptions(),
5555
typingOptions,
5656
projectRootPath: getProjectRootPath(project),

src/services/jsTyping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace ts.JsTyping {
7777
exclude = typingOptions.exclude || [];
7878

7979
const possibleSearchDirs = map(fileNames, getDirectoryPath);
80-
if (projectRootPath !== undefined) {
80+
if (projectRootPath) {
8181
possibleSearchDirs.push(projectRootPath);
8282
}
8383
searchDirs = deduplicate(possibleSearchDirs);

0 commit comments

Comments
 (0)