Repository: intellij-rust/intellij-rust
Issue: Plugin fails on servo project

<!--
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.
Feel free to remove all the irrelevant text to request a new feature.
-->

## Environment

* **IntelliJ Rust plugin version:** 0.2.116.2155-201
* **Rust toolchain version:** 1.41.0
* **IDE name and version:** CLion 2020.1 EAP
* **Operating system:** Linux 5.4.19-200.fc31.x86_64

## Problem description

When trying to use CLion and the Rust plugin with https://github.com/servo/servo, the plugin tries to run `~/.cargo/bin/cargo check --message-format json` and fails. That's to be expected, as the command should be something like `./mach check --message-format json` because `mach` does some extra things behind the scene.

There should be a way to specify the command the plugin runs in order to get its input. I might have missed it, but I can't find a way to do it.

## Steps to reproduce

Try to load the https://github.com/servo/servo project.
<!--
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/).
-->


Changed files:
src/main/kotlin/org/rust/cargo/toolchain/Cargo.kt, src/test/kotlin/org/rustSlowTests/lang/resolve/CargoGeneratedItemsResolveTest.kt

diff --git a/src/main/kotlin/org/rust/cargo/toolchain/Cargo.kt b/src/main/kotlin/org/rust/cargo/toolchain/Cargo.kt
index d8e66fdbd..572e3c0eb 100644
--- a/src/main/kotlin/org/rust/cargo/toolchain/Cargo.kt
+++ b/src/main/kotlin/org/rust/cargo/toolchain/Cargo.kt
@@ -143,8 +143,14 @@ class Cargo(private val cargoExecutable: Path) {
     ): BuildScriptsInfo? {
         if (!isFeatureEnabled(RsExperiments.EVALUATE_BUILD_SCRIPTS)) return null
         val additionalArgs = listOf("--message-format", "json")
-        val processOutput = CargoCommandLine("check", projectDirectory, additionalArgs)
-            .execute(owner, listener = listener)
+        val commandLine = CargoCommandLine("check", projectDirectory, additionalArgs)
+
+        val processOutput = try {
+            commandLine.execute(owner, listener = listener)
+        } catch (e: ExecutionException) {
+            LOG.warn(e)
+            return null
+        }
 
         // BACKCOMPAT: 2019.3
         @Suppress("DEPRECATION")
diff --git a/src/test/kotlin/org/rustSlowTests/lang/resolve/CargoGeneratedItemsResolveTest.kt b/src/test/kotlin/org/rustSlowTests/lang/resolve/CargoGeneratedItemsResolveTest.kt
index 8698aaf01..ee5fb31b1 100644
--- a/src/test/kotlin/org/rustSlowTests/lang/resolve/CargoGeneratedItemsResolveTest.kt
+++ b/src/test/kotlin/org/rustSlowTests/lang/resolve/CargoGeneratedItemsResolveTest.kt
@@ -744,7 +744,7 @@ class CargoGeneratedItemsResolveTest : RunConfigurationTestBase() {
                         f.write_all(text).unwrap()
                     }
                 """)
-            }
+            }.checkReferenceIsResolved<RsPath>("src/main.rs", toFile = ".../gen/hello.rs")
         }
     }
 
@@ -786,10 +786,35 @@ class CargoGeneratedItemsResolveTest : RunConfigurationTestBase() {
                         ).unwrap();
                     }
                 """)
-            }
+            }.checkReferenceIsResolved<RsPath>("src/main.rs", toFile = ".../hello.rs")
         }
     }
 
+    @MinRustcVersion("1.32.0")
+    fun `test do not fail on compilation error`() = withEnabledEvaluateBuildScriptsFeature {
+        buildProject {
+            toml("Cargo.toml", """
+                [package]
+                name = "intellij-rust-test"
+                version = "0.1.0"
+                authors = []
+            """)
+
+            dir("src") {
+                rust("main.rs", """
+                    pub mod bar;
+                    fn main() {
+                        println!("{}", bar::message());
+                                            //^
+                    }
+                """)
+                rust("bar.rs", """
+                    pub fn message() -> String { } // compilation error
+                """)
+            }
+        }.checkReferenceIsResolved<RsPath>("src/main.rs", toFile = ".../src/bar.rs")
+    }
+
     private fun withEnabledFetchOutDirFeature(action: () -> Unit) =
         runWithEnabledFeature(RsExperiments.FETCH_OUT_DIR, action)