Skip to content

Commit

Permalink
Merge pull request microsoft#23239 from Microsoft/skipWatchingTypeCac…
Browse files Browse the repository at this point in the history
…heInfos

Skip watching script infos in the global type cache location
  • Loading branch information
sheetalkamat authored Apr 7, 2018
2 parents 9762598 + 7a0a1f6 commit 4170f35
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,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;
Expand Down
8 changes: 6 additions & 2 deletions src/harness/unittests/typingsInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)", () => {
Expand Down Expand Up @@ -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]);
});
Expand Down Expand Up @@ -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]);
});

Expand Down Expand Up @@ -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]);
});
Expand Down
16 changes: 11 additions & 5 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,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;
private readonly suppressDiagnosticEvents?: boolean;
Expand Down Expand Up @@ -431,6 +432,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) {
Expand Down Expand Up @@ -548,10 +551,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();
}
});
}
Expand Down Expand Up @@ -642,7 +646,6 @@ namespace ts.server {
return undefined;
}
if (isInferredProjectName(projectName)) {
this.ensureProjectStructuresUptoDate();
return findProjectByName(projectName, this.inferredProjects);
}
return this.findExternalProjectByProjectName(projectName) || this.findConfiguredProjectByProjectName(toNormalizedPath(projectName));
Expand Down Expand Up @@ -1738,7 +1741,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,
Expand Down
6 changes: 0 additions & 6 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,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;
Expand Down
9 changes: 8 additions & 1 deletion src/server/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`;
}
}
2 changes: 1 addition & 1 deletion src/server/typingsInstaller/nodeTypingsInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7934,6 +7934,7 @@ declare namespace ts.server {
readonly useSingleInferredProject: boolean;
readonly useInferredProjectPerProjectRoot: boolean;
readonly typingsInstaller: ITypingsInstaller;
private readonly globalCacheLocationDirectoryPath;
readonly throttleWaitMilliseconds?: number;
private readonly eventHandler?;
private readonly suppressDiagnosticEvents?;
Expand Down

0 comments on commit 4170f35

Please sign in to comment.