Search in sources :

Example 1 with TestOrganizeImportsConfiguration

use of org.eclipse.n4js.ide.tests.helper.server.AbstractOrganizeImportsTest.TestOrganizeImportsConfiguration in project n4js by eclipse.

the class AbstractOrganizeImportsTest method performTest.

@Override
protected void performTest(Project project, String moduleName, TestOrganizeImportsConfiguration config) throws Exception {
    FileURI uri = getFileURIFromModuleName(moduleName);
    if (config.expectedIssues.isEmpty()) {
        assertNoIssues();
    } else {
        assertIssues(Collections.singletonMap(uri, config.expectedIssues));
    }
    TextDocumentIdentifier id = new TextDocumentIdentifier(uri.toString());
    Range range = new Range(new Position(0, 0), new Position(0, 0));
    CodeActionContext context = new CodeActionContext();
    CodeActionParams params = new CodeActionParams(id, range, context);
    CompletableFuture<List<Either<Command, CodeAction>>> codeActionFuture = languageServer.codeAction(params);
    List<Either<Command, CodeAction>> result = codeActionFuture.join();
    Command organizeImportsCommand = result.stream().map(e -> e.isLeft() ? e.getLeft() : e.getRight().getCommand()).filter(cmd -> cmd != null && Objects.equals(cmd.getCommand(), N4JSCommandService.N4JS_ORGANIZE_IMPORTS)).findFirst().orElse(null);
    Assert.assertNotNull("code action for organize imports not found", organizeImportsCommand);
    ExecuteCommandParams execParams = new ExecuteCommandParams(organizeImportsCommand.getCommand(), organizeImportsCommand.getArguments());
    CompletableFuture<Object> execFuture = languageServer.executeCommand(execParams);
    execFuture.join();
    joinServerRequests();
    assertContentOfFileOnDisk(uri, config.expectedCode);
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) Iterables(com.google.common.collect.Iterables) IssueCodes(org.eclipse.n4js.validation.IssueCodes) CompletableFuture(java.util.concurrent.CompletableFuture) Range(org.eclipse.lsp4j.Range) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) Lists(com.google.common.collect.Lists) ExecuteCommandParams(org.eclipse.lsp4j.ExecuteCommandParams) N4JSLanguageConstants(org.eclipse.n4js.N4JSLanguageConstants) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Position(org.eclipse.lsp4j.Position) N4JSCommandService(org.eclipse.n4js.ide.server.commands.N4JSCommandService) CodeAction(org.eclipse.lsp4j.CodeAction) FileURI(org.eclipse.n4js.workspace.locations.FileURI) Set(java.util.Set) Project(org.eclipse.n4js.tests.codegen.Project) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) Strings(org.eclipse.n4js.utils.Strings) List(java.util.List) Command(org.eclipse.lsp4j.Command) TestOrganizeImportsConfiguration(org.eclipse.n4js.ide.tests.helper.server.AbstractOrganizeImportsTest.TestOrganizeImportsConfiguration) Pair(org.eclipse.xtext.xbase.lib.Pair) Assert(org.junit.Assert) Collections(java.util.Collections) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) CodeAction(org.eclipse.lsp4j.CodeAction) ExecuteCommandParams(org.eclipse.lsp4j.ExecuteCommandParams) 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

Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)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 ExecuteCommandParams (org.eclipse.lsp4j.ExecuteCommandParams)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 N4JSLanguageConstants (org.eclipse.n4js.N4JSLanguageConstants)1 N4JSCommandService (org.eclipse.n4js.ide.server.commands.N4JSCommandService)1 TestOrganizeImportsConfiguration (org.eclipse.n4js.ide.tests.helper.server.AbstractOrganizeImportsTest.TestOrganizeImportsConfiguration)1