Skip to content

Commit f6f866e

Browse files
committed
Reset the noEmitForJsFiles option when updating compiler options (#12570)
1 parent 4c9bdb9 commit f6f866e

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

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)