Skip to content

Commit 3375fed

Browse files
committed
Reset the noEmitForJsFiles option when updating compiler options (#12570)
1 parent 5108285 commit 3375fed

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,6 +2729,65 @@ namespace ts.projectSystem {
27292729
arguments: { projectFileName: projectName }
27302730
}).response;
27312731
assert.isTrue(diags.length === 0);
2732+
2733+
session.executeCommand(<server.protocol.SetCompilerOptionsForInferredProjectsRequest>{
2734+
type: "request",
2735+
command: server.CommandNames.CompilerOptionsForInferredProjects,
2736+
seq: 3,
2737+
arguments: { options: { module: ModuleKind.CommonJS } }
2738+
});
2739+
const diagsAfterUpdate = session.executeCommand(<server.protocol.CompilerOptionsDiagnosticsRequest>{
2740+
type: "request",
2741+
command: server.CommandNames.CompilerOptionsDiagnosticsFull,
2742+
seq: 4,
2743+
arguments: { projectFileName: projectName }
2744+
}).response;
2745+
assert.isTrue(diagsAfterUpdate.length === 0);
2746+
});
2747+
2748+
it("for external project", () => {
2749+
const f1 = {
2750+
path: "/a/b/f1.js",
2751+
content: "function test1() { }"
2752+
};
2753+
const host = createServerHost([f1, libFile]);
2754+
const session = createSession(host);
2755+
const projectService = session.getProjectService();
2756+
const projectFileName = "/a/b/project.csproj";
2757+
const externalFiles = toExternalFiles([f1.path]);
2758+
projectService.openExternalProject(<protocol.ExternalProject>{
2759+
projectFileName,
2760+
rootFiles: externalFiles,
2761+
options: {}
2762+
});
2763+
2764+
checkNumberOfProjects(projectService, { externalProjects: 1 });
2765+
2766+
const diags = session.executeCommand(<server.protocol.CompilerOptionsDiagnosticsRequest>{
2767+
type: "request",
2768+
command: server.CommandNames.CompilerOptionsDiagnosticsFull,
2769+
seq: 2,
2770+
arguments: { projectFileName }
2771+
}).response;
2772+
assert.isTrue(diags.length === 0);
2773+
2774+
session.executeCommand(<server.protocol.OpenExternalProjectRequest>{
2775+
type: "request",
2776+
command: server.CommandNames.OpenExternalProject,
2777+
seq: 3,
2778+
arguments: {
2779+
projectFileName,
2780+
rootFiles: externalFiles,
2781+
options: { module: ModuleKind.CommonJS }
2782+
}
2783+
});
2784+
const diagsAfterUpdate = session.executeCommand(<server.protocol.CompilerOptionsDiagnosticsRequest>{
2785+
type: "request",
2786+
command: server.CommandNames.CompilerOptionsDiagnosticsFull,
2787+
seq: 4,
2788+
arguments: { projectFileName }
2789+
}).response;
2790+
assert.isTrue(diagsAfterUpdate.length === 0);
27322791
});
27332792
});
27342793

src/server/project.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,7 @@ namespace ts.server {
248248
this.compilerOptions.allowNonTsExtensions = true;
249249
}
250250

251-
if (this.projectKind === ProjectKind.Inferred || this.projectKind === ProjectKind.External) {
252-
this.compilerOptions.noEmitForJsFiles = true;
253-
}
251+
this.setInternalCompilerOptionsForEmittingJsFiles();
254252

255253
this.lsHost = new LSHost(this.projectService.host, this, this.projectService.cancellationToken);
256254
this.lsHost.setCompilationSettings(this.compilerOptions);
@@ -266,6 +264,12 @@ namespace ts.server {
266264
this.markAsDirty();
267265
}
268266

267+
private setInternalCompilerOptionsForEmittingJsFiles() {
268+
if (this.projectKind === ProjectKind.Inferred || this.projectKind === ProjectKind.External) {
269+
this.compilerOptions.noEmitForJsFiles = true;
270+
}
271+
}
272+
269273
getProjectErrors() {
270274
return this.projectErrors;
271275
}
@@ -637,6 +641,7 @@ namespace ts.server {
637641
this.lastCachedUnresolvedImportsList = undefined;
638642
}
639643
this.compilerOptions = compilerOptions;
644+
this.setInternalCompilerOptionsForEmittingJsFiles();
640645
this.lsHost.setCompilationSettings(compilerOptions);
641646

642647
this.markAsDirty();

0 commit comments

Comments
 (0)