Skip to content

Commit bb71dcd

Browse files
authored
add projectUsesOutFile field to protocol.CompileOnSaveAffectedFileListSingleProject (microsoft#13915)
1 parent 51d4970 commit bb71dcd

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,6 +3031,54 @@ namespace ts.projectSystem {
30313031
});
30323032
});
30333033

3034+
describe("emit with outFile or out setting", () => {
3035+
function test(opts: CompilerOptions, expectedUsesOutFile: boolean) {
3036+
const f1 = {
3037+
path: "/a/a.ts",
3038+
content: "let x = 1"
3039+
};
3040+
const f2 = {
3041+
path: "/a/b.ts",
3042+
content: "let y = 1"
3043+
};
3044+
const config = {
3045+
path: "/a/tsconfig.json",
3046+
content: JSON.stringify({
3047+
compilerOptions: opts,
3048+
compileOnSave: true
3049+
})
3050+
};
3051+
const host = createServerHost([f1, f2, config]);
3052+
const session = createSession(host);
3053+
session.executeCommand(<protocol.OpenRequest>{
3054+
seq: 1,
3055+
type: "request",
3056+
command: "open",
3057+
arguments: { file: f1.path }
3058+
});
3059+
checkNumberOfProjects(session.getProjectService(), { configuredProjects: 1 });
3060+
const { response } = session.executeCommand(<protocol.CompileOnSaveAffectedFileListRequest>{
3061+
seq: 2,
3062+
type: "request",
3063+
command: "compileOnSaveAffectedFileList",
3064+
arguments: { file: f1.path }
3065+
});
3066+
assert.equal((<protocol.CompileOnSaveAffectedFileListSingleProject[]>response).length, 1, "expected output for 1 project");
3067+
assert.equal((<protocol.CompileOnSaveAffectedFileListSingleProject[]>response)[0].fileNames.length, 2, "expected output for 1 project");
3068+
assert.equal((<protocol.CompileOnSaveAffectedFileListSingleProject[]>response)[0].projectUsesOutFile, expectedUsesOutFile, "usesOutFile");
3069+
}
3070+
3071+
it ("projectUsesOutFile should not be returned if not set", () => {
3072+
test({}, /*expectedUsesOutFile*/ false);
3073+
});
3074+
it ("projectUsesOutFile should be true if outFile is set", () => {
3075+
test({ outFile: "/a/out.js" }, /*expectedUsesOutFile*/ true);
3076+
});
3077+
it ("projectUsesOutFile should be true if out is set", () => {
3078+
test({ out: "/a/out.js" }, /*expectedUsesOutFile*/ true);
3079+
});
3080+
});
3081+
30343082
describe("import helpers", () => {
30353083
it("should not crash in tsserver", () => {
30363084
const f1 = {

src/server/protocol.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,11 @@ namespace ts.server.protocol {
12391239
* List of files names that should be recompiled
12401240
*/
12411241
fileNames: string[];
1242+
1243+
/**
1244+
* true if project uses outFile or out compiler option
1245+
*/
1246+
projectUsesOutFile: boolean;
12421247
}
12431248

12441249
/**

src/server/session.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,8 @@ namespace ts.server {
10401040
if (project.compileOnSaveEnabled && project.languageServiceEnabled) {
10411041
result.push({
10421042
projectFileName: project.getProjectName(),
1043-
fileNames: project.getCompileOnSaveAffectedFileList(info)
1043+
fileNames: project.getCompileOnSaveAffectedFileList(info),
1044+
projectUsesOutFile: !!project.getCompilerOptions().outFile || !!project.getCompilerOptions().out
10441045
});
10451046
}
10461047
}

0 commit comments

Comments
 (0)