From 9dc3c93fb079716a4684475542c4eff11a551319 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 3 Apr 2018 13:02:27 -0700 Subject: [PATCH 1/4] Add time stamp into the ti log. --- src/server/server.ts | 6 ------ src/server/shared.ts | 9 ++++++++- src/server/typingsInstaller/nodeTypingsInstaller.ts | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/server/server.ts b/src/server/server.ts index c1f7b866803..8b2b4893bd6 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -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; diff --git a/src/server/shared.ts b/src/server/shared.ts index e8b64ce06ec..b46a385106e 100644 --- a/src/server/shared.ts +++ b/src/server/shared.ts @@ -33,4 +33,11 @@ namespace ts.server { ? sys.args[index + 1] : undefined; } -} \ No newline at end of file + + /*@internal*/ + export function nowString() { + // E.g. "12:34:56.789" + const d = new Date(); + return `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`; + } +} diff --git a/src/server/typingsInstaller/nodeTypingsInstaller.ts b/src/server/typingsInstaller/nodeTypingsInstaller.ts index 018dac7ec10..37555bf310b 100644 --- a/src/server/typingsInstaller/nodeTypingsInstaller.ts +++ b/src/server/typingsInstaller/nodeTypingsInstaller.ts @@ -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; From 235e1c5594626446a14d8d8c08b6910d3563e1b0 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 3 Apr 2018 13:12:37 -0700 Subject: [PATCH 2/4] There is no need to ensure project structure when tryiong to get inferred project The project operations will validate if its valid anyways --- src/harness/unittests/typingsInstaller.ts | 5 +++-- src/server/editorServices.ts | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/harness/unittests/typingsInstaller.ts b/src/harness/unittests/typingsInstaller.ts index 0a27f860352..5bf968064f6 100644 --- a/src/harness/unittests/typingsInstaller.ts +++ b/src/harness/unittests/typingsInstaller.ts @@ -188,7 +188,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 +961,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 +1107,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]); }); diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index c46e2fa6875..9251ea6a022 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -633,7 +633,6 @@ namespace ts.server { return undefined; } if (isInferredProjectName(projectName)) { - this.ensureProjectStructuresUptoDate(); return findProjectByName(projectName, this.inferredProjects); } return this.findExternalProjectByProjectName(projectName) || this.findConfiguredProjectByProjectName(toNormalizedPath(projectName)); From c77a9693d1f0f941a9f44b7b6f2eb7dad7aef5c9 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 6 Apr 2018 14:58:13 -0700 Subject: [PATCH 3/4] Do not send project update in background if there was no ensureUpdate pending on the project structure --- src/server/editorServices.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 9251ea6a022..b05d2ab6c95 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -539,10 +539,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(); } }); } From dc3f4c377c1d8c63f97346b795dd150acd416b78 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 6 Apr 2018 15:18:39 -0700 Subject: [PATCH 4/4] Do not watch script infos that are part of global typings location --- src/compiler/core.ts | 2 ++ src/harness/unittests/typingsInstaller.ts | 3 +++ src/server/editorServices.ts | 8 +++++++- tests/baselines/reference/api/tsserverlibrary.d.ts | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 5ca2bcee1d6..4fb85fb36c4 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -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; diff --git a/src/harness/unittests/typingsInstaller.ts b/src/harness/unittests/typingsInstaller.ts index 5bf968064f6..9b874b2aca6 100644 --- a/src/harness/unittests/typingsInstaller.ts +++ b/src/harness/unittests/typingsInstaller.ts @@ -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)", () => { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index b05d2ab6c95..d7b6d814fe5 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -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) { @@ -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, diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index a2f9506dc1c..3e095dba77d 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -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;