Skip to content

Commit

Permalink
fixes kotlin configuration deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
LeFrosch committed Oct 2, 2024
1 parent 6f2be3e commit 2072ae8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object ProgressIndicatorStub : ProgressIndicatorEx {

override fun isModal(): Boolean { return false }

override fun getModalityState(): ModalityState { return ModalityState.defaultModalityState() }
override fun getModalityState(): ModalityState { return ModalityState.nonModal() }

override fun setModalityProgress(p0: ProgressIndicator?) { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.idea.blaze.base.async.executor.ProgressIndicatorStub;
import com.google.idea.blaze.base.ideinfo.KotlinToolchainIdeInfo;
import com.google.idea.blaze.base.model.BlazeProjectData;
import com.google.idea.blaze.base.model.BlazeVersionData;
Expand All @@ -44,6 +45,7 @@
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.pom.java.LanguageLevel;
Expand Down Expand Up @@ -326,31 +328,33 @@ public void afterSync(
KotlinJavaModuleConfigurator.Companion.getInstance();
NotificationMessageCollector collector =
new NotificationMessageCollector(project, "Configuring Kotlin", "Configuring Kotlin");
Application application = ApplicationManager.getApplication();

application.invokeAndWait(
() -> {
configurator.getOrCreateKotlinLibrary(project, collector);
});

List<Function0<Unit>> writeActions = new ArrayList<>();
application.runReadAction(
() -> {
configurator.configureModule(workspaceModule, collector, writeActions);
});

if (ApplicationManager.getApplication().isUnitTestMode()) {
// do not invoke it later since serviceContainer may be disposed before it get completed
ProgressManager.getInstance().runProcess(() -> {
Application application = ApplicationManager.getApplication();
application.invokeAndWait(
() -> {
writeActions.stream().forEach(Function0::invoke);
configurator.getOrCreateKotlinLibrary(project, collector);
});
} else {
application.invokeLater(

List<Function0<Unit>> writeActions = new ArrayList<>();
application.runReadAction(
() -> {
writeActions.stream().forEach(Function0::invoke);
configurator.configureModule(workspaceModule, collector, writeActions);
});
}

if (ApplicationManager.getApplication().isUnitTestMode()) {
// do not invoke it later since serviceContainer may be disposed before it get completed
application.invokeAndWait(
() -> {
writeActions.stream().forEach(Function0::invoke);
});
} else {
application.invokeLater(
() -> {
writeActions.stream().forEach(Function0::invoke);
});
}
}, ProgressIndicatorStub.INSTANCE);
}
}
}

0 comments on commit 2072ae8

Please sign in to comment.