Repository: intellij-rust/intellij-rust
Issue: There is an exception after opening a project on wsl

## Environment

* **IntelliJ Rust plugin version:** 0.4.169.4542-221-nightly
* **Rust toolchain version:** null
* **IDE name and version:** CLion 2022.1 Beta (CL-221.5080.93)
* **Operating system:** Windows 10 10.0
* **Macro expansion engine:** new
* **Name resolution engine:** new

## Problem description
Sometimes there is an exception if open project on wsl

## Steps to reproduce

1. Run CLion
2. Open a project on WSL

## Expected Results
the project successfully opened

## Actual Results
Exception occurs

<details>
  <summary>Exception</summary>

```
java.lang.Throwable: AWT events are prohibited inside RefreshCargoProjectsAction#update (org.rust.ide.actions.RefreshCargoProjectsAction); got java.awt.event.InvocationEvent[INVOCATION_DEFAULT,runnable=com.intellij.openapi.application.impl.FlushQueue$$Lambda$286/0x0000000100439c40@596889c9,notifier=null,catchExceptions=false,when=1649168244330] on sun.awt.windows.WToolkit@64c05d6c
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:182)
	at com.intellij.ide.ProhibitAWTEvents.dispatch(ProhibitAWTEvents.java:40)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:460)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:484)
	at com.intellij.ide.IdeEventQueue.pumpEventsForHierarchy(IdeEventQueue.java:943)
	at com.intellij.openapi.progress.util.ProgressWindow.lambda$startBlocking$4(ProgressWindow.java:205)
	at com.intellij.openapi.application.impl.ApplicationImpl.runUnlockingIntendedWrite(ApplicationImpl.java:899)
	at com.intellij.openapi.progress.util.ProgressWindow.startBlocking(ProgressWindow.java:201)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$execFromEDT$6(ProgressRunner.java:321)
	at java.base/java.util.concurrent.CompletableFuture.uniAcceptNow(CompletableFuture.java:753)
	at java.base/java.util.concurrent.CompletableFuture.uniAcceptStage(CompletableFuture.java:731)
	at java.base/java.util.concurrent.CompletableFuture.thenAccept(CompletableFuture.java:2108)
	at com.intellij.openapi.progress.impl.ProgressRunner.execFromEDT(ProgressRunner.java:318)
	at com.intellij.openapi.progress.impl.ProgressRunner.submit(ProgressRunner.java:259)
	at com.intellij.openapi.progress.impl.ProgressRunner.submitAndGet(ProgressRunner.java:185)
	at com.intellij.openapi.application.impl.ApplicationImpl.runProcessWithProgressSynchronously(ApplicationImpl.java:477)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcessWithProgressSynchronously(CoreProgressManager.java:537)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcessWithProgressSynchronously(ProgressManagerImpl.java:85)
	at com.intellij.openapi.progress.impl.CoreProgressManager.run(CoreProgressManager.java:385)
	at com.intellij.openapi.progress.ProgressManager.run(ProgressManager.java:191)
	at com.intellij.execution.wsl.WslDistributionDescriptor.executeOrRunTask(WslDistributionDescriptor.java:198)
	at com.intellij.execution.wsl.WslDistributionDescriptor.lambda$new$1(WslDistributionDescriptor.java:50)
	at com.intellij.execution.wsl.WslDistributionDescriptor$2.compute(WslDistributionDescriptor.java:212)
	at com.intellij.openapi.util.ClearableLazyValue.getValue(ClearableLazyValue.java:39)
	at com.intellij.execution.wsl.WslDistributionDescriptor$2.getValue(WslDistributionDescriptor.java:222)
	at com.intellij.execution.wsl.WslDistributionDescriptor.getMntRoot(WslDistributionDescriptor.java:128)
	at com.intellij.execution.wsl.WSLDistribution.getMntRoot(WSLDistribution.java:527)
	at org.rust.cargo.toolchain.wsl.RsWslToolchain$Companion.getWindowsPathWithFix(RsWslToolchain.kt:82)
	at org.rust.cargo.toolchain.wsl.RsWslToolchain$Companion.access$getWindowsPathWithFix(RsWslToolchain.kt:76)
	at org.rust.cargo.toolchain.wsl.RsWslToolchain.<init>(RsWslToolchain.kt:23)
	at org.rust.cargo.toolchain.wsl.RsWslToolchainProvider.getToolchain(RsWslToolchainProvider.kt:19)
	at org.rust.cargo.toolchain.RsToolchainProvider$Companion$getToolchain$1.invoke(RsToolchainProvider.kt:20)
	at org.rust.cargo.toolchain.RsToolchainProvider$Companion$getToolchain$1.invoke(RsToolchainProvider.kt:20)
	at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:210)
	at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:170)
	at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:194)
	at kotlin.sequences.SequencesKt___SequencesKt.firstOrNull(_Sequences.kt:167)
	at org.rust.cargo.toolchain.RsToolchainProvider$Companion.getToolchain(RsToolchainProvider.kt:21)
	at org.rust.cargo.project.settings.RustProjectSettingsService$State.getToolchain(RustProjectSettingsService.kt:58)
	at org.rust.cargo.project.settings.impl.RustProjectSettingsServiceImpl.getToolchain(RustProjectSettingsServiceImpl.kt:53)
	at org.rust.cargo.project.settings.RustProjectSettingsServiceKt.getToolchain(RustProjectSettingsService.kt:166)
	at org.rust.ide.actions.RefreshCargoProjectsAction.update(RefreshCargoProjectsAction.kt:21)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.lambda$performDumbAwareUpdate$0(ActionUtil.java:131)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareUpdate(ActionUtil.java:145)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.doUpdate(ActionUpdater.java:639)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$updateActionReal$4(ActionUpdater.java:125)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$computeOnEdt$6(ActionUpdater.java:209)
	at com.intellij.openapi.progress.ProgressManager.lambda$runProcess$0(ProgressManager.java:58)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:189)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:608)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:683)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:639)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:607)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:176)
	at com.intellij.openapi.progress.ProgressManager.runProcess(ProgressManager.java:58)
	at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$computeOnEdt$7(ActionUpdater.java:207)
	at com.intellij.openapi.actionSystem.impl.ActionUpdateEdtExecutor.lambda$computeOnEdt$0(ActionUpdateEdtExecutor.java:45)
	at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:200)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
	at com.intellij.openapi.application.impl.ApplicationImpl$3.run(ApplicationImpl.java:511)
	at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:69)
	at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:112)
	at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:42)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:898)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:746)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:439)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:803)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:438)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:106)
	at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:604)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:436)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:484)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
```

