Repository: intellij-rust/intellij-rust
Issue: Build button does nothing in PyCharm

<!--
Hello and thank you for the issue!
If you would like to report a bug, we have added some points below that you can fill out.
Consider using "Help | Create New Issue" action that fills out all necessary information automatically.
Feel free to remove all the irrelevant text to request a new feature.
-->

## Environment

* **IntelliJ Rust plugin version:** 0.4.168.4555-213
* **Rust toolchain version:**  1.58.1 stable-x86_64-pc-windows-msvc
* **IDE name and version:** PyCharm 2021.3.3 (Professional Edition) (PY-213.7172.26)
* **Operating system:** Windows 10 Pro 21H2 19044.1586

## Problem description

Hammer button does nothing, but working directory for play button already setup

https://user-images.githubusercontent.com/50753350/163594808-dfd5fca8-1237-4ce1-8513-e2a26bf69fd1.mp4




## Steps to reproduce

<!--
Please include as much of your codebase as needed to reproduce the error.
If the relevant files are large, please provide a link to a public repository or a [Gist](https://gist.github.com/).

If you provide a screenshot of some code, please also copy-paste the corresponding code snippet here.
-->

Create cargo project in sub directory of PyCharm project and set cargo project as working directory

Changed files:
src/main/kotlin/org/rust/cargo/runconfig/buildtool/CargoBuildTaskRunner.kt

diff --git a/src/main/kotlin/org/rust/cargo/runconfig/buildtool/CargoBuildTaskRunner.kt b/src/main/kotlin/org/rust/cargo/runconfig/buildtool/CargoBuildTaskRunner.kt
index 91038a5e3..4970332f2 100644
--- a/src/main/kotlin/org/rust/cargo/runconfig/buildtool/CargoBuildTaskRunner.kt
+++ b/src/main/kotlin/org/rust/cargo/runconfig/buildtool/CargoBuildTaskRunner.kt
@@ -25,7 +25,6 @@ import com.intellij.openapi.progress.Task
 import com.intellij.openapi.project.Project
 import com.intellij.task.*
 import com.intellij.task.impl.ProjectModelBuildTaskImpl
-import com.intellij.util.PlatformUtils
 import org.jetbrains.concurrency.*
 import org.rust.RsBundle
 import org.rust.cargo.project.model.cargoProjects
@@ -34,6 +33,7 @@ import org.rust.cargo.runconfig.CargoCommandRunner
 import org.rust.cargo.runconfig.buildProject
 import org.rust.cargo.runconfig.buildtool.CargoBuildManager.createBuildEnvironment
 import org.rust.cargo.runconfig.buildtool.CargoBuildManager.getBuildConfiguration
+import org.rust.cargo.runconfig.buildtool.CargoBuildManager.isBuildToolWindowAvailable
 import org.rust.cargo.runconfig.command.CargoCommandConfiguration
 import org.rust.cargo.runconfig.command.CargoCommandConfiguration.Companion.findCargoProject
 import org.rust.cargo.runconfig.createCargoCommandRunConfiguration
@@ -94,17 +94,22 @@ class CargoBuildTaskRunner : ProjectTaskRunner() {
         return resultPromise
     }
 
-    override fun canRun(projectTask: ProjectTask): Boolean =
-        when (projectTask) {
+    override fun canRun(projectTask: ProjectTask): Boolean {
+        return when (projectTask) {
             is ModuleFilesBuildTask -> false
-            is ModuleBuildTask ->
-                projectTask.module.cargoProjectRoot != null
+            is ModuleBuildTask -> {
+                if (projectTask.module.cargoProjectRoot != null) return true
+                val runManager = RunManager.getInstance(projectTask.module.project)
+                val buildableElement = runManager.selectedConfiguration?.configuration
+                buildableElement is CargoCommandConfiguration && buildableElement.isBuildToolWindowAvailable
+            }
             is ProjectModelBuildTask<*> -> {
                 val buildableElement = projectTask.buildableElement
                 buildableElement is CargoBuildConfiguration && buildableElement.enabled
             }
             else -> false
         }
+    }
 
     fun expandTask(task: ProjectTask): List<ProjectTask> {
         if (task !is ModuleBuildTask) return listOf(task)