diff options
author | Aleksey Kladov <[email protected]> | 2020-04-01 11:03:06 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-04-01 11:34:12 +0100 |
commit | 65c89c3a200833099714e2943ead14184ae9c0df (patch) | |
tree | a60a9020823fac1fe9ad490d245cb9b9455f397c | |
parent | b5306ea70659aad28b1a5de248128b47a5e5f1bf (diff) |
Cleanup
-rw-r--r-- | crates/ra_flycheck/src/lib.rs | 64 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/src/world.rs | 4 |
3 files changed, 35 insertions, 39 deletions
diff --git a/crates/ra_flycheck/src/lib.rs b/crates/ra_flycheck/src/lib.rs index 75aece45f..ee09d8de3 100644 --- a/crates/ra_flycheck/src/lib.rs +++ b/crates/ra_flycheck/src/lib.rs | |||
@@ -4,9 +4,9 @@ | |||
4 | mod conv; | 4 | mod conv; |
5 | 5 | ||
6 | use std::{ | 6 | use std::{ |
7 | error, fmt, | 7 | env, error, fmt, |
8 | io::{BufRead, BufReader}, | 8 | io::{BufRead, BufReader}, |
9 | path::{Path, PathBuf}, | 9 | path::PathBuf, |
10 | process::{Command, Stdio}, | 10 | process::{Command, Stdio}, |
11 | time::Instant, | 11 | time::Instant, |
12 | }; | 12 | }; |
@@ -23,10 +23,10 @@ use crate::conv::{map_rust_diagnostic_to_lsp, MappedRustDiagnostic}; | |||
23 | pub use crate::conv::url_from_path_with_drive_lowercasing; | 23 | pub use crate::conv::url_from_path_with_drive_lowercasing; |
24 | 24 | ||
25 | #[derive(Clone, Debug)] | 25 | #[derive(Clone, Debug)] |
26 | pub struct CheckConfig { | 26 | pub struct FlycheckConfig { |
27 | pub args: Vec<String>, | ||
28 | pub command: String, | 27 | pub command: String, |
29 | pub all_targets: bool, | 28 | pub all_targets: bool, |
29 | pub extra_args: Vec<String>, | ||
30 | } | 30 | } |
31 | 31 | ||
32 | /// Flycheck wraps the shared state and communication machinery used for | 32 | /// Flycheck wraps the shared state and communication machinery used for |
@@ -42,12 +42,11 @@ pub struct Flycheck { | |||
42 | } | 42 | } |
43 | 43 | ||
44 | impl Flycheck { | 44 | impl Flycheck { |
45 | pub fn new(config: CheckConfig, workspace_root: PathBuf) -> Flycheck { | 45 | pub fn new(config: FlycheckConfig, workspace_root: PathBuf) -> Flycheck { |
46 | let (task_send, task_recv) = unbounded::<CheckTask>(); | 46 | let (task_send, task_recv) = unbounded::<CheckTask>(); |
47 | let (cmd_send, cmd_recv) = unbounded::<CheckCommand>(); | 47 | let (cmd_send, cmd_recv) = unbounded::<CheckCommand>(); |
48 | let handle = jod_thread::spawn(move || { | 48 | let handle = jod_thread::spawn(move || { |
49 | let mut check = FlycheckThread::new(config, workspace_root); | 49 | FlycheckThread::new(config, workspace_root).run(&task_send, &cmd_recv); |
50 | check.run(&task_send, &cmd_recv); | ||
51 | }); | 50 | }); |
52 | Flycheck { task_recv, cmd_send, handle } | 51 | Flycheck { task_recv, cmd_send, handle } |
53 | } | 52 | } |
@@ -76,7 +75,7 @@ pub enum CheckCommand { | |||
76 | } | 75 | } |
77 | 76 | ||
78 | struct FlycheckThread { | 77 | struct FlycheckThread { |
79 | options: CheckConfig, | 78 | config: FlycheckConfig, |
80 | workspace_root: PathBuf, | 79 | workspace_root: PathBuf, |
81 | last_update_req: Option<Instant>, | 80 | last_update_req: Option<Instant>, |
82 | // XXX: drop order is significant | 81 | // XXX: drop order is significant |
@@ -90,9 +89,9 @@ struct FlycheckThread { | |||
90 | } | 89 | } |
91 | 90 | ||
92 | impl FlycheckThread { | 91 | impl FlycheckThread { |
93 | fn new(options: CheckConfig, workspace_root: PathBuf) -> FlycheckThread { | 92 | fn new(config: FlycheckConfig, workspace_root: PathBuf) -> FlycheckThread { |
94 | FlycheckThread { | 93 | FlycheckThread { |
95 | options, | 94 | config, |
96 | workspace_root, | 95 | workspace_root, |
97 | last_update_req: None, | 96 | last_update_req: None, |
98 | message_recv: never(), | 97 | message_recv: never(), |
@@ -216,27 +215,27 @@ impl FlycheckThread { | |||
216 | self.message_recv = never(); | 215 | self.message_recv = never(); |
217 | self.check_process = None; | 216 | self.check_process = None; |
218 | 217 | ||
219 | let mut args: Vec<String> = vec![ | 218 | let cmd = { |
220 | self.options.command.clone(), | 219 | let mut cmd = Command::new(cargo_binary()); |
221 | "--workspace".to_string(), | 220 | cmd.arg(&self.config.command); |
222 | "--message-format=json".to_string(), | 221 | cmd.args(&["--workspace", "--message-format=json", "--manifest-path"]); |
223 | "--manifest-path".to_string(), | 222 | cmd.arg(self.workspace_root.join("Cargo.toml")); |
224 | format!("{}/Cargo.toml", self.workspace_root.display()), | 223 | if self.config.all_targets { |
225 | ]; | 224 | cmd.arg("--all-targets"); |
226 | if self.options.all_targets { | 225 | } |
227 | args.push("--all-targets".to_string()); | 226 | cmd.args(self.config.extra_args.iter()); |
228 | } | 227 | cmd.current_dir(&self.workspace_root); |
229 | args.extend(self.options.args.iter().cloned()); | 228 | cmd |
229 | }; | ||
230 | 230 | ||
231 | let (message_send, message_recv) = unbounded(); | 231 | let (message_send, message_recv) = unbounded(); |
232 | let workspace_root = self.workspace_root.to_owned(); | ||
233 | self.message_recv = message_recv; | 232 | self.message_recv = message_recv; |
234 | self.check_process = Some(jod_thread::spawn(move || { | 233 | self.check_process = Some(jod_thread::spawn(move || { |
235 | // If we trigger an error here, we will do so in the loop instead, | 234 | // If we trigger an error here, we will do so in the loop instead, |
236 | // which will break out of the loop, and continue the shutdown | 235 | // which will break out of the loop, and continue the shutdown |
237 | let _ = message_send.send(CheckEvent::Begin); | 236 | let _ = message_send.send(CheckEvent::Begin); |
238 | 237 | ||
239 | let res = run_cargo(&args, Some(&workspace_root), &mut |message| { | 238 | let res = run_cargo(cmd, &mut |message| { |
240 | // Skip certain kinds of messages to only spend time on what's useful | 239 | // Skip certain kinds of messages to only spend time on what's useful |
241 | match &message { | 240 | match &message { |
242 | Message::CompilerArtifact(artifact) if artifact.fresh => return true, | 241 | Message::CompilerArtifact(artifact) if artifact.fresh => return true, |
@@ -285,17 +284,11 @@ impl fmt::Display for CargoError { | |||
285 | impl error::Error for CargoError {} | 284 | impl error::Error for CargoError {} |
286 | 285 | ||
287 | fn run_cargo( | 286 | fn run_cargo( |
288 | args: &[String], | 287 | mut command: Command, |
289 | current_dir: Option<&Path>, | ||
290 | on_message: &mut dyn FnMut(cargo_metadata::Message) -> bool, | 288 | on_message: &mut dyn FnMut(cargo_metadata::Message) -> bool, |
291 | ) -> Result<(), CargoError> { | 289 | ) -> Result<(), CargoError> { |
292 | let mut command = Command::new("cargo"); | 290 | dbg!(&command); |
293 | if let Some(current_dir) = current_dir { | ||
294 | command.current_dir(current_dir); | ||
295 | } | ||
296 | |||
297 | let mut child = command | 291 | let mut child = command |
298 | .args(args) | ||
299 | .stdout(Stdio::piped()) | 292 | .stdout(Stdio::piped()) |
300 | .stderr(Stdio::null()) | 293 | .stderr(Stdio::null()) |
301 | .stdin(Stdio::null()) | 294 | .stdin(Stdio::null()) |
@@ -346,9 +339,8 @@ fn run_cargo( | |||
346 | // FIXME: Read the stderr to display the reason, see `read2()` reference in PR comment: | 339 | // FIXME: Read the stderr to display the reason, see `read2()` reference in PR comment: |
347 | // https://github.com/rust-analyzer/rust-analyzer/pull/3632#discussion_r395605298 | 340 | // https://github.com/rust-analyzer/rust-analyzer/pull/3632#discussion_r395605298 |
348 | format!( | 341 | format!( |
349 | "the command produced no valid metadata (exit code: {:?}): cargo {}", | 342 | "the command produced no valid metadata (exit code: {:?}): {:?}", |
350 | exit_code, | 343 | exit_code, command |
351 | args.join(" ") | ||
352 | ) | 344 | ) |
353 | } | 345 | } |
354 | Err(err) => format!("io error: {:?}", err), | 346 | Err(err) => format!("io error: {:?}", err), |
@@ -357,3 +349,7 @@ fn run_cargo( | |||
357 | 349 | ||
358 | Err(CargoError(err_msg)) | 350 | Err(CargoError(err_msg)) |
359 | } | 351 | } |
352 | |||
353 | fn cargo_binary() -> String { | ||
354 | env::var("CARGO").unwrap_or_else(|_| "cargo".to_string()) | ||
355 | } | ||
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 79dc03de4..06122ed95 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -21,7 +21,7 @@ use lsp_types::{ | |||
21 | WorkDoneProgressBegin, WorkDoneProgressCreateParams, WorkDoneProgressEnd, | 21 | WorkDoneProgressBegin, WorkDoneProgressCreateParams, WorkDoneProgressEnd, |
22 | WorkDoneProgressReport, | 22 | WorkDoneProgressReport, |
23 | }; | 23 | }; |
24 | use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckConfig, CheckTask}; | 24 | use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckTask, FlycheckConfig}; |
25 | use ra_ide::{Canceled, FileId, InlayHintsConfig, LibraryData, SourceRootId}; | 25 | use ra_ide::{Canceled, FileId, InlayHintsConfig, LibraryData, SourceRootId}; |
26 | use ra_prof::profile; | 26 | use ra_prof::profile; |
27 | use ra_vfs::{VfsFile, VfsTask, Watch}; | 27 | use ra_vfs::{VfsFile, VfsTask, Watch}; |
@@ -102,10 +102,10 @@ fn get_config( | |||
102 | max_length: config.inlay_hints_max_length, | 102 | max_length: config.inlay_hints_max_length, |
103 | }, | 103 | }, |
104 | check: if config.cargo_watch_enable { | 104 | check: if config.cargo_watch_enable { |
105 | Some(CheckConfig { | 105 | Some(FlycheckConfig { |
106 | args: config.cargo_watch_args.clone(), | ||
107 | command: config.cargo_watch_command.clone(), | 106 | command: config.cargo_watch_command.clone(), |
108 | all_targets: config.cargo_watch_all_targets, | 107 | all_targets: config.cargo_watch_all_targets, |
108 | extra_args: config.cargo_watch_args.clone(), | ||
109 | }) | 109 | }) |
110 | } else { | 110 | } else { |
111 | None | 111 | None |
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index 7814a682e..2db058eb1 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs | |||
@@ -11,7 +11,7 @@ use std::{ | |||
11 | use crossbeam_channel::{unbounded, Receiver}; | 11 | use crossbeam_channel::{unbounded, Receiver}; |
12 | use lsp_types::Url; | 12 | use lsp_types::Url; |
13 | use parking_lot::RwLock; | 13 | use parking_lot::RwLock; |
14 | use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckConfig, Flycheck}; | 14 | use ra_flycheck::{url_from_path_with_drive_lowercasing, Flycheck, FlycheckConfig}; |
15 | use ra_ide::{ | 15 | use ra_ide::{ |
16 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, InlayHintsConfig, LibraryData, | 16 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, InlayHintsConfig, LibraryData, |
17 | SourceRootId, | 17 | SourceRootId, |
@@ -58,7 +58,7 @@ pub struct Config { | |||
58 | pub line_folding_only: bool, | 58 | pub line_folding_only: bool, |
59 | pub inlay_hints: InlayHintsConfig, | 59 | pub inlay_hints: InlayHintsConfig, |
60 | pub rustfmt_args: Vec<String>, | 60 | pub rustfmt_args: Vec<String>, |
61 | pub check: Option<CheckConfig>, | 61 | pub check: Option<FlycheckConfig>, |
62 | pub vscode_lldb: bool, | 62 | pub vscode_lldb: bool, |
63 | pub proc_macro_srv: Option<String>, | 63 | pub proc_macro_srv: Option<String>, |
64 | } | 64 | } |