Skip to content

Commit a1f3f87

Browse files
committed
Fix #97
1 parent c7730e2 commit a1f3f87

File tree

41 files changed

+616
-160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+616
-160
lines changed

core/ts.core.tests/src/ts/core/tests/Main.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.List;
66

77
import ts.TypeScriptException;
8+
import ts.client.CodeEdit;
89
import ts.client.ITypeScriptServiceClient;
910
import ts.client.TypeScriptServiceClient;
1011
import ts.client.completions.CompletionInfo;
@@ -13,7 +14,6 @@
1314
import ts.client.definition.DefinitionsInfo;
1415
import ts.client.format.ITypeScriptFormatCollector;
1516
import ts.client.navbar.ITypeScriptNavBarCollector;
16-
import ts.client.navbar.NavigationBarItem;
1717
import ts.client.navbar.NavigationBarItemRoot;
1818
import ts.utils.FileUtils;
1919

@@ -55,21 +55,22 @@ public static void main(String[] args) throws InterruptedException, TypeScriptEx
5555

5656
client.format(fileName, 1, 1, 1, 12, new ITypeScriptFormatCollector() {
5757
@Override
58-
public void format(int startLine, int startOffset, int endLine, int endOffset, String newText)
59-
throws TypeScriptException {
60-
System.err.println(newText);
58+
public void format(List<CodeEdit> codeEdits) throws TypeScriptException {
59+
for (CodeEdit codeEdit : codeEdits) {
60+
System.err.println(codeEdit.getNewText());
61+
}
6162
}
6263
});
63-
64+
6465
client.navbar(fileName, null, new ITypeScriptNavBarCollector() {
65-
66+
6667
@Override
6768
public void setNavBar(NavigationBarItemRoot root) {
6869
System.err.println(root);
6970
}
7071
});
7172

72-
//client.join();
73+
// client.join();
7374
client.dispose();
7475

7576
}

