mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2026-03-27 20:40:59 +00:00
fix: Do not panic if rust-analyzer fails to spawn the discover command
This commit is contained in:
@@ -10,6 +10,7 @@ use std::{
|
||||
process::{ChildStderr, ChildStdout, Command, Stdio},
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
use crossbeam_channel::Sender;
|
||||
use paths::Utf8PathBuf;
|
||||
use process_wrap::std::{StdChildWrapper, StdCommandWrap};
|
||||
@@ -156,7 +157,7 @@ impl<T: Sized + Send + 'static> CommandHandle<T> {
|
||||
parser: impl JsonLinesParser<T>,
|
||||
sender: Sender<T>,
|
||||
out_file: Option<Utf8PathBuf>,
|
||||
) -> std::io::Result<Self> {
|
||||
) -> anyhow::Result<Self> {
|
||||
command.stdout(Stdio::piped()).stderr(Stdio::piped()).stdin(Stdio::null());
|
||||
|
||||
let program = command.get_program().into();
|
||||
@@ -168,7 +169,10 @@ impl<T: Sized + Send + 'static> CommandHandle<T> {
|
||||
child.wrap(process_wrap::std::ProcessSession);
|
||||
#[cfg(windows)]
|
||||
child.wrap(process_wrap::std::JobObject);
|
||||
let mut child = child.spawn().map(JodGroupChild)?;
|
||||
let mut child = child
|
||||
.spawn()
|
||||
.map(JodGroupChild)
|
||||
.with_context(|| "Failed to spawn command: {child:?}")?;
|
||||
|
||||
let stdout = child.0.stdout().take().unwrap();
|
||||
let stderr = child.0.stderr().take().unwrap();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Infrastructure for lazy project discovery. Currently only support rust-project.json discovery
|
||||
//! via a custom discover command.
|
||||
use std::{io, path::Path};
|
||||
use std::path::Path;
|
||||
|
||||
use crossbeam_channel::Sender;
|
||||
use ide_db::FxHashMap;
|
||||
@@ -47,7 +47,7 @@ impl DiscoverCommand {
|
||||
&self,
|
||||
discover_arg: DiscoverArgument,
|
||||
current_dir: &Path,
|
||||
) -> io::Result<DiscoverHandle> {
|
||||
) -> anyhow::Result<DiscoverHandle> {
|
||||
let command = &self.command[0];
|
||||
let args = &self.command[1..];
|
||||
|
||||
|
||||
@@ -825,33 +825,29 @@ impl GlobalState {
|
||||
}
|
||||
Task::DiscoverLinkedProjects(arg) => {
|
||||
if let Some(cfg) = self.config.discover_workspace_config() {
|
||||
// the clone is unfortunately necessary to avoid a borrowck error when
|
||||
// `self.report_progress` is called later
|
||||
let title = &cfg.progress_label.clone();
|
||||
let command = cfg.command.clone();
|
||||
let discover = DiscoverCommand::new(self.discover_sender.clone(), command);
|
||||
|
||||
if self.discover_jobs_active == 0 {
|
||||
self.report_progress(title, Progress::Begin, None, None, None);
|
||||
}
|
||||
self.discover_jobs_active += 1;
|
||||
|
||||
let arg = match arg {
|
||||
DiscoverProjectParam::Buildfile(it) => DiscoverArgument::Buildfile(it),
|
||||
DiscoverProjectParam::Path(it) => DiscoverArgument::Path(it),
|
||||
};
|
||||
|
||||
let handle = discover
|
||||
.spawn(
|
||||
arg,
|
||||
&std::env::current_dir()
|
||||
.expect("Failed to get cwd during project discovery"),
|
||||
)
|
||||
.unwrap_or_else(|e| {
|
||||
panic!("Failed to spawn project discovery command: {e}")
|
||||
});
|
||||
|
||||
self.discover_handles.push(handle);
|
||||
match discover.spawn(arg, self.config.root_path().as_ref()) {
|
||||
Ok(handle) => {
|
||||
if self.discover_jobs_active == 0 {
|
||||
let title = &cfg.progress_label.clone();
|
||||
self.report_progress(title, Progress::Begin, None, None, None);
|
||||
}
|
||||
self.discover_jobs_active += 1;
|
||||
self.discover_handles.push(handle)
|
||||
}
|
||||
Err(e) => self.show_message(
|
||||
lsp_types::MessageType::ERROR,
|
||||
format!("Failed to spawn project discovery command: {e:#}"),
|
||||
false,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
Task::FetchBuildData(progress) => {
|
||||
|
||||
@@ -101,7 +101,7 @@ impl CargoTestHandle {
|
||||
ws_target_dir: Option<&Utf8Path>,
|
||||
test_target: TestTarget,
|
||||
sender: Sender<CargoTestMessage>,
|
||||
) -> std::io::Result<Self> {
|
||||
) -> anyhow::Result<Self> {
|
||||
let mut cmd = toolchain::command(Tool::Cargo.path(), root, &options.extra_env);
|
||||
cmd.env("RUSTC_BOOTSTRAP", "1");
|
||||
cmd.arg("--color=always");
|
||||
|
||||
Reference in New Issue
Block a user