Merge pull request #23241 from Microsoft/skipWatchingTypeCacheInfos

[release-2.8] Skip watching script infos in the global type cache location
This commit is contained in:
Sheetal Nandi 2018-04-09 11:31:06 -07:00 committed by GitHub
commit 0e0ecbcef5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 15 deletions

View File

@ -2258,6 +2258,8 @@ namespace ts {
* Adds a trailing directory separator to a path, if it does not already have one.
* @param path The path.
*/
export function ensureTrailingDirectorySeparator(path: Path): Path;
export function ensureTrailingDirectorySeparator(path: string): string;
export function ensureTrailingDirectorySeparator(path: string) {
if (path.charAt(path.length - 1) !== directorySeparator) {
return path + directorySeparator;

View File

@ -141,12 +141,15 @@ namespace ts.projectSystem {
checkNumberOfProjects(projectService, { configuredProjects: 1 });
const p = configuredProjectAt(projectService, 0);
checkProjectActualFiles(p, [file1.path, tsconfig.path]);
checkWatchedFiles(host, [tsconfig.path, libFile.path, packageJson.path, "/a/b/bower_components", "/a/b/node_modules"]);
installer.installAll(/*expectedCount*/ 1);
checkNumberOfProjects(projectService, { configuredProjects: 1 });
host.checkTimeoutQueueLengthAndRun(2);
checkProjectActualFiles(p, [file1.path, jquery.path, tsconfig.path]);
// should not watch jquery
checkWatchedFiles(host, [tsconfig.path, libFile.path, packageJson.path, "/a/b/bower_components", "/a/b/node_modules"]);
});
it("inferred project (typings installed)", () => {
@ -188,7 +191,7 @@ namespace ts.projectSystem {
checkProjectActualFiles(p, [file1.path]);
installer.installAll(/*expectedCount*/ 1);
host.checkTimeoutQueueLengthAndRun(2);
checkNumberOfProjects(projectService, { inferredProjects: 1 });
checkProjectActualFiles(p, [file1.path, jquery.path]);
});
@ -961,6 +964,7 @@ namespace ts.projectSystem {
assert.isTrue(host.fileExists(node.path), "typings for 'node' should be created");
assert.isTrue(host.fileExists(commander.path), "typings for 'commander' should be created");
host.checkTimeoutQueueLengthAndRun(2);
checkProjectActualFiles(service.inferredProjects[0], [file.path, node.path, commander.path]);
});
@ -1106,7 +1110,7 @@ namespace ts.projectSystem {
checkProjectActualFiles(p, [file1.path]);
installer.installAll(/*expectedCount*/ 1);
host.checkTimeoutQueueLengthAndRun(2);
checkNumberOfProjects(projectService, { inferredProjects: 1 });
checkProjectActualFiles(p, [file1.path, jquery.path]);
});

View File

@ -389,6 +389,7 @@ namespace ts.server {
public readonly useSingleInferredProject: boolean;
public readonly useInferredProjectPerProjectRoot: boolean;
public readonly typingsInstaller: ITypingsInstaller;
private readonly globalCacheLocationDirectoryPath: Path;
public readonly throttleWaitMilliseconds?: number;
private readonly eventHandler?: ProjectServiceEventHandler;
@ -423,6 +424,8 @@ namespace ts.server {
}
this.currentDirectory = this.host.getCurrentDirectory();
this.toCanonicalFileName = createGetCanonicalFileName(this.host.useCaseSensitiveFileNames);
this.globalCacheLocationDirectoryPath = this.typingsInstaller.globalTypingsCacheLocation &&
ensureTrailingDirectorySeparator(this.toPath(this.typingsInstaller.globalTypingsCacheLocation));
this.throttledOperations = new ThrottledOperations(this.host, this.logger);
if (this.typesMapLocation) {
@ -539,10 +542,11 @@ namespace ts.server {
else {
if (this.pendingEnsureProjectForOpenFiles) {
this.ensureProjectForOpenFiles();
// Send the event to notify that there were background project updates
// send current list of open files
this.sendProjectsUpdatedInBackgroundEvent();
}
// Send the event to notify that there were background project updates
// send current list of open files
this.sendProjectsUpdatedInBackgroundEvent();
}
});
}
@ -633,7 +637,6 @@ namespace ts.server {
return undefined;
}
if (isInferredProjectName(projectName)) {
this.ensureProjectStructuresUptoDate();
return findProjectByName(projectName, this.inferredProjects);
}
return this.findExternalProjectByProjectName(projectName) || this.findConfiguredProjectByProjectName(toNormalizedPath(projectName));
@ -1725,7 +1728,10 @@ namespace ts.server {
private watchClosedScriptInfo(info: ScriptInfo) {
Debug.assert(!info.fileWatcher);
// do not watch files with mixed content - server doesn't know how to interpret it
if (!info.isDynamicOrHasMixedContent()) {
// do not watch files in the global cache location
if (!info.isDynamicOrHasMixedContent() &&
(!this.globalCacheLocationDirectoryPath ||
!startsWith(info.path, this.globalCacheLocationDirectoryPath))) {
const { fileName } = info;
info.fileWatcher = this.watchFactory.watchFilePath(
this.host,

View File

@ -234,12 +234,6 @@ namespace ts.server {
}
}
// E.g. "12:34:56.789"
function nowString() {
const d = new Date();
return `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`;
}
interface QueuedOperation {
operationId: string;
operation: () => void;

View File

@ -33,4 +33,11 @@ namespace ts.server {
? sys.args[index + 1]
: undefined;
}
}
/*@internal*/
export function nowString() {
// E.g. "12:34:56.789"
const d = new Date();
return `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`;
}
}

View File

@ -21,7 +21,7 @@ namespace ts.server.typingsInstaller {
}
writeLine = (text: string) => {
try {
fs.appendFileSync(this.logFile, text + sys.newLine);
fs.appendFileSync(this.logFile, `[${nowString()}] ${text}${sys.newLine}`);
}
catch (e) {
this.logEnabled = false;

View File

@ -7847,6 +7847,7 @@ declare namespace ts.server {
readonly useSingleInferredProject: boolean;
readonly useInferredProjectPerProjectRoot: boolean;
readonly typingsInstaller: ITypingsInstaller;
private readonly globalCacheLocationDirectoryPath;
readonly throttleWaitMilliseconds?: number;
private readonly eventHandler?;
readonly globalPlugins: ReadonlyArray<string>;