Skip to content

Commit bdd8ff6

Browse files
Adjusted usage of CompletableFuture and added required requests concept
Required requests are use to have some requests waiting for the response to other requests. This would be required for openExternalProject (see angelozerr#142). Also adjusted the code so that: - async methods return CompletableFuture and never throw, - sync methods block for the future result and throw in case of error.
1 parent c85b895 commit bdd8ff6

File tree

2 files changed

+235
-175
lines changed

2 files changed

+235
-175
lines changed

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

Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
* Contributors:
99
* Angelo Zerr <[email protected]> - initial API and implementation
10+
* Lorenzo Dalla Vecchia <[email protected]> - adjusted usage of CompletableFuture
1011
*/
1112
package ts.client;
1213

@@ -77,8 +78,8 @@ public interface ITypeScriptServiceClient {
7778
* @param insertString
7879
* @throws TypeScriptException
7980
*/
80-
// void changeFile(String fileName, int position, int endPosition, String
81-
// insertString) throws TypeScriptException;
81+
// void changeFile(String fileName, int position, int
82+
// endPosition, String insertString) throws TypeScriptException;
8283

8384
/**
8485
* Change file content at the given lines/offsets.
@@ -91,8 +92,8 @@ public interface ITypeScriptServiceClient {
9192
* @param insertString
9293
* @throws TypeScriptException
9394
*/
94-
void changeFile(String fileName, int line, int offset, int endLine, int endOffset, String insertString)
95-
throws TypeScriptException;
95+
void changeFile(String fileName, int line, int offset, int endLine, int endOffset,
96+
String insertString) throws TypeScriptException;
9697

9798
void updateFile(String fileName, String newText) throws TypeScriptException;
9899

@@ -102,10 +103,9 @@ void changeFile(String fileName, int line, int offset, int endLine, int endOffse
102103
* @param fileName
103104
* @param position
104105
* @return completion for the given fileName at the given position.
105-
* @throws TypeScriptException
106106
*/
107107
// CompletableFuture<List<CompletionEntry>> completions(String fileName, int
108-
// position) throws TypeScriptException;
108+
// position);
109109

110110
/**
111111
* Completion for the given fileName at the given line/offset.
@@ -114,16 +114,14 @@ void changeFile(String fileName, int line, int offset, int endLine, int endOffse
114114
* @param line
115115
* @param offset
116116
* @return completion for the given fileName at the given line/offset
117-
* @throws TypeScriptException
118117
*/
119-
CompletableFuture<List<CompletionEntry>> completions(String fileName, int line, int offset)
120-
throws TypeScriptException;
118+
CompletableFuture<List<CompletionEntry>> completions(String fileName, int line, int offset);
121119

122120
CompletableFuture<List<CompletionEntry>> completions(String name, int line, int offset,
123-
ICompletionEntryFactory instanceCreator) throws TypeScriptException;
121+
ICompletionEntryFactory instanceCreator);
124122

125123
CompletableFuture<List<CompletionEntryDetails>> completionEntryDetails(String fileName, int line, int offset,
126-
String[] entryNames, CompletionEntry completionEntry) throws TypeScriptException;
124+
String[] entryNames, CompletionEntry completionEntry);
127125

128126
/**
129127
* Definition for the given fileName at the given line/offset.
@@ -132,9 +130,8 @@ CompletableFuture<List<CompletionEntryDetails>> completionEntryDetails(String fi
132130
* @param line
133131
* @param offset
134132
* @return
135-
* @throws TypeScriptException
136133
*/
137-
CompletableFuture<List<FileSpan>> definition(String fileName, int line, int offset) throws TypeScriptException;
134+
CompletableFuture<List<FileSpan>> definition(String fileName, int line, int offset);
138135

139136
/**
140137
* Signature help for the given fileName at the given line/offset.
@@ -143,10 +140,8 @@ CompletableFuture<List<CompletionEntryDetails>> completionEntryDetails(String fi
143140
* @param line
144141
* @param offset
145142
* @return
146-
* @throws TypeScriptException
147143
*/
148-
CompletableFuture<SignatureHelpItems> signatureHelp(String fileName, int line, int offset)
149-
throws TypeScriptException;
144+
CompletableFuture<SignatureHelpItems> signatureHelp(String fileName, int line, int offset);
150145

151146
/**
152147
* Quick info for the given fileName at the given line/offset.
@@ -155,14 +150,12 @@ CompletableFuture<SignatureHelpItems> signatureHelp(String fileName, int line, i
155150
* @param line
156151
* @param offset
157152
* @return
158-
* @throws TypeScriptException
159153
*/
160-
CompletableFuture<QuickInfo> quickInfo(String fileName, int line, int offset) throws TypeScriptException;
154+
CompletableFuture<QuickInfo> quickInfo(String fileName, int line, int offset);
161155

162-
CompletableFuture<List<DiagnosticEvent>> geterr(String[] files, int delay) throws TypeScriptException;
156+
CompletableFuture<List<DiagnosticEvent>> geterr(String[] files, int delay);
163157

164-
CompletableFuture<List<DiagnosticEvent>> geterrForProject(String file, int delay, ProjectInfo projectInfo)
165-
throws TypeScriptException;
158+
CompletableFuture<List<DiagnosticEvent>> geterrForProject(String file, int delay, ProjectInfo projectInfo);
166159

167160
/**
168161
* Format for the given fileName at the given line/offset.
@@ -173,10 +166,8 @@ CompletableFuture<List<DiagnosticEvent>> geterrForProject(String file, int delay
173166
* @param endLine
174167
* @param endOffset
175168
* @return
176-
* @throws TypeScriptException
177169
*/
178-
CompletableFuture<List<CodeEdit>> format(String fileName, int line, int offset, int endLine, int endOffset)
179-
throws TypeScriptException;
170+
CompletableFuture<List<CodeEdit>> format(String fileName, int line, int offset, int endLine, int endOffset);
180171

181172
/**
182173
* Find references for the given fileName at the given line/offset.
@@ -185,10 +176,8 @@ CompletableFuture<List<CodeEdit>> format(String fileName, int line, int offset,
185176
* @param line
186177
* @param offset
187178
* @return
188-
* @throws TypeScriptException
189179
*/
190-
CompletableFuture<ReferencesResponseBody> references(String fileName, int line, int offset)
191-
throws TypeScriptException;
180+
CompletableFuture<ReferencesResponseBody> references(String fileName, int line, int offset);
192181

193182
/**
194183
* Find occurrences for the given fileName at the given line/offset.
@@ -197,21 +186,17 @@ CompletableFuture<ReferencesResponseBody> references(String fileName, int line,
197186
* @param line
198187
* @param offset
199188
* @return
200-
* @throws TypeScriptException
201189
*/
202-
CompletableFuture<List<OccurrencesResponseItem>> occurrences(String fileName, int line, int offset)
203-
throws TypeScriptException;
190+
CompletableFuture<List<OccurrencesResponseItem>> occurrences(String fileName, int line, int offset);
204191

205192
CompletableFuture<RenameResponseBody> rename(String file, int line, int offset, Boolean findInComments,
206-
Boolean findInStrings) throws TypeScriptException;
193+
Boolean findInStrings);
207194