</details>

Changed files:
src/main/kotlin/org/rust/ide/actions/CargoEditSettingsAction.kt
src/main/kotlin/org/rust/ide/actions/macroExpansion/RsShowMacroExpansionGroup.kt
src/main/kotlin/org/rust/ide/actions/macroExpansion/RsShowMacroExpansionActions.kt
src/main/kotlin/org/rust/ide/actions/RustfmtFileAction.kt
src/main/kotlin/org/rust/cargo/runconfig/command/RunCargoCommandActionBase.kt
src/main/kotlin/org/rust/cargo/project/model/CargoProjectActionBase.kt
src/test/kotlin/org/rust/cargo/commands/RustfmtTest.kt
src/main/kotlin/org/rust/ide/spelling/RsSpellCheckerGenerateDictionariesAction.kt
src/main/kotlin/org/rust/ide/actions/RsBuildAction.kt
src/main/kotlin/org/rust/ide/actions/RustfmtCargoProjectAction.kt
src/main/kotlin/org/rust/ide/actions/ToggleExternalLinterOnTheFlyAction.kt
src/main/kotlin/org/rust/ide/console/RunRustConsoleAction.kt
src/main/kotlin/org/rust/ide/actions/ShareInPlaygroundAction.kt
src/main/kotlin/org/rust/ide/actions/RsToolsActionGroup.kt
src/main/kotlin/org/rust/ide/actions/diagnostic/CreateNewGithubIssue.kt

