@Test void testCodeActionsEndpoint() { DataBusBroker broker = mock(DataBusBroker.class); CodeActions actions = mock(CodeActions.class); CodeActionParams params = new CodeActionParams(new TextDocumentIdentifier(DOCUMENT_URI), null, null); List<Either<Command, CodeAction>> expected = emptyList(); when(actions.collect(params)).thenReturn(expected); MyTextDocumentService service = MyTextDocumentService.builder().dataBus(broker).actions(actions).build(); try { assertEquals(expected, service.codeAction(params).get()); } catch (InterruptedException | ExecutionException e) { fail(e.getMessage()); } verify(actions).collect(params); }
@Override public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) { return supplyAsync(() -> actions.collect(params)) .whenComplete( reportExceptionIfThrown( createDescriptiveErrorMessage( "code actions lookup", params.getTextDocument().getUri()))); }
MyTextDocumentService implements TextDocumentService, EventObserver<RunAnalysisEvent> { @Override public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) { return supplyAsync(() -> actions.collect(params)) .whenComplete( reportExceptionIfThrown( createDescriptiveErrorMessage( "code actions lookup", params.getTextDocument().getUri()))); } }
MyTextDocumentService implements TextDocumentService, EventObserver<RunAnalysisEvent> { @Override public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) { return supplyAsync(() -> actions.collect(params)) .whenComplete( reportExceptionIfThrown( createDescriptiveErrorMessage( "code actions lookup", params.getTextDocument().getUri()))); } @Inject @Builder  MyTextDocumentService(
      Communications communications,
      LanguageEngineFacade engine,
      Formations formations,
      Completions completions,
      Occurrences occurrences,
      DataBusBroker dataBus,
      CodeActions actions); }
MyTextDocumentService implements TextDocumentService, EventObserver<RunAnalysisEvent> { @Override public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) { return supplyAsync(() -> actions.collect(params)) .whenComplete( reportExceptionIfThrown( createDescriptiveErrorMessage( "code actions lookup", params.getTextDocument().getUri()))); } @Inject @Builder  MyTextDocumentService(
      Communications communications,
      LanguageEngineFacade engine,
      Formations formations,
      Completions completions,
      Occurrences occurrences,
      DataBusBroker dataBus,
      CodeActions actions); @Override CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(
      CompletionParams params); @Override CompletableFuture<CompletionItem> resolveCompletionItem(CompletionItem unresolved); @Override CompletableFuture<List<? extends Location>> definition(
      TextDocumentPositionParams position); @Override CompletableFuture<List<? extends Location>> references(ReferenceParams params); @Override CompletableFuture<List<? extends DocumentHighlight>> documentHighlight(
      TextDocumentPositionParams position); @Override CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params); @Override CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params); @Override void didOpen(DidOpenTextDocumentParams params); @Override void didChange(DidChangeTextDocumentParams params); @Override void didClose(DidCloseTextDocumentParams params); @Override void didSave(DidSaveTextDocumentParams params); @Override void observerCallback(@Nonnull RunAnalysisEvent event); @Override CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(DocumentSymbolParams params); }
MyTextDocumentService implements TextDocumentService, EventObserver<RunAnalysisEvent> { @Override public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) { return supplyAsync(() -> actions.collect(params)) .whenComplete( reportExceptionIfThrown( createDescriptiveErrorMessage( "code actions lookup", params.getTextDocument().getUri()))); } @Inject @Builder  MyTextDocumentService(
      Communications communications,
      LanguageEngineFacade engine,
      Formations formations,
      Completions completions,
      Occurrences occurrences,
      DataBusBroker dataBus,
      CodeActions actions); @Override CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(
      CompletionParams params); @Override CompletableFuture<CompletionItem> resolveCompletionItem(CompletionItem unresolved); @Override CompletableFuture<List<? extends Location>> definition(
      TextDocumentPositionParams position); @Override CompletableFuture<List<? extends Location>> references(ReferenceParams params); @Override CompletableFuture<List<? extends DocumentHighlight>> documentHighlight(
      TextDocumentPositionParams position); @Override CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params); @Override CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params); @Override void didOpen(DidOpenTextDocumentParams params); @Override void didChange(DidChangeTextDocumentParams params); @Override void didClose(DidCloseTextDocumentParams params); @Override void didSave(DidSaveTextDocumentParams params); @Override void observerCallback(@Nonnull RunAnalysisEvent event); @Override CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(DocumentSymbolParams params);  }