Skip to content

Commit bd74145

Browse files
committed
Do big refactoring to use Java8 CompletableFuture for
TypeScriptServiceClient. See #63
1 parent ec08dcc commit bd74145

File tree

237 files changed

+4695
-3519
lines changed

Some content is hidden

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

237 files changed

+4695
-3519
lines changed

core/ts.core.tests/.classpath

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
4+
<attributes>
5+
<attribute name="maven.pomderived" value="true"/>
6+
</attributes>
7+
</classpathentry>
48
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5-
<classpathentry kind="src" path="src"/>
9+
<classpathentry kind="src" path="src/"/>
610
<classpathentry kind="output" path="target/classes"/>
711
</classpath>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Bundle-Vendor: %providerName
55
Bundle-Localization: plugin
66
Bundle-SymbolicName: ts.core.tests
77
Bundle-Version: 1.2.0.qualifier
8-
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
8+
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
99
Import-Package: com.eclipsesource.json;version="0.9.4",
1010
org.osgi.framework;version="1.3.0"
1111
Bundle-ActivationPolicy: lazy

core/ts.core.tests/samples/sample.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

core/ts.core.tests/samples/sample.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

core/ts.core.tests/samples/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"noImplicitAny": true,
55
"removeComments": true,
66
"preserveConstEnums": true,
7-
"sourceMap": true,
8-
"watch": true
7+
"sourceMap": true
98
},
109
"files": [
1110
"sample.ts"
Lines changed: 95 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
package ts.core.tests;
22

33
import java.io.File;
4-
import java.io.IOException;
54
import java.util.List;
5+
import java.util.concurrent.CompletableFuture;
6+
import java.util.concurrent.ExecutionException;
67

78
import ts.TypeScriptException;
8-
import ts.client.CodeEdit;
9+
import ts.client.FileSpan;
910
import ts.client.ITypeScriptServiceClient;
11+
import ts.client.Location;
12+
import ts.client.LoggingInterceptor;
1013
import ts.client.TypeScriptServiceClient;
11-
import ts.client.completions.CompletionInfo;
12-
import ts.client.completions.ICompletionEntry;
13-
import ts.client.completions.ICompletionInfo;
14-
import ts.client.definition.DefinitionsInfo;
15-
import ts.client.format.ITypeScriptFormatCollector;
16-
import ts.client.navbar.ITypeScriptNavBarCollector;
17-
import ts.client.navbar.NavigationBarItemRoot;
14+
import ts.client.completions.CompletionEntry;
15+
import ts.client.diagnostics.DiagnosticEvent;
16+
import ts.client.projectinfo.ProjectInfo;
17+
import ts.client.quickinfo.QuickInfo;
1818
import ts.utils.FileUtils;
1919

2020
public class Main {
2121

22-
public static void main(String[] args) throws InterruptedException, TypeScriptException, IOException {
23-
22+
public static void main(String[] args) throws TypeScriptException, InterruptedException, ExecutionException {
2423
File projectDir = new File("./samples");
25-
// sample2.ts has the following content:
24+
// sample.ts has the following content:
2625
// var s = "";s.
2726
File sampleFile = new File(projectDir, "sample.ts");
2827
String fileName = FileUtils.getPath(sampleFile);
@@ -31,60 +30,104 @@ public static void main(String[] args) throws InterruptedException, TypeScriptEx
3130
ITypeScriptServiceClient client = new TypeScriptServiceClient(projectDir,
3231
new File("../ts.repository/node_modules/typescript/bin/tsserver"), null);
3332

34-
// Open "sample2.ts" in an editor
33+
client.addInterceptor(LoggingInterceptor.getInstance());
34+
35+
// Open "sample.ts" in an editor
3536
client.openFile(fileName, null);
3637

37-
// Do completion after the last dot of "s" variable which is a String
38-
// (charAt, ....)
39-
CompletionInfo completionInfo = new CompletionInfo(null);
40-
client.completions(fileName, 1, 14, null, completionInfo);
41-
display(completionInfo);
38+
// compile on save
39+
client.compileOnSaveEmitFile(fileName, true);
40+
41+
42+
// Completions with line/offset
43+
CompletableFuture<List<CompletionEntry>> completionPromise = client.completions(fileName, 1, 14);
44+
List<CompletionEntry> entries = completionPromise.get();
45+
displayCompletions(entries);
46+
47+
// Completions with position (only since TypeScript 2.0)
48+
// completionPromise = client.completions(fileName, 14);
49+
// entries = completionPromise.get();
50+
// displayCompletions(entries);
51+
52+
// QuickInfo
53+
CompletableFuture<QuickInfo> quickInfoPromise = client.quickInfo(fileName, 1, 5);
54+
QuickInfo quickInfo = quickInfoPromise.get();
55+
displayQuickInfo(quickInfo);
56+
57+
// Definition
58+
CompletableFuture<List<FileSpan>> definitionPromise = client.definition(fileName, 1, 5);
59+
List<FileSpan> definition = definitionPromise.get();
60+
displayDefinition(definition);
4261

4362
// Update the editor content to set s as number
44-
client.updateFile(fileName, "var s = 1;s.");
63+
// var s = 1;s.
64+
// client.changeFile(fileName, 9, 11, "1"); // position change, doesn't
65+
// work with TypeScript 2.1.4
66+
client.changeFile(fileName, 1, 9, 1, 11, "1");
4567

4668
// Do completion after the last dot of "s" variable which is a Number
4769
// (toExponential, ....)
48-
completionInfo = new CompletionInfo(null);
49-
client.completions(fileName, 1, 14, null, completionInfo);
50-
display(completionInfo);
51-
52-
DefinitionsInfo definitionInfo = new DefinitionsInfo();
53-
client.definition(fileName, 1, 12, definitionInfo);
54-
display(definitionInfo);
55-
56-
client.format(fileName, 1, 1, 1, 12, new ITypeScriptFormatCollector() {
57-
@Override
58-
public void format(List<CodeEdit> codeEdits) throws TypeScriptException {
59-
for (CodeEdit codeEdit : codeEdits) {
60-
System.err.println(codeEdit.getNewText());
61-
}
62-
}
63-
});
64-
65-
client.navbar(fileName, null, new ITypeScriptNavBarCollector() {
66-
67-
@Override
68-
public void setNavBar(NavigationBarItemRoot root) {
69-
System.err.println(root);
70-
}
71-
});
72-
73-
// client.join();
70+
completionPromise = client.completions(fileName, 1, 14);
71+
entries = completionPromise.get();
72+
displayCompletions(entries);
73+
74+
// geterr
75+
List<DiagnosticEvent> events = client.geterr(new String[] { fileName }, 0).get();
76+
displayDiagnostics(events);
77+
78+
// projectInfo
79+
ProjectInfo projectInfo = client.projectInfo(fileName, null, true).get();
80+
displayProjectInfo(projectInfo);
81+
82+
//
83+
// client.geterrForProjectRequest(file, delay, projectInfo)
84+
85+
// Close "sample.ts"
86+
client.closeFile(fileName);
87+
88+
89+
// synchronized (client) {t
90+
// try {
91+
// client.wait(2000);
92+
// } catch (InterruptedException e) {
93+
// // TODO Auto-generated catch block
94+
// e.printStackTrace();
95+
// }
96+
// }
7497
client.dispose();
7598

7699
}
77100

78-
private static void display(DefinitionsInfo definitionInfo) {
79-
// TODO Auto-generated method stub
101+
public static void displayCompletions(List<CompletionEntry> entries) {
102+
for (CompletionEntry entry : entries) {
103+
System.err.println(entry.getName());
104+
}
105+
}
80106

107+
private static void displayQuickInfo(QuickInfo quickInfo) {
108+
System.err.println("DisplayString: " + quickInfo.getDisplayString() + ", start: "
109+
+ toString(quickInfo.getStart()) + ", end: " + toString(quickInfo.getEnd()));
81110
}
82111

83-
private static void display(ICompletionInfo completionInfo) {
84-
System.out.println("getCompletionsAtLineOffset:");
85-
ICompletionEntry[] entries = completionInfo.getEntries();
86-
for (ICompletionEntry entry : entries) {
87-
System.out.println(entry.getName());
112+
private static void displayDefinition(List<FileSpan> spans) {
113+
for (FileSpan span : spans) {
114+
System.err.println("file: " + span.getFile() + ", start: " + toString(span.getStart()) + ", end: "
115+
+ toString(span.getEnd()));
88116
}
89117
}
118+
119+
private static void displayDiagnostics(List<DiagnosticEvent> events) {
120+
for (DiagnosticEvent event : events) {
121+
System.err.println(event.getBody().getFile());
122+
}
123+
}
124+
125+
private static void displayProjectInfo(ProjectInfo projectInfo) {
126+
System.err.println(projectInfo.getConfigFileName());
127+
}
128+
129+
private static String toString(Location loc) {
130+
return "{" + loc.getLine() + ", " + loc.getOffset() + "}";
131+
}
132+
90133
}

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

Lines changed: 0 additions & 81 deletions
This file was deleted.

core/ts.core.tests/src/ts/core/tests/NavBarTest.java

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)