Skip to content

Commit dc3f4c3

Browse files
committed
Do not watch script infos that are part of global typings location
1 parent c77a969 commit dc3f4c3

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

src/compiler/core.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,8 @@ namespace ts {
22582258
* Adds a trailing directory separator to a path, if it does not already have one.
22592259
* @param path The path.
22602260
*/
2261+
export function ensureTrailingDirectorySeparator(path: Path): Path;
2262+
export function ensureTrailingDirectorySeparator(path: string): string;
22612263
export function ensureTrailingDirectorySeparator(path: string) {
22622264
if (path.charAt(path.length - 1) !== directorySeparator) {
22632265
return path + directorySeparator;

src/harness/unittests/typingsInstaller.ts

Lines changed: 3 additions & 0 deletions
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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ namespace ts.server {
389389
public readonly useSingleInferredProject: boolean;
390390
public readonly useInferredProjectPerProjectRoot: boolean;
391391
public readonly typingsInstaller: ITypingsInstaller;
392+
private readonly globalCacheLocationDirectoryPath: Path;
392393
public readonly throttleWaitMilliseconds?: number;
393394
private readonly eventHandler?: ProjectServiceEventHandler;
394395

@@ -423,6 +424,8 @@ namespace ts.server {
423424
}
424425
this.currentDirectory = this.host.getCurrentDirectory();
425426
this.toCanonicalFileName = createGetCanonicalFileName(this.host.useCaseSensitiveFileNames);
427+
this.globalCacheLocationDirectoryPath = this.typingsInstaller.globalTypingsCacheLocation &&
428+
ensureTrailingDirectorySeparator(this.toPath(this.typingsInstaller.globalTypingsCacheLocation));
426429
this.throttledOperations = new ThrottledOperations(this.host, this.logger);
427430

428431
if (this.typesMapLocation) {
@@ -1725,7 +1728,10 @@ namespace ts.server {
17251728
private watchClosedScriptInfo(info: ScriptInfo) {
17261729
Debug.assert(!info.fileWatcher);
17271730
// do not watch files with mixed content - server doesn't know how to interpret it
1728-
if (!info.isDynamicOrHasMixedContent()) {
1731+
// do not watch files in the global cache location
1732+
if (!info.isDynamicOrHasMixedContent() &&
1733+
(!this.globalCacheLocationDirectoryPath ||
1734+
!startsWith(info.path, this.globalCacheLocationDirectoryPath))) {
17291735
const { fileName } = info;
17301736
info.fileWatcher = this.watchFactory.watchFilePath(
17311737
this.host,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7847,6 +7847,7 @@ declare namespace ts.server {
78477847
readonly useSingleInferredProject: boolean;
78487848
readonly useInferredProjectPerProjectRoot: boolean;
78497849
readonly typingsInstaller: ITypingsInstaller;
7850+
private readonly globalCacheLocationDirectoryPath;
78507851
readonly throttleWaitMilliseconds?: number;
78517852
private readonly eventHandler?;
78527853
readonly globalPlugins: ReadonlyArray<string>;

0 commit comments

Comments
 (0)