diff --git a/src/main/kotlin/org/rust/cargo/project/model/CargoProjectActionBase.kt b/src/main/kotlin/org/rust/cargo/project/model/CargoProjectActionBase.kt
index 2548461ea..a4a36b209 100644
--- a/src/main/kotlin/org/rust/cargo/project/model/CargoProjectActionBase.kt
+++ b/src/main/kotlin/org/rust/cargo/project/model/CargoProjectActionBase.kt
@@ -5,6 +5,9 @@
 
 package org.rust.cargo.project.model
 
+import com.intellij.openapi.actionSystem.ActionUpdateThread
 import com.intellij.openapi.project.DumbAwareAction
 
-abstract class CargoProjectActionBase : DumbAwareAction()
+abstract class CargoProjectActionBase : DumbAwareAction() {
+    override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
+}
diff --git a/src/main/kotlin/org/rust/cargo/runconfig/command/RunCargoCommandActionBase.kt b/src/main/kotlin/org/rust/cargo/runconfig/command/RunCargoCommandActionBase.kt
index 8564dc30e..7be9b107d 100644
--- a/src/main/kotlin/org/rust/cargo/runconfig/command/RunCargoCommandActionBase.kt
+++ b/src/main/kotlin/org/rust/cargo/runconfig/command/RunCargoCommandActionBase.kt
@@ -5,11 +5,13 @@
 
 package org.rust.cargo.runconfig.command
 
