Search in sources :

Example 31 with FileURI

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

the class AbstractIdeTest method changeFilesOnDiskWithoutNotification.

/**
 * Same as {@link #changeFileOnDiskWithoutNotification(FileURI, Function)}, but changes one or more files at once,
 * as defined by the given {@link WorkspaceEdit}.
 */
protected List<Pair<FileURI, List<TextEdit>>> changeFilesOnDiskWithoutNotification(WorkspaceEdit workspaceEdit) {
    List<Either<TextDocumentEdit, ResourceOperation>> documentChanges = workspaceEdit.getDocumentChanges();
    if (documentChanges != null && !documentChanges.isEmpty()) {
        List<Pair<FileURI, List<TextEdit>>> appliedChanges = new ArrayList<>();
        for (Either<TextDocumentEdit, ResourceOperation> documentChange : documentChanges) {
            if (documentChange.isRight()) {
                throw new UnsupportedOperationException("resource operations not yet supported by AbstractIdeTest");
            }
            TextDocumentEdit edit = documentChange.getLeft();
            if (edit.getTextDocument().getVersion() != null) {
                throw new UnsupportedOperationException("text document versions not yet supported by AbstractIdeTest");
            }
            FileURI fileURI = getFileURIFromURIString(edit.getTextDocument().getUri());
            changeFileOnDiskWithoutNotification(fileURI, edit.getEdits());
            appliedChanges.add(Pair.of(fileURI, edit.getEdits()));
        }
        return appliedChanges;
    }
    Map<String, List<TextEdit>> changes = workspaceEdit.getChanges();
    if (changes != null && !changes.isEmpty()) {
        List<Pair<FileURI, List<TextEdit>>> appliedChanges = new ArrayList<>();
        for (Entry<String, List<TextEdit>> entry : changes.entrySet()) {
            FileURI fileURI = getFileURIFromURIString(entry.getKey());
            changeFileOnDiskWithoutNotification(fileURI, entry.getValue());
            appliedChanges.add(Pair.of(fileURI, entry.getValue()));
        }
        return appliedChanges;
    }
    List<Either<ResourceChange, TextDocumentEdit>> resourceChanges = workspaceEdit.getResourceChanges();
    if (resourceChanges != null && !resourceChanges.isEmpty()) {
        throw new UnsupportedOperationException("deprecated property 'WorkspaceEdit#resourceChanges' is not supported");
    }
    throw new IllegalArgumentException("workspace edit without changes");
}
Also used : ArrayList(java.util.ArrayList) TextDocumentEdit(org.eclipse.lsp4j.TextDocumentEdit) FileURI(org.eclipse.n4js.workspace.locations.FileURI) TextEdit(org.eclipse.lsp4j.TextEdit) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) Pair(org.eclipse.xtext.xbase.lib.Pair) ResourceOperation(org.eclipse.lsp4j.ResourceOperation)

Example 32 with FileURI

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

the class AbstractIdeTest method changeFileOnDiskWithoutNotification.

/**
 * Same as {@link #changeFileOnDiskWithoutNotification(FileURI, Pair...)}, accepting a module name instead of a file
 * URI.
 */
@SafeVarargs
protected final void changeFileOnDiskWithoutNotification(String moduleName, Pair<String, ? extends CharSequence>... replacements) {
    FileURI fileURI = getFileURIFromModuleName(moduleName);
    changeFileOnDiskWithoutNotification(fileURI, replacements);
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI)

Example 33 with FileURI

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

the class AbstractIdeTest method renameFileOnDiskWithoutNotification.

/**
 * Same as {@link #renameFileOnDiskWithoutNotification(FileURI, String)}, accepting a module name.
 */
protected void renameFileOnDiskWithoutNotification(String moduleName, String newFileNameIncludingExtension) {
    FileURI fileURI = getFileURIFromModuleName(moduleName);
    renameFileOnDiskWithoutNotification(fileURI, newFileNameIncludingExtension);
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI)

Example 34 with FileURI

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

the class AbstractIdeTest method moveFile.

/**
 * Moves the given file or folder to the new location and notifies the server.
 */
protected void moveFile(FileURI fileURI, File newLocation) {
    FileURI newFileURI = toFileURI(newLocation).appendSegment(fileURI.getName());
    internalMoveFile(fileURI, newFileURI, true);
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI)

Example 35 with FileURI

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

the class AbstractIdeTest method renameFileOnDiskWithoutNotification.

/**
 * Rename an existing file on disk without notifying the LSP server about it.
 */
protected void renameFileOnDiskWithoutNotification(FileURI fileURI, String newFileNameIncludingExtension) {
    FileURI fileURIRenamed = fileURI.getParent().appendSegment(newFileNameIncludingExtension);
    internalMoveFile(fileURI, fileURIRenamed, false);
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI)

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