Skip to content

Commit 7a0a1f6

Browse files
committed
Do not watch script infos that are part of global typings location
1 parent c9f3995 commit 7a0a1f6

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

src/compiler/core.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,8 @@ namespace ts {
22462246
* Adds a trailing directory separator to a path, if it does not already have one.
22472247
* @param path The path.
22482248
*/
2249+
export function ensureTrailingDirectorySeparator(path: Path): Path;
2250+
export function ensureTrailingDirectorySeparator(path: string): string;
22492251
export function ensureTrailingDirectorySeparator(path: string) {
22502252
if (path.charAt(path.length - 1) !== directorySeparator) {
22512253
return path + directorySeparator;

src/harness/unittests/typingsInstaller.ts

+3
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,15 @@ namespace ts.projectSystem {
141141
checkNumberOfProjects(projectService, { configuredProjects: 1 });
142142
const p = configuredProjectAt(projectService, 0);
143143
checkProjectActualFiles(p, [file1.path, tsconfig.path]);
144+
checkWatchedFiles(host, [tsconfig.path, libFile.path, packageJson.path, "/a/b/bower_components", "/a/b/node_modules"]);
144145

145146
installer.installAll(/*expectedCount*/ 1);
146147

147148
checkNumberOfProjects(projectService, { configuredProjects: 1 });
148149
host.checkTimeoutQueueLengthAndRun(2);
149150
checkProjectActualFiles(p, [file1.path, jquery.path, tsconfig.path]);
151+
// should not watch jquery
152+
checkWatchedFiles(host, [tsconfig.path, libFile.path, packageJson.path, "/a/b/bower_components", "/a/b/node_modules"]);
150153
});
151154

152155
it("inferred project (typings installed)", () => {

src/server/editorServices.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ namespace ts.server {
392392
public readonly useSingleInferredProject: boolean;
393393
public readonly useInferredProjectPerProjectRoot: boolean;
394394
public readonly typingsInstaller: ITypingsInstaller;
395+
private readonly globalCacheLocationDirectoryPath: Path;
395396
public readonly throttleWaitMilliseconds?: number;
396397
private readonly eventHandler?: ProjectServiceEventHandler;
397398
private readonly suppressDiagnosticEvents?: boolean;
@@ -431,6 +432,8 @@ namespace ts.server {
431432
}
432433
this.currentDirectory = this.host.getCurrentDirectory();
433434
this.toCanonicalFileName = createGetCanonicalFileName(this.host.useCaseSensitiveFileNames);
435+
this.globalCacheLocationDirectoryPath = this.typingsInstaller.globalTypingsCacheLocation &&
436+
ensureTrailingDirectorySeparator(this.toPath(this.typingsInstaller.globalTypingsCacheLocation));
434437
this.throttledOperations = new ThrottledOperations(this.host, this.logger);
435438

436439
if (this.typesMapLocation) {
@@ -1738,7 +1741,10 @@ namespace ts.server {
17381741
private watchClosedScriptInfo(info: ScriptInfo) {
17391742
Debug.assert(!info.fileWatcher);
17401743
// do not watch files with mixed content - server doesn't know how to interpret it
1741-
if (!info.isDynamicOrHasMixedContent()) {
1744+
// do not watch files in the global cache location
1745+
if (!info.isDynamicOrHasMixedContent() &&
1746+
(!this.globalCacheLocationDirectoryPath ||
1747+
!startsWith(info.path, this.globalCacheLocationDirectoryPath))) {
17421748
const { fileName } = info;
17431749
info.fileWatcher = this.watchFactory.watchFilePath(
17441750
this.host,

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

+1
Original file line numberDiff line numberDiff line change
@@ -7930,6 +7930,7 @@ declare namespace ts.server {
79307930
readonly useSingleInferredProject: boolean;
79317931
readonly useInferredProjectPerProjectRoot: boolean;
79327932
readonly typingsInstaller: ITypingsInstaller;
7933+
private readonly globalCacheLocationDirectoryPath;
79337934
readonly throttleWaitMilliseconds?: number;
79347935
private readonly eventHandler?;
79357936
private readonly suppressDiagnosticEvents?;

0 commit comments

Comments
 (0)