+import com.intellij.openapi.actionSystem.ActionUpdateThread
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.project.DumbAwareAction
 import org.rust.cargo.runconfig.hasCargoProject
 
 abstract class RunCargoCommandActionBase : DumbAwareAction() {
+    override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
     override fun update(e: AnActionEvent) {
         val hasCargoProject = e.project?.hasCargoProject == true
         e.presentation.isEnabledAndVisible = hasCargoProject
diff --git a/src/main/kotlin/org/rust/ide/actions/CargoEditSettingsAction.kt b/src/main/kotlin/org/rust/ide/actions/CargoEditSettingsAction.kt
index 35a066811..97e236217 100644
--- a/src/main/kotlin/org/rust/ide/actions/CargoEditSettingsAction.kt
+++ b/src/main/kotlin/org/rust/ide/actions/CargoEditSettingsAction.kt
@@ -5,6 +5,7 @@
 
 package org.rust.ide.actions
 
+import com.intellij.openapi.actionSystem.ActionUpdateThread
 import com.intellij.openapi.actionSystem.AnAction
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.project.DumbAware
@@ -13,6 +14,8 @@ import org.rust.openapiext.showSettingsDialog
 
 class CargoEditSettingsAction : AnAction(), DumbAware {
 
+    override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
+
     override fun update(e: AnActionEvent) {
         super.update(e)
         e.presentation.isEnabledAndVisible = e.project != null
diff --git a/src/main/kotlin/org/rust/ide/actions/RsBuildAction.kt b/src/main/kotlin/org/rust/ide/actions/RsBuildAction.kt
index 66f44c203..5120067ce 100644
--- a/src/main/kotlin/org/rust/ide/actions/RsBuildAction.kt
+++ b/src/main/kotlin/org/rust/ide/actions/RsBuildAction.kt
@@ -6,6 +6,7 @@
 package org.rust.ide.actions
 
 import com.google.common.annotations.VisibleForTesting
+import com.intellij.openapi.actionSystem.ActionUpdateThread
 import com.intellij.openapi.actionSystem.AnAction
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.actionSystem.DataContext
@@ -32,6 +33,8 @@ class RsBuildAction : AnAction() {
         }
     }
 
+    override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
+
     override fun update(e: AnActionEvent) {
         super.update(e)
         e.presentation.isEnabledAndVisible = isSuitablePlatform() && e.project?.hasCargoProject == true
diff --git a/src/main/kotlin/org/rust/ide/actions/RsToolsActionGroup.kt b/src/main/kotlin/org/rust/ide/actions/RsToolsActionGroup.kt
index 22b65e195..e460ce76e 100644
--- a/src/main/kotlin/org/rust/ide/actions/RsToolsActionGroup.kt
+++ b/src/main/kotlin/org/rust/ide/actions/RsToolsActionGroup.kt
@@ -5,6 +5,7 @@
 
 package org.rust.ide.actions
 
+import com.intellij.openapi.actionSystem.ActionUpdateThread
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.actionSystem.DefaultActionGroup
 import com.intellij.openapi.project.DumbAware
@@ -12,6 +13,8 @@ import org.rust.cargo.runconfig.hasCargoProject
 
 class RsToolsActionGroup : DefaultActionGroup(), DumbAware {
 
+    override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
+
     override fun update(e: AnActionEvent) {
         val project = e.project ?: return
         e.presentation.isEnabledAndVisible = project.hasCargoProject
diff --git a/src/main/kotlin/org/rust/ide/actions/RustfmtCargoProjectAction.kt b/src/main/kotlin/org/rust/ide/actions/RustfmtCargoProjectAction.kt
index faa9159ca..fabd66348 100644
--- a/src/main/kotlin/org/rust/ide/actions/RustfmtCargoProjectAction.kt
+++ b/src/main/kotlin/org/rust/ide/actions/RustfmtCargoProjectAction.kt
@@ -5,6 +5,7 @@
 
 package org.rust.ide.actions
 
+import com.intellij.openapi.actionSystem.ActionUpdateThread
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.project.DumbAwareAction
 import com.intellij.openapi.vfs.VfsUtil
@@ -21,6 +22,8 @@ import org.rust.stdext.unwrapOrElse
 
 class RustfmtCargoProjectAction : DumbAwareAction() {
 
+    override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
+
     override fun update(e: AnActionEvent) {
         super.update(e)
         e.presentation.isEnabled = getContext(e) != null
diff --git a/src/main/kotlin/org/rust/ide/actions/RustfmtFileAction.kt b/src/main/kotlin/org/rust/ide/actions/RustfmtFileAction.kt
index 1f4b60b3d..615f85d46 100644
--- a/src/main/kotlin/org/rust/ide/actions/RustfmtFileAction.kt
+++ b/src/main/kotlin/org/rust/ide/actions/RustfmtFileAction.kt
@@ -6,13 +6,11 @@
 package org.rust.ide.actions
 
 import com.intellij.execution.ExecutionException
+import com.intellij.openapi.actionSystem.ActionUpdateThread
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.actionSystem.CommonDataKeys
 import com.intellij.openapi.editor.Document
-import com.intellij.openapi.editor.Editor
-import com.intellij.openapi.fileEditor.FileEditorManager
 import com.intellij.openapi.project.DumbAwareAction
-import com.intellij.openapi.project.Project
 import org.rust.RsBundle
 import org.rust.cargo.project.model.CargoProject
 import org.rust.cargo.project.model.cargoProjects
@@ -26,6 +24,8 @@ import org.rust.openapiext.*
 
 class RustfmtFileAction : DumbAwareAction() {
 
+    override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
+
     override fun update(e: AnActionEvent) {
         super.update(e)
         e.presentation.isEnabled = getContext(e) != null
@@ -63,14 +63,11 @@ class RustfmtFileAction : DumbAwareAction() {
     private fun getContext(e: AnActionEvent): Triple<CargoProject, Rustfmt, Document>? {
         val project = e.project ?: return null
         val rustfmt = project.toolchain?.rustfmt() ?: return null
-        val editor = e.getData(CommonDataKeys.EDITOR_EVEN_IF_INACTIVE) ?: getSelectedEditor(project) ?: return null
+        val editor = e.getData(CommonDataKeys.EDITOR) ?: return null
         val document = editor.document
         val file = document.virtualFile ?: return null
         if (!(file.isInLocalFileSystem && file.isRustFile)) return null
         val cargoProject = project.cargoProjects.findProjectForFile(file) ?: return null
         return Triple(cargoProject, rustfmt, document)
     }
-
-    private fun getSelectedEditor(project: Project): Editor? =
-        FileEditorManager.getInstance(project).selectedTextEditor
 }
diff --git a/src/main/kotlin/org/rust/ide/actions/ShareInPlaygroundAction.kt b/src/main/kotlin/org/rust/ide/actions/ShareInPlaygroundAction.kt
index ff012e76f..f1b0d7bc9 100644
--- a/src/main/kotlin/org/rust/ide/actions/ShareInPlaygroundAction.kt
+++ b/src/main/kotlin/org/rust/ide/actions/ShareInPlaygroundAction.kt
@@ -12,6 +12,7 @@ import com.intellij.ide.util.PropertiesComponent
 import com.intellij.notification.NotificationAction
 import com.intellij.notification.NotificationListener
 import com.intellij.notification.NotificationType
+import com.intellij.openapi.actionSystem.ActionUpdateThread
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.actionSystem.CommonDataKeys
 import com.intellij.openapi.application.runReadAction
@@ -42,6 +43,8 @@ import java.time.Duration
 
 class ShareInPlaygroundAction : DumbAwareAction() {
 
+    override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
+
     override fun update(e: AnActionEvent) {
         val file = e.getData(CommonDataKeys.PSI_FILE) as? RsFile
         e.presentation.isEnabledAndVisible = file != null
diff --git a/src/main/kotlin/org/rust/ide/actions/ToggleExternalLinterOnTheFlyAction.kt b/src/main/kotlin/org/rust/ide/actions/ToggleExternalLinterOnTheFlyAction.kt
index df922c02a..ea9ace357 100644
--- a/src/main/kotlin/org/rust/ide/actions/ToggleExternalLinterOnTheFlyAction.kt
+++ b/src/main/kotlin/org/rust/ide/actions/ToggleExternalLinterOnTheFlyAction.kt
@@ -5,6 +5,7 @@
 
 package org.rust.ide.actions
 
+import com.intellij.openapi.actionSystem.ActionUpdateThread
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.actionSystem.ToggleAction
 import org.rust.cargo.project.settings.rustSettings
@@ -21,6 +22,8 @@ class ToggleExternalLinterOnTheFlyAction : ToggleAction() {
         project.rustSettings.modify { it.runExternalLinterOnTheFly = state }
     }
 
+    override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
+
     override fun update(e: AnActionEvent) {
         super.update(e)
         val externalLinterName = e.project?.rustSettings?.externalLinter?.title ?: "External Linter"
diff --git a/src/main/kotlin/org/rust/ide/actions/diagnostic/CreateNewGithubIssue.kt b/src/main/kotlin/org/rust/ide/actions/diagnostic/CreateNewGithubIssue.kt
index 38918339b..94d6ca5ab 100644
--- a/src/main/kotlin/org/rust/ide/actions/diagnostic/CreateNewGithubIssue.kt
+++ b/src/main/kotlin/org/rust/ide/actions/diagnostic/CreateNewGithubIssue.kt
@@ -6,6 +6,7 @@
 package org.rust.ide.actions.diagnostic
 
 import com.intellij.ide.BrowserUtil
+import com.intellij.openapi.actionSystem.ActionUpdateThread
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.actionSystem.PlatformDataKeys
 import com.intellij.openapi.application.ApplicationInfo
@@ -30,6 +31,8 @@ import kotlin.reflect.full.memberProperties
 
 class CreateNewGithubIssue : DumbAwareAction() {
 
+    override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
+
     override fun update(e: AnActionEvent) {
         e.presentation.isEnabledAndVisible = e.project?.hasCargoProject == true
     }
diff --git a/src/main/kotlin/org/rust/ide/actions/macroExpansion/RsShowMacroExpansionActions.kt b/src/main/kotlin/org/rust/ide/actions/macroExpansion/RsShowMacroExpansionActions.kt
index 6feff8505..ce90e2585 100644
--- a/src/main/kotlin/org/rust/ide/actions/macroExpansion/RsShowMacroExpansionActions.kt
+++ b/src/main/kotlin/org/rust/ide/actions/macroExpansion/RsShowMacroExpansionActions.kt
@@ -7,6 +7,7 @@ package org.rust.ide.actions.macroExpansion
 
 import com.google.common.annotations.VisibleForTesting
 import com.intellij.codeInsight.hint.HintManager
+import com.intellij.openapi.actionSystem.ActionUpdateThread
 import com.intellij.openapi.actionSystem.AnAction
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.actionSystem.DataContext
@@ -24,6 +25,8 @@ import org.rust.stdext.RsResult.Ok
 
 abstract class RsShowMacroExpansionActionBase(private val expandRecursively: Boolean) : AnAction() {
 
+    override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
+
     override fun update(e: AnActionEvent) {
         e.presentation.isEnabledAndVisible = getMacroUnderCaret(e.dataContext) != null
     }
diff --git a/src/main/kotlin/org/rust/ide/actions/macroExpansion/RsShowMacroExpansionGroup.kt b/src/main/kotlin/org/rust/ide/actions/macroExpansion/RsShowMacroExpansionGroup.kt
index 3e775a6c8..e913f98b8 100644
--- a/src/main/kotlin/org/rust/ide/actions/macroExpansion/RsShowMacroExpansionGroup.kt
+++ b/src/main/kotlin/org/rust/ide/actions/macroExpansion/RsShowMacroExpansionGroup.kt
@@ -6,6 +6,7 @@
 package org.rust.ide.actions.macroExpansion
 
 import com.intellij.openapi.actionSystem.ActionPlaces
+import com.intellij.openapi.actionSystem.ActionUpdateThread
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.actionSystem.DefaultActionGroup
 import org.rust.lang.core.psi.RsMacroCall
@@ -16,6 +17,9 @@ import org.rust.lang.core.psi.RsMacroCall
  * It is required to show those actions only on certain elements (like [RsMacroCall]s).
  */
 class RsShowMacroExpansionGroup : DefaultActionGroup() {
+
+    override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
+
     override fun update(event: AnActionEvent) {
         val inEditorPopupMenu = event.place == ActionPlaces.EDITOR_POPUP
         event.presentation.isEnabledAndVisible = inEditorPopupMenu && getMacroUnderCaret(event.dataContext) != null
diff --git a/src/main/kotlin/org/rust/ide/console/RunRustConsoleAction.kt b/src/main/kotlin/org/rust/ide/console/RunRustConsoleAction.kt
index 8db966331..e94f8dc50 100644
--- a/src/main/kotlin/org/rust/ide/console/RunRustConsoleAction.kt
+++ b/src/main/kotlin/org/rust/ide/console/RunRustConsoleAction.kt
@@ -6,6 +6,7 @@
 package org.rust.ide.console
 
 import com.intellij.notification.NotificationType
+import com.intellij.openapi.actionSystem.ActionUpdateThread
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.application.TransactionGuard
 import com.intellij.openapi.project.DumbAwareAction
@@ -13,6 +14,9 @@ import org.rust.cargo.runconfig.hasCargoProject
 import org.rust.ide.notifications.showBalloonWithoutProject
 
 class RunRustConsoleAction : DumbAwareAction() {
+
+    override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
+
     override fun update(e: AnActionEvent) {
         e.presentation.isEnabled = e.project?.hasCargoProject == true
     }
diff --git a/src/main/kotlin/org/rust/ide/spelling/RsSpellCheckerGenerateDictionariesAction.kt b/src/main/kotlin/org/rust/ide/spelling/RsSpellCheckerGenerateDictionariesAction.kt
index 7c59d29f6..8da3ec2cf 100644
--- a/src/main/kotlin/org/rust/ide/spelling/RsSpellCheckerGenerateDictionariesAction.kt
+++ b/src/main/kotlin/org/rust/ide/spelling/RsSpellCheckerGenerateDictionariesAction.kt
@@ -5,6 +5,7 @@
 
 package org.rust.ide.spelling
 
+import com.intellij.openapi.actionSystem.ActionUpdateThread
 import com.intellij.openapi.actionSystem.AnAction
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.actionSystem.LangDataKeys
@@ -33,6 +34,8 @@ class RsSpellCheckerGenerateDictionariesAction : AnAction() {
         generator.generate()
     }
 
+    override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
+
     override fun update(e: AnActionEvent) {
         e.presentation.isEnabledAndVisible = e.project?.cargoProjects?.hasAtLeastOneValidProject == true
     }
diff --git a/src/test/kotlin/org/rust/cargo/commands/RustfmtTest.kt b/src/test/kotlin/org/rust/cargo/commands/RustfmtTest.kt
index e1cc6997c..808ad46d3 100644
--- a/src/test/kotlin/org/rust/cargo/commands/RustfmtTest.kt
+++ b/src/test/kotlin/org/rust/cargo/commands/RustfmtTest.kt
@@ -6,9 +6,7 @@
 package org.rust.cargo.commands
 
 import com.intellij.codeInsight.actions.ReformatCodeProcessor
-import com.intellij.openapi.actionSystem.CommonDataKeys
 import com.intellij.openapi.command.WriteCommandAction
-import com.intellij.openapi.editor.Editor
 import com.intellij.openapi.util.TextRange
 import com.intellij.psi.PsiFile
 import com.intellij.psi.codeStyle.CodeStyleManager
@@ -99,7 +97,7 @@ class RustfmtTest : RsWithToolchainTestBase() {
         fn main() {
             println!("Hello, ΣΠ∫!");
         }
-    """) { reformatFile(myFixture.editor) }
+    """) { reformatFile() }
 
     fun `test rustfmt file action ignores emit option 1`() = doTest({
         toml("Cargo.toml", """
@@ -124,7 +122,7 @@ class RustfmtTest : RsWithToolchainTestBase() {
         project.rustfmtSettings.modifyTemporary(testRootDisposable) {
             it.additionalArguments = "--emit files"
         }
-        reformatFile(myFixture.editor)
+        reformatFile()
     }
 
     fun `test rustfmt file action ignores emit option 2`() = doTest({
@@ -150,7 +148,7 @@ class RustfmtTest : RsWithToolchainTestBase() {
         project.rustfmtSettings.modifyTemporary(testRootDisposable) {
             it.additionalArguments = "--emit=files"
         }
-        reformatFile(myFixture.editor)
+        reformatFile()
     }
 
     fun `test rustfmt file action with edited configuration 1`() = doTest({
@@ -177,7 +175,7 @@ class RustfmtTest : RsWithToolchainTestBase() {
             it.additionalArguments = "--unstable-features"
             it.channel = RustChannel.NIGHTLY
         }
-        reformatFile(myFixture.editor)
+        reformatFile()
     }
 
     fun `test rustfmt file action with edited configuration 2`() = doTest({
@@ -205,7 +203,7 @@ class RustfmtTest : RsWithToolchainTestBase() {
             it.channel = RustChannel.STABLE
         }
         assertThrows(RsProcessExecutionException::class.java) {
-            reformatFile(myFixture.editor)
+            reformatFile()
         }
     }
 
@@ -232,7 +230,7 @@ class RustfmtTest : RsWithToolchainTestBase() {
         project.rustfmtSettings.modifyTemporary(testRootDisposable) {
             it.additionalArguments = "+nightly --unstable-features"
         }
-        reformatFile(myFixture.editor)
+        reformatFile()
     }
 
     fun `test rustfmt file action edition 2018`() = doTest({
@@ -255,7 +253,7 @@ class RustfmtTest : RsWithToolchainTestBase() {
         async fn foo() {
             println!("Hello, ΣΠ∫!");
         }
-    """) { reformatFile(myFixture.editor) }
+    """) { reformatFile() }
 
     fun `test rustfmt cargo project action`() = doTest({
         toml("Cargo.toml", """
@@ -531,8 +529,8 @@ class RustfmtTest : RsWithToolchainTestBase() {
         }
     }
 
-    private fun reformatFile(editor: Editor) {
-        myFixture.launchAction("Cargo.RustfmtFile", CommonDataKeys.EDITOR_EVEN_IF_INACTIVE to editor)
+    private fun reformatFile() {
+        myFixture.launchAction("Cargo.RustfmtFile")
     }
 
     private fun reformatCargoProject() {