core/ts.core.tests/src/ts/core/tests/Main2.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ public static void main(String[] args) throws InterruptedException, TypeScriptEx
5858
private static void validate(File sampleFile, MockTypeScriptProject tsProject, boolean normalize) throws TypeScriptException {
5959
MockTypeScriptFile tsFile = tsProject.openFile(sampleFile, normalize);
6060
tsFile.getProject().geterr(tsFile, 0, new ITypeScriptGeterrCollector() {
61-
6261
@Override
63-
public void addDiagnostic(String event, String file, String text, int startLine, int startOffset, int endLine,
64-
int endOffset) {
62+
public void addDiagnostic(String event, String file, String text, int startLine, int startOffset,
63+
int endLine, int endOffset, String category, int code) {
6564
System.err.println(event);
6665
}
6766
});
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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;
12+
13+
/**
14+
* Object found in response messages defining an editing instruction for a span
15+
* of text in source code. The effect of this instruction is to replace the text
16+
* starting at start and ending one character before end with newText. For an
17+
* insertion, the text span is empty. For a deletion, newText is empty.
18+
*/
19+
public class CodeEdit {
20+
21+
/**
22+
* First character of the text span to edit.
23+
*/
24+
private Location start;
25+
26+
/**
27+
* One character past last character of the text span to edit.
28+
*/
29+
private Location end;
30+
31+
/**
32+
* Replace the span defined above with this string (may be the empty
33+
* string).
34+
*/
35+
private String newText;
36+
37+
/**
38+
* Returns first character of the text span to edit.
39+
*
40+
* @return first character of the text span to edit.
41+
*/
42+
public Location getStart() {
43+
return start;
44+
}
45+
46+
/**
47+
* Returns one character past last character of the text span to edit.
48+
*
49+
* @return one character past last character of the text span to edit.
50+
*/
51+
public Location getEnd() {
52+
return end;
53+
}
54+
55+
/**
56+
* Replace the span defined above with this string (may be the empty string)
57+
*
58+
* @return replace the span defined above with this string (may be the empty
59+
* string)
60+
*/
61+
public String getNewText() {
62+
return newText;
63+
}
64+
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public enum CommandNames {
4646
NavTree("navtree", "2.0.6"),
4747

4848
// 2.1.0
49-
Implementation("implementation", "2.1.0"),
49+
Implementation("implementation", "2.1.0"),
50+
GetSupportedCodeFixes("getSupportedCodeFixes", "2.1.0"),
5051
GetCodeFixes("getCodeFixes", "2.1.0");
5152

5253
private final String name;

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import ts.TypeScriptException;
1414
import ts.client.codefixes.ITypeScriptGetCodeFixesCollector;
15+
import ts.client.codefixes.ITypeScriptGetSupportedCodeFixesCollector;
1516
import ts.client.completions.ITypeScriptCompletionCollector;
1617
import ts.client.completions.ITypeScriptCompletionEntryDetailsCollector;
1718
import ts.client.definition.ITypeScriptDefinitionCollector;
@@ -95,20 +96,22 @@ void syntacticDiagnosticsSync(String file, Boolean includeLinePosition, ITypeScr
9596
throws TypeScriptException;
9697

9798
// Since 2.0.5
98-
99+
99100
void compileOnSaveEmitFile(String fileName, Boolean forced) throws TypeScriptException;
100-
101+
101102
// Since 2.0.6
102103

103104
void navtree(String fileName, IPositionProvider positionProvider, ITypeScriptNavBarCollector collector)
104105
throws TypeScriptException;
105106

106107
// Since 2.1.0
107-
108+
108109
void getCodeFixes(String fileName, IPositionProvider positionProvider, int startLine, int startOffset, int endLine,
109-
int endOffset, ITypeScriptGetCodeFixesCollector collector) throws TypeScriptException;
110+
int endOffset, String[] errorCodes, ITypeScriptGetCodeFixesCollector collector) throws TypeScriptException;
111+
112+
void getSupportedCodeFixes(ITypeScriptGetSupportedCodeFixesCollector collector) throws TypeScriptException;
110113

111114
void implementation(String fileName, int line, int offset, ITypeScriptDefinitionCollector collector)
112115
throws TypeScriptException;
113-
116+
114117
}

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

+13-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import ts.TypeScriptException;
3030
import ts.client.codefixes.ITypeScriptGetCodeFixesCollector;
31+
import ts.client.codefixes.ITypeScriptGetSupportedCodeFixesCollector;
3132
import ts.client.completions.ITypeScriptCompletionCollector;
3233
import ts.client.completions.ITypeScriptCompletionEntryDetailsCollector;
3334
import ts.client.definition.ITypeScriptDefinitionCollector;
@@ -52,6 +53,7 @@
5253
import ts.internal.client.protocol.ConfigureRequestArguments;
5354
import ts.internal.client.protocol.DefinitionRequest;
5455
import ts.internal.client.protocol.FormatRequest;
56+
import ts.internal.client.protocol.GetSupportedCodeFixesRequest;
5557
import ts.internal.client.protocol.GeterrRequest;
5658
import ts.internal.client.protocol.ImplementationRequest;
5759
import ts.internal.client.protocol.NavBarRequest;
@@ -267,7 +269,7 @@ private void collect(JsonObject response, ITypeScriptDiagnosticsCollector collec
267269
start = diagnostic.get("start").asObject();
268270
end = diagnostic.get("end").asObject();
269271
collector.addDiagnostic(event, file, text, start.getInt("line", -1), start.getInt("offset", -1),
270-
end.getInt("line", -1), end.getInt("offset", -1));
272+
end.getInt("line", -1), end.getInt("offset", -1), null, -1);
271273
}
272274
}
273275

@@ -344,11 +346,19 @@ public void navtree(String fileName, IPositionProvider positionProvider, ITypeSc
344346

345347
// ---------------- Since 2.1.0
346348

349+
@Override
350+
public void getSupportedCodeFixes(ITypeScriptGetSupportedCodeFixesCollector collector)
351+
throws TypeScriptException {
352+
GetSupportedCodeFixesRequest request = new GetSupportedCodeFixesRequest(collector);
353+
execute(request);
354+
}
355+
347356
@Override
348357
public void getCodeFixes(String fileName, IPositionProvider positionProvider, int startLine, int startOffset,
349-
int endLine, int endOffset, ITypeScriptGetCodeFixesCollector collector) throws TypeScriptException {
358+
int endLine, int endOffset, String[] errorCodes, ITypeScriptGetCodeFixesCollector collector)
359+
throws TypeScriptException {
350360
CodeFixRequest request = new CodeFixRequest(fileName, positionProvider, startLine, startOffset, endLine,
351-
endOffset, collector);
361+
endOffset, errorCodes, collector);
352362
execute(request);
353363
}
354364

core/ts.core/src/ts/client/codefixes/CodeEdit.java

-34
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package ts.client.codefixes;
22

3+
import java.util.List;
4+
5+
import ts.client.CodeEdit;
6+
37
public class FileCodeEdits {
48

59
private String fileName;
6-
private CodeEdit textChanges;
10+
private List<CodeEdit> textChanges;
711

812
public String getFileName() {
913
return fileName;
1014
}
1115

12-
public CodeEdit getTextChanges() {
16+
public List<CodeEdit> getTextChanges() {
1317
return textChanges;
1418
}
1519
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package ts.client.codefixes;
22

3+
import java.util.List;
4+
35
import ts.client.ITypeScriptCollector;
46

57
public interface ITypeScriptGetCodeFixesCollector extends ITypeScriptCollector {
68

9+
void fix(List<CodeAction> codeActions);
710
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ts.client.codefixes;
2+
3+
import java.util.List;
4+
5+
import ts.client.ITypeScriptCollector;
6+
7+
public interface ITypeScriptGetSupportedCodeFixesCollector extends ITypeScriptCollector {
8+
9+
void setSupportedCodeFixes(List<String> errorCodes);
10+
}

core/ts.core/src/ts/client/diagnostics/ITypeScriptDiagnosticsCollector.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
public interface ITypeScriptDiagnosticsCollector extends ITypeScriptCollector {
66

77
void addDiagnostic(String event, String file, String text, int startLine, int startOffset, int endLine,
8-
int endOffset);
8+
int endOffset, String category, int code);
99

1010
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package ts.client.format;
22

3+
import java.util.List;
4+
35
import ts.TypeScriptException;
6+
import ts.client.CodeEdit;
47
import ts.client.ITypeScriptCollector;
58

69
public interface ITypeScriptFormatCollector extends ITypeScriptCollector {
710

8-
void format(int startLine, int startOffset, int endLine, int endOffset, String newText) throws TypeScriptException;
11+
void format(List<CodeEdit> codeEdits) throws TypeScriptException;
912
}

core/ts.core/src/ts/client/navbar/INavigationBarItem.java

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
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+
*/
111
package ts.client.navbar;
212

313
import ts.client.IKindProvider;

core/ts.core/src/ts/client/navbar/ITypeScriptNavBarCollector.java

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
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+
*/
111
package ts.client.navbar;
212

313
import ts.client.ITypeScriptCollector;

core/ts.core/src/ts/client/navbar/NavigationBarItem.java

+14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
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+
*/
111
package ts.client.navbar;
212

313
import java.util.List;
414

15+
/**
16+
* Navigation bar item.
17+
*
18+
*/
519
public class NavigationBarItem implements INavigationBarItem {
620

721
private String text;

core/ts.core/src/ts/client/navbar/TextSpan.java

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
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+
*/
111
package ts.client.navbar;
212

313
import ts.TypeScriptException;

0 commit comments

Comments
 (0)