Skip to content

Commit

Permalink
chore: Support Jetbrains IDEs 243 - take into account that addListene…
Browse files Browse the repository at this point in the history
…r expects suspend function (#6782)
  • Loading branch information
tpasternak authored Sep 24, 2024
1 parent 1d56586 commit ade3e21
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,35 @@
import com.intellij.openapi.Disposable;
import com.intellij.openapi.components.ComponentManagerEx;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;

import com.intellij.util.JavaCoroutines;
import com.intellij.vfs.AsyncVfsEventsListener;
import com.intellij.vfs.AsyncVfsEventsPostProcessor;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.function.Consumer;

// #api242
public class AsyncVfsEventsPostProcessorCompat {
private AsyncVfsEventsPostProcessorCompat(){

}

public static void addListener(AsyncVfsEventsListener listener, Disposable disposable, Project project) {
AsyncVfsEventsPostProcessor.getInstance().addListener(listener, ((ComponentManagerEx)project).getCoroutineScope());
public static void addListener(Consumer<List<? extends VFileEvent>> listener, Disposable disposable, Project project) {
AsyncVfsEventsPostProcessor.getInstance().addListener(new AsyncVfsEventsListener() {
@Override
public @Nullable Object filesChanged(@NotNull List<? extends VFileEvent> list, @NotNull Continuation<? super Unit> continuation) {
return JavaCoroutines.suspendJava(javaContinuation -> {
listener.accept(list);
javaContinuation.resume(Unit.INSTANCE);
}
, continuation);
}
}, ((ComponentManagerEx) project).getCoroutineScope());
}
}

0 comments on commit ade3e21

Please sign in to comment.