Skip to content

Commit 81e2d5d

Browse files
committed
Prepare compile on save with tsserver. See
#109
1 parent 0fdafd6 commit 81e2d5d

9 files changed

+141
-8
lines changed

core/ts.core/META-INF/MANIFEST.MF

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Bundle-ActivationPolicy: lazy
1313
Export-Package: ts,
1414
ts.client,
1515
ts.client.codefixes,
16+
ts.client.compileonsave,
1617
ts.client.completions,
1718
ts.client.configure,
1819
ts.client.diagnostics,
@@ -22,6 +23,7 @@ Export-Package: ts,
2223
ts.client.projectinfo,
2324
ts.client.quickinfo,
2425
ts.client.references,
26+
ts.client.rename,
2527
ts.client.signaturehelp,
2628
ts.cmd,
2729
ts.cmd.tsc,

core/ts.core/src/ts/client/CommandNames.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public enum CommandNames {
4242
SyntacticDiagnosticsSync("syntacticDiagnosticsSync", "2.0.3"),
4343

4444
// 2.0.5
45-
compileOnSaveAffectedFileList("CompileOnSaveAffectedFileList", "2.0.5"),
46-
compileOnSaveEmitFile("compileOnSaveEmitFile", "2.0.5"),
45+
CompileOnSaveAffectedFileList("compileOnSaveAffectedFileList", "2.0.5"),
46+
CompileOnSaveEmitFile("compileOnSaveEmitFile", "2.0.5"),
4747

4848
// 2.0.6
4949
NavTree("navtree", "2.0.6"),

core/ts.core/src/ts/client/ITypeScriptServiceClient.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import ts.TypeScriptException;
1717
import ts.client.codefixes.CodeAction;
18+
import ts.client.compileonsave.CompileOnSaveAffectedFileListSingleProject;
1819
import ts.client.completions.CompletionEntry;
1920
import ts.client.completions.CompletionEntryDetails;
2021
import ts.client.completions.ICompletionEntryFactory;
@@ -230,7 +231,10 @@ CompletableFuture<DiagnosticEventBody> syntacticDiagnosticsSync(String file, Boo
230231

231232
// Since 2.0.5
232233

233-
void compileOnSaveEmitFile(String fileName, Boolean forced) throws TypeScriptException;
234+
CompletableFuture<Boolean> compileOnSaveEmitFile(String fileName, Boolean forced) throws TypeScriptException;
235+
236+
CompletableFuture<List<CompileOnSaveAffectedFileListSingleProject>> compileOnSaveAffectedFileList(String fileName)
237+
throws TypeScriptException;
234238

235239
// Since 2.0.6
236240

core/ts.core/src/ts/client/TypeScriptServiceClient.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import ts.TypeScriptException;
2727
import ts.TypeScriptNoContentAvailableException;
2828
import ts.client.codefixes.CodeAction;
29+
import ts.client.compileonsave.CompileOnSaveAffectedFileListSingleProject;
2930
import ts.client.completions.CompletionEntry;
3031
import ts.client.completions.CompletionEntryDetails;
3132
import ts.client.completions.ICompletionEntryFactory;
@@ -45,6 +46,7 @@
4546
import ts.internal.client.protocol.ChangeRequest;
4647
import ts.internal.client.protocol.CloseRequest;
4748
import ts.internal.client.protocol.CodeFixRequest;
49+
import ts.internal.client.protocol.CompileOnSaveAffectedFileListRequest;
4850
import ts.internal.client.protocol.CompileOnSaveEmitFileRequest;
4951
import ts.internal.client.protocol.CompletionDetailsRequest;
5052
import ts.internal.client.protocol.CompletionsRequest;
@@ -379,8 +381,14 @@ public CompletableFuture<DiagnosticEventBody> syntacticDiagnosticsSync(String fi
379381
// Since 2.0.5
380382

381383
@Override
382-
public void compileOnSaveEmitFile(String fileName, Boolean forced) throws TypeScriptException {
383-
execute(new CompileOnSaveEmitFileRequest(fileName, forced), false);
384+
public CompletableFuture<Boolean> compileOnSaveEmitFile(String fileName, Boolean forced) throws TypeScriptException {
385+
return execute(new CompileOnSaveEmitFileRequest(fileName, forced), true);
386+
}
387+
388+
@Override
389+
public CompletableFuture<List<CompileOnSaveAffectedFileListSingleProject>> compileOnSaveAffectedFileList(String fileName)
390+
throws TypeScriptException {
391+
return execute(new CompileOnSaveAffectedFileListRequest(fileName), true);
384392
}
385393

386394
// Since 2.0.6
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (c) 2015-2016 Angelo ZERR.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Angelo Zerr <[email protected]> - initial API and implementation
10+
*/
11+
package ts.client.compileonsave;
12+
13+
import java.util.List;
14+
15+
/**
16+
* Contains a list of files that should be regenerated in a project
17+
*
18+
*/
19+
public class CompileOnSaveAffectedFileListSingleProject {
20+
21+
/**
22+
* Project name
23+
*/
24+
private String projectFileName;
25+
/**
26+
* List of files names that should be recompiled
27+
*/
28+
private List<String> fileNames;
29+
30+
public String getProjectFileName() {
31+
return projectFileName;
32+
}
33+
34+
public List<String> getFileNames() {
35+
return fileNames;
36+
}
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright (c) 2015-2017 Angelo ZERR.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Angelo Zerr <[email protected]> - initial API and implementation
10+
*/
11+
package ts.internal.client.protocol;
12+
13+
import java.util.List;
14+
15+
import com.google.gson.JsonObject;
16+
17+
import ts.client.CommandNames;
18+
import ts.client.compileonsave.CompileOnSaveAffectedFileListSingleProject;
19+
20+
/**
21+
* Request to obtain the list of files that should be regenerated if target file
22+
* is recompiled. NOTE: this us query-only operation and does not generate any
23+
* output on disk.
24+
*
25+
* @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
26+
*/
27+
public class CompileOnSaveAffectedFileListRequest extends FileRequest<FileRequestArgs> {
28+
29+
public CompileOnSaveAffectedFileListRequest(String fileName) {
30+
super(CommandNames.CompileOnSaveAffectedFileList.getName(), new FileRequestArgs(fileName, null));
31+
}
32+
33+
@Override
34+
public Response<List<CompileOnSaveAffectedFileListSingleProject>> parseResponse(JsonObject json) {
35+
return GsonHelper.DEFAULT_GSON.fromJson(json, CompileOnSaveAffectedFileListResponse.class);
36+
}
37+
38+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) 2015-2017 Angelo ZERR.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Angelo Zerr <[email protected]> - initial API and implementation
10+
*/
11+
package ts.internal.client.protocol;
12+
13+
import java.util.List;
14+
15+
import ts.client.compileonsave.CompileOnSaveAffectedFileListSingleProject;
16+
17+
/**
18+
* Response for CompileOnSaveAffectedFileListRequest request;
19+
*
20+
* @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
21+
*/
22+
public class CompileOnSaveAffectedFileListResponse extends Response<List<CompileOnSaveAffectedFileListSingleProject>> {
23+
24+
}

core/ts.core/src/ts/internal/client/protocol/CompileOnSaveEmitFileRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
public class CompileOnSaveEmitFileRequest extends Request<CompileOnSaveEmitFileRequestArgs> {
2424

2525
public CompileOnSaveEmitFileRequest(String file, Boolean forced) {
26-
super(CommandNames.compileOnSaveEmitFile.getName(), new CompileOnSaveEmitFileRequestArgs(file, forced));
26+
super(CommandNames.CompileOnSaveEmitFile.getName(), new CompileOnSaveEmitFileRequestArgs(file, forced));
2727
}
2828

2929
@Override
30-
public Response<?> parseResponse(JsonObject json) {
31-
return null;
30+
public Response<Boolean> parseResponse(JsonObject json) {
31+
return GsonHelper.DEFAULT_GSON.fromJson(json, CompileOnSaveEmitFileResponse.class);
3232
}
3333

3434
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) 2015-2017 Angelo ZERR.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Angelo Zerr <[email protected]> - initial API and implementation
10+
*/
11+
package ts.internal.client.protocol;
12+
13+
/**
14+
* Response for CompileOnSaveRequest request;
15+
*
16+
* @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
17+
*/
18+
public class CompileOnSaveEmitFileResponse extends Response<Boolean> {
19+
20+
}

0 commit comments

Comments
 (0)