Skip to content

Commit

Permalink
FL-17684 show target chooser synchronously in headless mode
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 153a69e82aa271159976cd76fafb1ba10e0698ce
  • Loading branch information
valich authored and intellij-monorepo-bot committed Feb 13, 2023
1 parent 1c37a1d commit 2dc8084
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
import com.intellij.codeInsight.navigation.NavigationUtil;
import com.intellij.codeInsight.unwrap.ScopeHighlighter;
import com.intellij.ide.IdeBundle;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.application.NonBlockingReadAction;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressIndicatorProvider;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.*;
import com.intellij.openapi.util.NlsContexts;
Expand Down Expand Up @@ -66,11 +71,18 @@ public static <T extends PsiElement> void showChooser(@NotNull Editor editor,
@NotNull @NlsContexts.PopupTitle String title,
int selection,
@NotNull NotNullFunction<? super PsiElement, ? extends TextRange> ranger) {
ReadAction.nonBlocking(() -> ContainerUtil.map(expressions, t -> new MyIntroduceTarget<>(t, ranger.fun(t), renderer.fun(t))))
.finishOnUiThread(ModalityState.NON_MODAL, targets ->
showIntroduceTargetChooser(editor, targets, target -> callback.pass(target.getPlace()), title, selection))
.expireWhen(() -> editor.isDisposed())
.submit(AppExecutorUtil.getAppExecutorService());

if (ApplicationManager.getApplication().isHeadlessEnvironment()) {
List<MyIntroduceTarget<T>> targets = ContainerUtil.map(expressions, t -> new MyIntroduceTarget<>(t, ranger.fun(t), renderer.fun(t)));
showIntroduceTargetChooser(editor, targets, target -> callback.pass(target.getPlace()), title, selection);
}
else {
ReadAction.nonBlocking(() -> ContainerUtil.map(expressions, t -> new MyIntroduceTarget<>(t, ranger.fun(t), renderer.fun(t))))
.finishOnUiThread(ModalityState.NON_MODAL, targets ->
showIntroduceTargetChooser(editor, targets, target -> callback.pass(target.getPlace()), title, selection))
.expireWhen(() -> editor.isDisposed())
.submit(AppExecutorUtil.getAppExecutorService());
}
}

public static <T extends IntroduceTarget> void showIntroduceTargetChooser(@NotNull Editor editor,
Expand Down

0 comments on commit 2dc8084

Please sign in to comment.