208-
CompletableFuture<List<NavigationBarItem>> navbar(String fileName, IPositionProvider positionProvider)
209-
throws TypeScriptException;
195+
CompletableFuture<List<NavigationBarItem>> navbar(String fileName, IPositionProvider positionProvider);
210196

211197
void configure(ConfigureRequestArguments arguments) throws TypeScriptException;
212198

213-
CompletableFuture<ProjectInfo> projectInfo(String file, String projectFileName, boolean needFileNameList)
214-
throws TypeScriptException;
199+
CompletableFuture<ProjectInfo> projectInfo(String file, String projectFileName, boolean needFileNameList);
215200

216201
// Since 2.0.3
217202

@@ -220,42 +205,35 @@ CompletableFuture<ProjectInfo> projectInfo(String file, String projectFileName,
220205
*
221206
* @param includeLinePosition
222207
* @return
223-
* @throws TypeScriptException
224208
*/
225-
CompletableFuture<DiagnosticEventBody> semanticDiagnosticsSync(String file, Boolean includeLinePosition)
226-
throws TypeScriptException;
209+
CompletableFuture<DiagnosticEventBody> semanticDiagnosticsSync(String file, Boolean includeLinePosition);
227210

228211
/**
229212
* Execute syntactic diagnostics for the given file.
230213
*
231214
* @param includeLinePosition
232215
* @return
233-
* @throws TypeScriptException
234216
*/
235-
CompletableFuture<DiagnosticEventBody> syntacticDiagnosticsSync(String file, Boolean includeLinePosition)
236-
throws TypeScriptException;
217+
CompletableFuture<DiagnosticEventBody> syntacticDiagnosticsSync(String file, Boolean includeLinePosition);
237218

238219
// Since 2.0.5
239220

240-
CompletableFuture<Boolean> compileOnSaveEmitFile(String fileName, Boolean forced) throws TypeScriptException;
221+
CompletableFuture<Boolean> compileOnSaveEmitFile(String fileName, Boolean forced);
241222

242-
CompletableFuture<List<CompileOnSaveAffectedFileListSingleProject>> compileOnSaveAffectedFileList(String fileName)
243-
throws TypeScriptException;
223+
CompletableFuture<List<CompileOnSaveAffectedFileListSingleProject>> compileOnSaveAffectedFileList(String fileName);
244224

245225
// Since 2.0.6
246226

247-
CompletableFuture<NavigationBarItem> navtree(String fileName, IPositionProvider positionProvider)
248-
throws TypeScriptException;
227+
CompletableFuture<NavigationBarItem> navtree(String fileName, IPositionProvider positionProvider);
249228

250-
CompletableFuture<TextInsertion> docCommentTemplate(String fileName, int line, int offset)
251-
throws TypeScriptException;
229+
CompletableFuture<TextInsertion> docCommentTemplate(String fileName, int line, int offset);
252230

253231
// Since 2.1.0
254232

255233
CompletableFuture<List<CodeAction>> getCodeFixes(String fileName, IPositionProvider positionProvider, int startLine,
256-
int startOffset, int endLine, int endOffset, List<Integer> errorCodes) throws TypeScriptException;
234+
int startOffset, int endLine, int endOffset, List<Integer> errorCodes);
257235

258-
CompletableFuture<List<String>> getSupportedCodeFixes() throws TypeScriptException;
236+
CompletableFuture<List<String>> getSupportedCodeFixes();
259237

260238
//
261239
/**
@@ -265,9 +243,8 @@ CompletableFuture<List<CodeAction>> getCodeFixes(String fileName, IPositionProvi
265243
* @param line
266244
* @param offset
267245
* @return
268-
* @throws TypeScriptException
269246
*/
270-
CompletableFuture<List<FileSpan>> implementation(String fileName, int line, int offset) throws TypeScriptException;
247+
CompletableFuture<List<FileSpan>> implementation(String fileName, int line, int offset);
271248

272249
void addClientListener(ITypeScriptClientListener listener);
273250

0 commit comments

Comments
 (0)