93
93
import org .eclipse .lsp4j .jsonrpc .messages .Either ;
94
94
import org .eclipse .lsp4j .jsonrpc .messages .Either3 ;
95
95
import org .eclipse .lsp4j .services .TextDocumentService ;
96
+ import org .springframework .scheduling .concurrent .CustomizableThreadFactory ;
96
97
import org .springframework .stereotype .Component ;
97
98
98
99
import java .net .URI ;
99
100
import java .util .Collections ;
100
101
import java .util .List ;
101
102
import java .util .concurrent .CompletableFuture ;
102
- import java .util .stream .Collectors ;
103
+ import java .util .concurrent .ExecutorService ;
104
+ import java .util .concurrent .Executors ;
103
105
104
106
@ Component
105
107
@ RequiredArgsConstructor
@@ -123,14 +125,17 @@ public class BSLTextDocumentService implements TextDocumentService, ProtocolExte
123
125
private final RenameProvider renameProvider ;
124
126
private final InlayHintProvider inlayHintProvider ;
125
127
128
+ private final ExecutorService executorService = Executors .newCachedThreadPool (new CustomizableThreadFactory ("text-document-service-" ));
129
+
126
130
@ Override
127
131
public CompletableFuture <Hover > hover (HoverParams params ) {
128
132
var documentContext = context .getDocument (params .getTextDocument ().getUri ());
129
133
if (documentContext == null ) {
130
134
return CompletableFuture .completedFuture (null );
131
135
}
132
- return CompletableFuture .supplyAsync (() ->
133
- hoverProvider .getHover (documentContext , params ).orElse (null )
136
+ return CompletableFuture .supplyAsync (
137
+ () -> hoverProvider .getHover (documentContext , params ).orElse (null ),
138
+ executorService
134
139
);
135
140
}
136
141
@@ -143,8 +148,9 @@ public CompletableFuture<Either<List<? extends Location>, List<? extends Locatio
143
148
return CompletableFuture .completedFuture (Either .forRight (Collections .emptyList ()));
144
149
}
145
150
146
- return CompletableFuture .supplyAsync (() ->
147
- Either .forRight (definitionProvider .getDefinition (documentContext , params ))
151
+ return CompletableFuture .supplyAsync (
152
+ () -> Either .forRight (definitionProvider .getDefinition (documentContext , params )),
153
+ executorService
148
154
);
149
155
}
150
156
@@ -155,7 +161,10 @@ public CompletableFuture<List<? extends Location>> references(ReferenceParams pa
155
161
return CompletableFuture .completedFuture (Collections .emptyList ());
156
162
}
157
163
158
- return CompletableFuture .supplyAsync (() -> referencesProvider .getReferences (documentContext , params ));
164
+ return CompletableFuture .supplyAsync (
165
+ () -> referencesProvider .getReferences (documentContext , params ),
166
+ executorService
167
+ );
159
168
}
160
169
161
170
@ Override
@@ -167,10 +176,11 @@ public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> docume
167
176
return CompletableFuture .completedFuture (null );
168
177
}
169
178
170
- return CompletableFuture .supplyAsync (() ->
171
- documentSymbolProvider .getDocumentSymbols (documentContext ).stream ()
179
+ return CompletableFuture .supplyAsync (
180
+ () -> documentSymbolProvider .getDocumentSymbols (documentContext ).stream ()
172
181
.map (Either ::<SymbolInformation , DocumentSymbol >forRight )
173
- .collect (Collectors .toList ())
182
+ .toList (),
183
+ executorService
174
184
);
175
185
}
176
186
@@ -181,7 +191,10 @@ public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActio
181
191
return CompletableFuture .completedFuture (null );
182
192
}
183
193
184
- return CompletableFuture .supplyAsync (() -> codeActionProvider .getCodeActions (params , documentContext ));
194
+ return CompletableFuture .supplyAsync (
195
+ () -> codeActionProvider .getCodeActions (params , documentContext ),
196
+ executorService
197
+ );
185
198
}
186
199
187
200
@ Override
@@ -191,7 +204,10 @@ public CompletableFuture<List<? extends CodeLens>> codeLens(CodeLensParams param
191
204
return CompletableFuture .completedFuture (Collections .emptyList ());
192
205
}
193
206
194
- return CompletableFuture .supplyAsync (() -> codeLensProvider .getCodeLens (documentContext ));
207
+ return CompletableFuture .supplyAsync (
208
+ () -> codeLensProvider .getCodeLens (documentContext ),
209
+ executorService
210
+ );
195
211
}
196
212
197
213
@ Override
@@ -201,7 +217,10 @@ public CompletableFuture<CodeLens> resolveCodeLens(CodeLens unresolved) {
201
217
if (documentContext == null ) {
202
218
return CompletableFuture .completedFuture (unresolved );
203
219
}
204
- return CompletableFuture .supplyAsync (() -> codeLensProvider .resolveCodeLens (documentContext , unresolved , data ));
220
+ return CompletableFuture .supplyAsync (
221
+ () -> codeLensProvider .resolveCodeLens (documentContext , unresolved , data ),
222
+ executorService
223
+ );
205
224
}
206
225
207
226
@ Override
@@ -211,8 +230,10 @@ public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormatting
211
230
return CompletableFuture .completedFuture (null );
212
231
}
213
232
214
- List <TextEdit > edits = formatProvider .getFormatting (params , documentContext );
215
- return CompletableFuture .completedFuture (edits );
233
+ return CompletableFuture .supplyAsync (
234
+ () -> formatProvider .getFormatting (params , documentContext ),
235
+ executorService
236
+ );
216
237
}
217
238
218
239
@ Override
@@ -222,8 +243,10 @@ public CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRange
222
243
return CompletableFuture .completedFuture (null );
223
244
}
224
245
225
- List <TextEdit > edits = formatProvider .getRangeFormatting (params , documentContext );
226
- return CompletableFuture .completedFuture (edits );
246
+ return CompletableFuture .supplyAsync (
247
+ () -> formatProvider .getRangeFormatting (params , documentContext ),
248
+ executorService
249
+ );
227
250
}
228
251
229
252
@ Override
@@ -233,7 +256,10 @@ public CompletableFuture<List<FoldingRange>> foldingRange(FoldingRangeRequestPar
233
256
return CompletableFuture .completedFuture (null );
234
257
}
235
258
236
- return CompletableFuture .supplyAsync (() -> foldingRangeProvider .getFoldingRange (documentContext ));
259
+ return CompletableFuture .supplyAsync (
260
+ () -> foldingRangeProvider .getFoldingRange (documentContext ),
261
+ executorService
262
+ );
237
263
}
238
264
239
265
@ Override
@@ -244,13 +270,15 @@ public CompletableFuture<List<CallHierarchyItem>> prepareCallHierarchy(CallHiera
244
270
return CompletableFuture .completedFuture (null );
245
271
}
246
272
247
- return CompletableFuture .supplyAsync (() -> {
248
- List <CallHierarchyItem > callHierarchyItems = callHierarchyProvider .prepareCallHierarchy (documentContext , params );
249
- if (callHierarchyItems .isEmpty ()) {
250
- return null ;
251
- }
252
- return callHierarchyItems ;
253
- });
273
+ return CompletableFuture .supplyAsync (
274
+ () -> {
275
+ List <CallHierarchyItem > callHierarchyItems = callHierarchyProvider .prepareCallHierarchy (documentContext , params );
276
+ if (callHierarchyItems .isEmpty ()) {
277
+ return null ;
278
+ }
279
+ return callHierarchyItems ;
280
+ },
281
+ executorService );
254
282
}
255
283
256
284
@ Override
@@ -262,7 +290,10 @@ public CompletableFuture<List<CallHierarchyIncomingCall>> callHierarchyIncomingC
262
290
return CompletableFuture .completedFuture (Collections .emptyList ());
263
291
}
264
292
265
- return CompletableFuture .supplyAsync (() -> callHierarchyProvider .incomingCalls (documentContext , params ));
293
+ return CompletableFuture .supplyAsync (
294
+ () -> callHierarchyProvider .incomingCalls (documentContext , params ),
295
+ executorService
296
+ );
266
297
}
267
298
268
299
@ Override
@@ -274,7 +305,10 @@ public CompletableFuture<List<CallHierarchyOutgoingCall>> callHierarchyOutgoingC
274
305
return CompletableFuture .completedFuture (Collections .emptyList ());
275
306
}
276
307
277
- return CompletableFuture .supplyAsync (() -> callHierarchyProvider .outgoingCalls (documentContext , params ));
308
+ return CompletableFuture .supplyAsync (
309
+ () -> callHierarchyProvider .outgoingCalls (documentContext , params ),
310
+ executorService
311
+ );
278
312
}
279
313
280
314
@ Override
@@ -284,7 +318,10 @@ public CompletableFuture<List<SelectionRange>> selectionRange(SelectionRangePara
284
318
return CompletableFuture .completedFuture (Collections .emptyList ());
285
319
}
286
320
287
- return CompletableFuture .supplyAsync (() -> selectionRangeProvider .getSelectionRange (documentContext , params ));
321
+ return CompletableFuture .supplyAsync (
322
+ () -> selectionRangeProvider .getSelectionRange (documentContext , params ),
323
+ executorService
324
+ );
288
325
}
289
326
290
327
@ Override
@@ -294,7 +331,10 @@ public CompletableFuture<List<ColorInformation>> documentColor(DocumentColorPara
294
331
return CompletableFuture .completedFuture (Collections .emptyList ());
295
332
}
296
333
297
- return CompletableFuture .supplyAsync (() -> colorProvider .getDocumentColor (documentContext ));
334
+ return CompletableFuture .supplyAsync (
335
+ () -> colorProvider .getDocumentColor (documentContext ),
336
+ executorService
337
+ );
298
338
}
299
339
300
340
@ Override
@@ -304,7 +344,10 @@ public CompletableFuture<List<ColorPresentation>> colorPresentation(ColorPresent
304
344
return CompletableFuture .completedFuture (Collections .emptyList ());
305
345
}
306
346
307
- return CompletableFuture .supplyAsync (() -> colorProvider .getColorPresentation (documentContext , params ));
347
+ return CompletableFuture .supplyAsync (
348
+ () -> colorProvider .getColorPresentation (documentContext , params ),
349
+ executorService
350
+ );
308
351
}
309
352
310
353
@ Override
@@ -314,7 +357,10 @@ public CompletableFuture<List<InlayHint>> inlayHint(InlayHintParams params) {
314
357
return CompletableFuture .completedFuture (Collections .emptyList ());
315
358
}
316
359
317
- return CompletableFuture .supplyAsync (() -> inlayHintProvider .getInlayHint (documentContext , params ));
360
+ return CompletableFuture .supplyAsync (
361
+ () -> inlayHintProvider .getInlayHint (documentContext , params ),
362
+ executorService
363
+ );
318
364
}
319
365
320
366
@ Override
@@ -380,7 +426,10 @@ public CompletableFuture<List<DocumentLink>> documentLink(DocumentLinkParams par
380
426
return CompletableFuture .completedFuture (null );
381
427
}
382
428
383
- return CompletableFuture .supplyAsync (() -> documentLinkProvider .getDocumentLinks (documentContext ));
429
+ return CompletableFuture .supplyAsync (
430
+ () -> documentLinkProvider .getDocumentLinks (documentContext ),
431
+ executorService
432
+ );
384
433
}
385
434
386
435
@ Override
@@ -397,7 +446,7 @@ public CompletableFuture<Diagnostics> diagnostics(DiagnosticParams params) {
397
446
if (range != null ) {
398
447
diagnostics = diagnostics .stream ()
399
448
.filter (diagnostic -> Ranges .containsRange (range , diagnostic .getRange ()))
400
- .collect ( Collectors . toList () );
449
+ .toList ();
401
450
}
402
451
return new Diagnostics (diagnostics , documentContext .getVersion ());
403
452
});
@@ -410,8 +459,10 @@ public CompletableFuture<Either3<Range, PrepareRenameResult, PrepareRenameDefaul
410
459
return CompletableFuture .completedFuture (null );
411
460
}
412
461
413
- return CompletableFuture .supplyAsync (() ->
414
- Either3 .forFirst (renameProvider .getPrepareRename (documentContext , params )));
462
+ return CompletableFuture .supplyAsync (
463
+ () -> Either3 .forFirst (renameProvider .getPrepareRename (documentContext , params )),
464
+ executorService
465
+ );
415
466
}
416
467
417
468
@ Override
@@ -421,7 +472,10 @@ public CompletableFuture<WorkspaceEdit> rename(RenameParams params) {
421
472
return CompletableFuture .completedFuture (null );
422
473
}
423
474
424
- return CompletableFuture .supplyAsync (() -> renameProvider .getRename (documentContext , params ));
475
+ return CompletableFuture .supplyAsync (
476
+ () -> renameProvider .getRename (documentContext , params ),
477
+ executorService
478
+ );
425
479
}
426
480
427
481
public void reset () {
0 commit comments