Skip to content

Commit

Permalink
Merge pull request #12575 from zhengbli/port12570
Browse files Browse the repository at this point in the history
Reset the noEmitForJsFiles option when updating compiler options (#12
  • Loading branch information
mhegazy authored Dec 1, 2016
2 parents fc1f6e3 + f6f866e commit 2cec8db
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
59 changes: 59 additions & 0 deletions src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2728,6 +2728,65 @@ namespace ts.projectSystem {
arguments: { projectFileName: projectName }
}).response;
assert.isTrue(diags.length === 0);

session.executeCommand(<server.protocol.SetCompilerOptionsForInferredProjectsRequest>{
type: "request",
command: server.CommandNames.CompilerOptionsForInferredProjects,
seq: 3,
arguments: { options: { module: ModuleKind.CommonJS } }
});
const diagsAfterUpdate = session.executeCommand(<server.protocol.CompilerOptionsDiagnosticsRequest>{
type: "request",
command: server.CommandNames.CompilerOptionsDiagnosticsFull,
seq: 4,
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(<protocol.ExternalProject>{
projectFileName,
rootFiles: externalFiles,
options: {}
});

checkNumberOfProjects(projectService, { externalProjects: 1 });

const diags = session.executeCommand(<server.protocol.CompilerOptionsDiagnosticsRequest>{
type: "request",
command: server.CommandNames.CompilerOptionsDiagnosticsFull,
seq: 2,
arguments: { projectFileName }
}).response;
assert.isTrue(diags.length === 0);

session.executeCommand(<server.protocol.OpenExternalProjectRequest>{
type: "request",
command: server.CommandNames.OpenExternalProject,
seq: 3,
arguments: {
projectFileName,
rootFiles: externalFiles,
options: { module: ModuleKind.CommonJS }
}
});
const diagsAfterUpdate = session.executeCommand(<server.protocol.CompilerOptionsDiagnosticsRequest>{
type: "request",
command: server.CommandNames.CompilerOptionsDiagnosticsFull,
seq: 4,
arguments: { projectFileName }
}).response;
assert.isTrue(diagsAfterUpdate.length === 0);
});
});

Expand Down
11 changes: 8 additions & 3 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -266,6 +264,12 @@ namespace ts.server {
this.markAsDirty();
}

private setInternalCompilerOptionsForEmittingJsFiles() {
if (this.projectKind === ProjectKind.Inferred || this.projectKind === ProjectKind.External) {
this.compilerOptions.noEmitForJsFiles = true;
}
}

getProjectErrors() {
return this.projectErrors;
}
Expand Down Expand Up @@ -637,6 +641,7 @@ namespace ts.server {
this.lastCachedUnresolvedImportsList = undefined;
}
this.compilerOptions = compilerOptions;
this.setInternalCompilerOptionsForEmittingJsFiles();
this.lsHost.setCompilationSettings(compilerOptions);

this.markAsDirty();
Expand Down

0 comments on commit 2cec8db

Please sign in to comment.