Skip to content

Commit 4170f35

Browse files
authored
Merge pull request microsoft#23239 from Microsoft/skipWatchingTypeCacheInfos
Skip watching script infos in the global type cache location
2 parents 9762598 + 7a0a1f6 commit 4170f35

File tree

7 files changed

+29
-15
lines changed

7 files changed

+29
-15
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

+6-2
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

+11-5
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) {
@@ -548,10 +551,11 @@ namespace ts.server {
548551
else {
549552
if (this.pendingEnsureProjectForOpenFiles) {
550553
this.ensureProjectForOpenFiles();
554+
555+
// Send the event to notify that there were background project updates
556+
// send current list of open files
557+
this.sendProjectsUpdatedInBackgroundEvent();
551558
}
552-
// Send the event to notify that there were background project updates
553-
// send current list of open files
554-
this.sendProjectsUpdatedInBackgroundEvent();
555559
}
556560
});
557561
}
@@ -642,7 +646,6 @@ namespace ts.server {
642646
return undefined;
643647
}
644648
if (isInferredProjectName(projectName)) {
645-
this.ensureProjectStructuresUptoDate();
646649
return findProjectByName(projectName, this.inferredProjects);
647650
}
648651
return this.findExternalProjectByProjectName(projectName) || this.findConfiguredProjectByProjectName(toNormalizedPath(projectName));
@@ -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,

src/server/server.ts

-6
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,6 @@ namespace ts.server {
211211
}
212212
}
213213

214-
// E.g. "12:34:56.789"
215-
function nowString() {
216-
const d = new Date();
217-
return `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`;
218-
}
219-
220214
interface QueuedOperation {
221215
operationId: string;
222216
operation: () => void;

src/server/shared.ts

+8-1
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

+1-1
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

+1
Original file line numberDiff line numberDiff line change
@@ -7934,6 +7934,7 @@ declare namespace ts.server {
79347934
readonly useSingleInferredProject: boolean;
79357935
readonly useInferredProjectPerProjectRoot: boolean;
79367936
readonly typingsInstaller: ITypingsInstaller;
7937+
private readonly globalCacheLocationDirectoryPath;
79377938
readonly throttleWaitMilliseconds?: number;
79387939
private readonly eventHandler?;
79397940
private readonly suppressDiagnosticEvents?;

0 commit comments

Comments
 (0)