Search in sources :

Example 1 with N4JSTestCodeActionConfiguration

use of org.eclipse.n4js.ide.tests.helper.server.AbstractCodeActionTest.N4JSTestCodeActionConfiguration in project n4js by eclipse.

the class AbstractCodeActionTest method performTest.

@Override
protected void performTest(Project project, String moduleName, N4JSTestCodeActionConfiguration tcac) throws InterruptedException, ExecutionException {
    CodeActionParams codeActionParams = new CodeActionParams();
    Range range = new Range();
    Position posStart = new Position(tcac.getLine(), tcac.getColumn());
    Position posEnd = tcac.getEndLine() >= 0 && tcac.getEndColumn() >= 0 ? new Position(tcac.getEndLine(), tcac.getEndColumn()) : posStart;
    range.setStart(posStart);
    range.setEnd(posEnd);
    codeActionParams.setRange(range);
    CodeActionContext context = new CodeActionContext();
    FileURI uri = getFileURIFromModuleName(moduleName);
    context.setDiagnostics(Lists.newArrayList(getIssuesInFile(uri)));
    codeActionParams.setContext(context);
    TextDocumentIdentifier textDocument = new TextDocumentIdentifier();
    textDocument.setUri(uri.toString());
    codeActionParams.setTextDocument(textDocument);
    CompletableFuture<List<Either<Command, CodeAction>>> future = languageServer.codeAction(codeActionParams);
    List<Either<Command, CodeAction>> result = future.get();
    if (tcac.getAssertCodeActions() != null) {
        tcac.getAssertCodeActions().apply(result);
    } else {
        String resultStr = result.stream().map(cmdOrAction -> getStringLSP4J().toString3(cmdOrAction)).collect(Collectors.joining("\n-----\n"));
        assertEquals(tcac.getExpectedCodeActions().trim(), resultStr.trim());
    }
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) CodeAction(org.eclipse.lsp4j.CodeAction) FileURI(org.eclipse.n4js.workspace.locations.FileURI) N4JSTestCodeActionConfiguration(org.eclipse.n4js.ide.tests.helper.server.AbstractCodeActionTest.N4JSTestCodeActionConfiguration) TestCodeActionConfiguration(org.eclipse.xtext.testing.AbstractLanguageServerTest.TestCodeActionConfiguration) CompletableFuture(java.util.concurrent.CompletableFuture) Range(org.eclipse.lsp4j.Range) Project(org.eclipse.n4js.tests.codegen.Project) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Collectors(java.util.stream.Collectors) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) ExecutionException(java.util.concurrent.ExecutionException) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) List(java.util.List) Lists(com.google.common.collect.Lists) Command(org.eclipse.lsp4j.Command) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Position(org.eclipse.lsp4j.Position) Assert.assertEquals(org.junit.Assert.assertEquals) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) CodeAction(org.eclipse.lsp4j.CodeAction) Range(org.eclipse.lsp4j.Range) FileURI(org.eclipse.n4js.workspace.locations.FileURI) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Command(org.eclipse.lsp4j.Command) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) List(java.util.List)

Aggregations

Lists (com.google.common.collect.Lists)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1 CodeAction (org.eclipse.lsp4j.CodeAction)1 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)1 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)1 Command (org.eclipse.lsp4j.Command)1 Position (org.eclipse.lsp4j.Position)1 Range (org.eclipse.lsp4j.Range)1 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)1 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)1 N4JSTestCodeActionConfiguration (org.eclipse.n4js.ide.tests.helper.server.AbstractCodeActionTest.N4JSTestCodeActionConfiguration)1 Project (org.eclipse.n4js.tests.codegen.Project)1 FileURI (org.eclipse.n4js.workspace.locations.FileURI)1 TestCodeActionConfiguration (org.eclipse.xtext.testing.AbstractLanguageServerTest.TestCodeActionConfiguration)1 Assert.assertEquals (org.junit.Assert.assertEquals)1