Search in sources :

Example 11 with FileURI

use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.

the class AbstractIdeTest method assertFile.

/**
 * Asserts the workspace contains the given file. {@link #getFileURIFromModuleName(String)}
 */
protected void assertFile(String moduleName) {
    try {
        FileURI file = getFileURIFromModuleName(moduleName);
        assertNotNull(file);
    } catch (Exception e) {
        fail();
    }
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI) WrappedException(org.eclipse.emf.common.util.WrappedException) IOException(java.io.IOException)

Example 12 with FileURI

use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.

the class AbstractIdeTest method createFileOnDiskWithoutNotification.

/**
 * Same as {@link #createFileOnDiskWithoutNotification(FileURI, CharSequence)}, placing the new file next to an
 * existing module.
 */
protected void createFileOnDiskWithoutNotification(String existingModuleName, String newFileNameIncludingExtension, CharSequence content) {
    FileURI existingFileURI = getFileURIFromModuleName(existingModuleName);
    FileURI newFileURI = existingFileURI.getParent().appendSegment(newFileNameIncludingExtension);
    createFileOnDiskWithoutNotification(newFileURI, content);
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI)

Example 13 with FileURI

use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.

the class AbstractIdeTest method assertIssues.

/**
 * Same as {@link #assertIssuesInFiles(Map, boolean)}, but in addition to checking the files denoted by the given
 * map's keys, this method will also assert that the remaining files in the workspace do not contain any issues.
 * Flag <code>withIgnoredIssues</code> applies to those issues accordingly.
 */
protected void assertIssues(Map<FileURI, List<String>> fileURIToExpectedIssues, boolean withIgnoredIssues) {
    // check given expectations
    assertIssuesInFiles(fileURIToExpectedIssues, withIgnoredIssues);
    Set<FileURI> checkedModules = fileURIToExpectedIssues.keySet();
    // check that there are no other issues in the workspace
    Multimap<FileURI, Diagnostic> allIssues = languageClient.getIssues();
    Set<FileURI> modulesWithIssues = allIssues.keySet();
    Set<FileURI> uncheckedModulesWithIssues = new LinkedHashSet<>(modulesWithIssues);
    uncheckedModulesWithIssues.removeAll(checkedModules);
    if (!uncheckedModulesWithIssues.isEmpty()) {
        Multimap<FileURI, String> issuesPerUncheckedModule = LinkedHashMultimap.create();
        for (FileURI currModuleURI : uncheckedModulesWithIssues) {
            List<String> currModuleIssuesAsList = getIssueStringsInFile(currModuleURI, withIgnoredIssues);
            issuesPerUncheckedModule.putAll(currModuleURI, currModuleIssuesAsList);
        }
        if (!issuesPerUncheckedModule.isEmpty()) {
            // empty if all remaining issues are ignored
            String msg = fileURIToExpectedIssues.size() == 0 ? "expected no issues in workspace but found one or more issues:" : "found one or more unexpected issues in workspace:";
            Assert.fail(msg + "\n" + issuesToString(issuesPerUncheckedModule));
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FileURI(org.eclipse.n4js.workspace.locations.FileURI) Diagnostic(org.eclipse.lsp4j.Diagnostic)

Example 14 with FileURI

use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.

the class AbstractRenameTest method performTestAtPosition.

private void performTestAtPosition(RenamePosition pos, RenameTestConfiguration config) throws InterruptedException, ExecutionException {
    FileURI fileURI = getFileURIFromModuleName(pos.moduleName);
    String uriStr = fileURI.toString();
    // ensure the file with URI 'fileURI' is open and is the only opened file
    if (!getOpenFiles().equals(Collections.singleton(fileURI))) {
        closeAllFiles();
        joinServerRequests();
        openFile(fileURI);
        joinServerRequests();
    }
    String sourceBefore = config.projectsModulesSourcesBefore.get(pos.projectName).get(pos.moduleName);
    PrepareRenameParams prepareRenameParams = new PrepareRenameParams();
    prepareRenameParams.setTextDocument(new TextDocumentIdentifier(uriStr));
    prepareRenameParams.setPosition(new Position(pos.line, pos.column));
    Either<Range, PrepareRenameResult> result1 = languageServer.prepareRename(prepareRenameParams).get();
    if (result1 == null || (result1.getLeft() == null && result1.getRight() == null)) {
        fail("element cannot be renamed", sourceBefore, pos);
    }
    RenameParams renameParams = new RenameParams();
    renameParams.setTextDocument(new TextDocumentIdentifier(uriStr));
    renameParams.setPosition(new Position(pos.line, pos.column));
    renameParams.setNewName(config.newName);
    WorkspaceEdit workspaceEdit = languageServer.rename(renameParams).get();
    Map<FileURI, String> fileURI2ActualSourceAfter = applyWorkspaceEdit(config.projectsModulesSourcesBefore, workspaceEdit, pos, config);
    Set<FileURI> checkedFileURIs = new LinkedHashSet<>();
    for (Map<String, String> moduleName2ExpectedSourceAfter : config.projectsModulesExpectedSourcesAfter.values()) {
        for (Entry<String, String> entry : moduleName2ExpectedSourceAfter.entrySet()) {
            String moduleName = entry.getKey();
            String expectedSourceAfter = entry.getValue();
            FileURI changedFileURI = getFileURIFromModuleName(moduleName);
            String actualSourceAfter = fileURI2ActualSourceAfter.get(changedFileURI);
            if (actualSourceAfter == null) {
                fail("expected changes in module '" + moduleName + "' but rename did not lead to any changes in this module", sourceBefore, pos);
            } else if (!actualSourceAfter.equals(expectedSourceAfter)) {
                fail("rename led to incorrect source code changes in module '" + moduleName + "'", sourceBefore, pos, expectedSourceAfter, actualSourceAfter);
            }
            checkedFileURIs.add(changedFileURI);
        }
    }
    for (Entry<FileURI, String> entry : fileURI2ActualSourceAfter.entrySet()) {
        FileURI changedFileURI = entry.getKey();
        String actualSourceAfter = entry.getValue();
        if (!checkedFileURIs.contains(changedFileURI)) {
            fail("rename led to unexpected changes in file '" + changedFileURI.getName() + "'", sourceBefore, pos, null, actualSourceAfter);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) RenameParams(org.eclipse.lsp4j.RenameParams) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) PrepareRenameResult(org.eclipse.lsp4j.PrepareRenameResult) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) Range(org.eclipse.lsp4j.Range) FileURI(org.eclipse.n4js.workspace.locations.FileURI)

Example 15 with FileURI

use of org.eclipse.n4js.workspace.locations.FileURI 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

FileURI (org.eclipse.n4js.workspace.locations.FileURI)49 List (java.util.List)13 Path (java.nio.file.Path)11 ArrayList (java.util.ArrayList)11 File (java.io.File)10 Position (org.eclipse.lsp4j.Position)9 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)9 IOException (java.io.IOException)7 CompletionList (org.eclipse.lsp4j.CompletionList)7 Collections (java.util.Collections)6 Range (org.eclipse.lsp4j.Range)6 Lists (com.google.common.collect.Lists)5 Sets (com.google.common.collect.Sets)5 Files (java.nio.file.Files)5 LinkedHashSet (java.util.LinkedHashSet)5 Set (java.util.Set)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 URI (org.eclipse.emf.common.util.URI)5 CompletionItem (org.eclipse.lsp4j.CompletionItem)5 Diagnostic (org.eclipse.lsp4j.Diagnostic)5