From e9258b8a2cd87cb37dd5772476613c7331bb6673 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 29 Nov 2016 19:44:20 -0800 Subject: [PATCH 1/4] Reset the noEmitForJsFiles option when updating compiler options --- src/server/project.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/server/project.ts b/src/server/project.ts index c28b29b944b44..275817fe874ad 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -636,6 +636,9 @@ namespace ts.server { this.cachedUnresolvedImportsPerFile.clear(); this.lastCachedUnresolvedImportsList = undefined; } + if (this.projectKind === ProjectKind.Inferred || this.projectKind === ProjectKind.Configured) { + compilerOptions.noEmitForJsFiles = true; + } this.compilerOptions = compilerOptions; this.lsHost.setCompilationSettings(compilerOptions); From b0c8a19d5767c6b30389209dc78df8cf9e7faa92 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 29 Nov 2016 20:25:26 -0800 Subject: [PATCH 2/4] add tests and remove duplicates --- .../unittests/tsserverProjectSystem.ts | 59 +++++++++++++++++++ src/server/project.ts | 14 +++-- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 368d2a660d4e5..deb4dee47fe5b 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -2728,6 +2728,65 @@ namespace ts.projectSystem { arguments: { projectFileName: projectName } }).response; assert.isTrue(diags.length === 0); + + session.executeCommand({ + type: "request", + command: server.CommandNames.CompilerOptionsForInferredProjects, + seq: 3, + arguments: { options: { module: ModuleKind.CommonJS } } + }); + const diagsAfterUpdate = session.executeCommand({ + type: "request", + command: server.CommandNames.CompilerOptionsDiagnosticsFull, + seq: 3, + arguments: { projectFileName: projectName } + }).response; + assert.isTrue(diagsAfterUpdate.length === 0); + }); + + it("for external project", () => { + const f1 = { + path: "/a/b/f1.js", + content: "function test1() { }" + }; + const host = createServerHost([f1, libFile]); + const session = createSession(host); + const projectService = session.getProjectService(); + const projectFileName = "/a/b/project.csproj"; + const externalFiles = toExternalFiles([f1.path]); + projectService.openExternalProject({ + projectFileName, + rootFiles: externalFiles, + options: {} + }); + + checkNumberOfProjects(projectService, { externalProjects: 1 }); + + const diags = session.executeCommand({ + type: "request", + command: server.CommandNames.CompilerOptionsDiagnosticsFull, + seq: 2, + arguments: { projectFileName } + }).response; + assert.isTrue(diags.length === 0); + + session.executeCommand({ + type: "request", + command: server.CommandNames.OpenExternalProject, + seq: 3, + arguments: { + projectFileName, + rootFiles: externalFiles, + options: { module: ModuleKind.CommonJS } + } + }); + const diagsAfterUpdate = session.executeCommand({ + type: "request", + command: server.CommandNames.CompilerOptionsDiagnosticsFull, + seq: 3, + arguments: { projectFileName } + }).response; + assert.isTrue(diagsAfterUpdate.length === 0); }); }); diff --git a/src/server/project.ts b/src/server/project.ts index 275817fe874ad..b1706d8f6fdb3 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -248,9 +248,7 @@ namespace ts.server { this.compilerOptions.allowNonTsExtensions = true; } - if (this.projectKind === ProjectKind.Inferred || this.projectKind === ProjectKind.External) { - this.compilerOptions.noEmitForJsFiles = true; - } + this.setInternalCompilerOptionsForEmittingJsFiles(); this.lsHost = new LSHost(this.projectService.host, this, this.projectService.cancellationToken); this.lsHost.setCompilationSettings(this.compilerOptions); @@ -266,6 +264,12 @@ namespace ts.server { this.markAsDirty(); } + setInternalCompilerOptionsForEmittingJsFiles() { + if (this.projectKind === ProjectKind.Inferred || this.projectKind === ProjectKind.External) { + this.compilerOptions.noEmitForJsFiles = true; + } + } + getProjectErrors() { return this.projectErrors; } @@ -636,10 +640,8 @@ namespace ts.server { this.cachedUnresolvedImportsPerFile.clear(); this.lastCachedUnresolvedImportsList = undefined; } - if (this.projectKind === ProjectKind.Inferred || this.projectKind === ProjectKind.Configured) { - compilerOptions.noEmitForJsFiles = true; - } this.compilerOptions = compilerOptions; + this.setInternalCompilerOptionsForEmittingJsFiles(); this.lsHost.setCompilationSettings(compilerOptions); this.markAsDirty(); From e9eb1f43e0801b7b08e9d1caff08c9524889bf18 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 29 Nov 2016 21:03:41 -0800 Subject: [PATCH 3/4] Change test req number --- src/harness/unittests/tsserverProjectSystem.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index deb4dee47fe5b..3e9fd7a70e4da 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -2738,7 +2738,7 @@ namespace ts.projectSystem { const diagsAfterUpdate = session.executeCommand({ type: "request", command: server.CommandNames.CompilerOptionsDiagnosticsFull, - seq: 3, + seq: 4, arguments: { projectFileName: projectName } }).response; assert.isTrue(diagsAfterUpdate.length === 0); @@ -2783,7 +2783,7 @@ namespace ts.projectSystem { const diagsAfterUpdate = session.executeCommand({ type: "request", command: server.CommandNames.CompilerOptionsDiagnosticsFull, - seq: 3, + seq: 4, arguments: { projectFileName } }).response; assert.isTrue(diagsAfterUpdate.length === 0); From 165211ddde7f275320692b1ecec65e23596aca4e Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 29 Nov 2016 22:00:02 -0800 Subject: [PATCH 4/4] make setInternalCompilerOptionsForEmittingJsFiles private --- src/server/project.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/project.ts b/src/server/project.ts index b1706d8f6fdb3..049f61269f886 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -264,7 +264,7 @@ namespace ts.server { this.markAsDirty(); } - setInternalCompilerOptionsForEmittingJsFiles() { + private setInternalCompilerOptionsForEmittingJsFiles() { if (this.projectKind === ProjectKind.Inferred || this.projectKind === ProjectKind.External) { this.compilerOptions.noEmitForJsFiles = true; }