Skip to content

Commit 0e0ecbc

Browse files
authored
Merge pull request #23241 from Microsoft/skipWatchingTypeCacheInfos
[release-2.8] Skip watching script infos in the global type cache location
2 parents 7deda06 + dc3f4c3 commit 0e0ecbc

File tree

7 files changed

+29
-15
lines changed

7 files changed

+29
-15
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: 6 additions & 2 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)", () => {
@@ -188,7 +191,7 @@ namespace ts.projectSystem {
188191
checkProjectActualFiles(p, [file1.path]);
189192

190193
installer.installAll(/*expectedCount*/ 1);
191-
194+
host.checkTimeoutQueueLengthAndRun(2);
192195
checkNumberOfProjects(projectService, { inferredProjects: 1 });
193196
checkProjectActualFiles(p, [file1.path, jquery.path]);
194197
});
@@ -961,6 +964,7 @@ namespace ts.projectSystem {
961964
assert.isTrue(host.fileExists(node.path), "typings for 'node' should be created");
962965
assert.isTrue(host.fileExists(commander.path), "typings for 'commander' should be created");
963966

967+
host.checkTimeoutQueueLengthAndRun(2);
964968
checkProjectActualFiles(service.inferredProjects[0], [file.path, node.path, commander.path]);
965969
});
966970

@@ -1106,7 +1110,7 @@ namespace ts.projectSystem {
11061110
checkProjectActualFiles(p, [file1.path]);
11071111

11081112
installer.installAll(/*expectedCount*/ 1);
1109-
1113+
host.checkTimeoutQueueLengthAndRun(2);
11101114
checkNumberOfProjects(projectService, { inferredProjects: 1 });
11111115
checkProjectActualFiles(p, [file1.path, jquery.path]);
11121116
});

src/server/editorServices.ts

Lines changed: 11 additions & 5 deletions
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) {
@@ -539,10 +542,11 @@ namespace ts.server {
539542
else {
540543
if (this.pendingEnsureProjectForOpenFiles) {
541544
this.ensureProjectForOpenFiles();
545+
546+
// Send the event to notify that there were background project updates
547+
// send current list of open files
548+
this.sendProjectsUpdatedInBackgroundEvent();
542549
}
543-
// Send the event to notify that there were background project updates
544-
// send current list of open files
545-
this.sendProjectsUpdatedInBackgroundEvent();
546550
}
547551
});
548552
}
@@ -633,7 +637,6 @@ namespace ts.server {
633637
return undefined;
634638
}
635639
if (isInferredProjectName(projectName)) {
636-
this.ensureProjectStructuresUptoDate();
637640
return findProjectByName(projectName, this.inferredProjects);
638641
}
639642
return this.findExternalProjectByProjectName(projectName) || this.findConfiguredProjectByProjectName(toNormalizedPath(projectName));
@@ -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,

src/server/server.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,6 @@ namespace ts.server {
234234
}
235235
}
236236

237-
// E.g. "12:34:56.789"
238-
function nowString() {
239-
const d = new Date();
240-
return `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`;
241-
}
242-
243237
interface QueuedOperation {
244238
operationId: string;
245239
operation: () => void;

src/server/shared.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,11 @@ namespace ts.server {
3333
? sys.args[index + 1]
3434
: undefined;
3535
}
36-
}
36+
37+
/*@internal*/
38+
export function nowString() {
39+
// E.g. "12:34:56.789"
40+
const d = new Date();
41+
return `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`;
42+
}
43+
}

src/server/typingsInstaller/nodeTypingsInstaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace ts.server.typingsInstaller {
2121
}
2222
writeLine = (text: string) => {
2323
try {
24-
fs.appendFileSync(this.logFile, text + sys.newLine);
24+
fs.appendFileSync(this.logFile, `[${nowString()}] ${text}${sys.newLine}`);
2525
}
2626
catch (e) {
2727
this.logEnabled = false;

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)