diff options
author | Emil Lauridsen <[email protected]> | 2019-12-25 19:23:44 +0000 |
---|---|---|
committer | Emil Lauridsen <[email protected]> | 2019-12-25 19:26:06 +0000 |
commit | 0cdbd0814958e174c5481d6bf16bd2a7e53ec981 (patch) | |
tree | a58277467e67ebdf8584ad2edf398ca630d6fd35 /crates/ra_lsp_server/src/cargo_check.rs | |
parent | 71d2d81dcc879bbb7898df11ac00578e93b27ab5 (diff) |
Keep VSCode config mostly backwards compatible
Diffstat (limited to 'crates/ra_lsp_server/src/cargo_check.rs')
-rw-r--r-- | crates/ra_lsp_server/src/cargo_check.rs | 52 |
1 files changed, 15 insertions, 37 deletions
diff --git a/crates/ra_lsp_server/src/cargo_check.rs b/crates/ra_lsp_server/src/cargo_check.rs index fa0409ee0..70c723b19 100644 --- a/crates/ra_lsp_server/src/cargo_check.rs +++ b/crates/ra_lsp_server/src/cargo_check.rs | |||
@@ -39,22 +39,14 @@ pub struct CheckWatcher { | |||
39 | 39 | ||
40 | impl CheckWatcher { | 40 | impl CheckWatcher { |
41 | pub fn new(options: &Options, workspace_root: PathBuf) -> CheckWatcher { | 41 | pub fn new(options: &Options, workspace_root: PathBuf) -> CheckWatcher { |
42 | let check_enabled = options.cargo_check_enable; | 42 | let options = options.clone(); |
43 | let check_command = options.cargo_check_command.clone(); | ||
44 | let check_args = options.cargo_check_args.clone(); | ||
45 | let shared = Arc::new(RwLock::new(CheckWatcherSharedState::new())); | 43 | let shared = Arc::new(RwLock::new(CheckWatcherSharedState::new())); |
46 | 44 | ||
47 | let (task_send, task_recv) = unbounded::<CheckTask>(); | 45 | let (task_send, task_recv) = unbounded::<CheckTask>(); |
48 | let (cmd_send, cmd_recv) = unbounded::<CheckCommand>(); | 46 | let (cmd_send, cmd_recv) = unbounded::<CheckCommand>(); |
49 | let shared_ = shared.clone(); | 47 | let shared_ = shared.clone(); |
50 | let handle = std::thread::spawn(move || { | 48 | let handle = std::thread::spawn(move || { |
51 | let mut check = CheckWatcherState::new( | 49 | let mut check = CheckWatcherState::new(options, workspace_root, shared_); |
52 | check_enabled, | ||
53 | check_command, | ||
54 | check_args, | ||
55 | workspace_root, | ||
56 | shared_, | ||
57 | ); | ||
58 | check.run(&task_send, &cmd_recv); | 50 | check.run(&task_send, &cmd_recv); |
59 | }); | 51 | }); |
60 | 52 | ||
@@ -68,9 +60,7 @@ impl CheckWatcher { | |||
68 | } | 60 | } |
69 | 61 | ||
70 | pub struct CheckWatcherState { | 62 | pub struct CheckWatcherState { |
71 | check_enabled: bool, | 63 | options: Options, |
72 | check_command: Option<String>, | ||
73 | check_args: Vec<String>, | ||
74 | workspace_root: PathBuf, | 64 | workspace_root: PathBuf, |
75 | running: bool, | 65 | running: bool, |
76 | watcher: WatchThread, | 66 | watcher: WatchThread, |
@@ -162,18 +152,13 @@ pub enum CheckCommand { | |||
162 | 152 | ||
163 | impl CheckWatcherState { | 153 | impl CheckWatcherState { |
164 | pub fn new( | 154 | pub fn new( |
165 | check_enabled: bool, | 155 | options: Options, |
166 | check_command: Option<String>, | ||
167 | check_args: Vec<String>, | ||
168 | workspace_root: PathBuf, | 156 | workspace_root: PathBuf, |
169 | shared: Arc<RwLock<CheckWatcherSharedState>>, | 157 | shared: Arc<RwLock<CheckWatcherSharedState>>, |
170 | ) -> CheckWatcherState { | 158 | ) -> CheckWatcherState { |
171 | let watcher = | 159 | let watcher = WatchThread::new(&options, &workspace_root); |
172 | WatchThread::new(check_enabled, check_command.as_ref(), &check_args, &workspace_root); | ||
173 | CheckWatcherState { | 160 | CheckWatcherState { |
174 | check_enabled, | 161 | options, |
175 | check_command, | ||
176 | check_args, | ||
177 | workspace_root, | 162 | workspace_root, |
178 | running: false, | 163 | running: false, |
179 | watcher, | 164 | watcher, |
@@ -204,12 +189,7 @@ impl CheckWatcherState { | |||
204 | self.shared.write().clear(task_send); | 189 | self.shared.write().clear(task_send); |
205 | 190 | ||
206 | self.watcher.cancel(); | 191 | self.watcher.cancel(); |
207 | self.watcher = WatchThread::new( | 192 | self.watcher = WatchThread::new(&self.options, &self.workspace_root); |
208 | self.check_enabled, | ||
209 | self.check_command.as_ref(), | ||
210 | &self.check_args, | ||
211 | &self.workspace_root, | ||
212 | ); | ||
213 | } | 193 | } |
214 | } | 194 | } |
215 | } | 195 | } |
@@ -306,25 +286,23 @@ enum CheckEvent { | |||
306 | } | 286 | } |
307 | 287 | ||
308 | impl WatchThread { | 288 | impl WatchThread { |
309 | fn new( | 289 | fn new(options: &Options, workspace_root: &PathBuf) -> WatchThread { |
310 | check_enabled: bool, | ||
311 | check_command: Option<&String>, | ||
312 | check_args: &[String], | ||
313 | workspace_root: &PathBuf, | ||
314 | ) -> WatchThread { | ||
315 | let check_command = check_command.cloned().unwrap_or("check".to_string()); | ||
316 | let mut args: Vec<String> = vec![ | 290 | let mut args: Vec<String> = vec![ |
317 | check_command, | 291 | options.cargo_watch_command.clone(), |
318 | "--message-format=json".to_string(), | 292 | "--message-format=json".to_string(), |
319 | "--manifest-path".to_string(), | 293 | "--manifest-path".to_string(), |
320 | format!("{}/Cargo.toml", workspace_root.to_string_lossy()), | 294 | format!("{}/Cargo.toml", workspace_root.to_string_lossy()), |
321 | ]; | 295 | ]; |
322 | args.extend(check_args.iter().cloned()); | 296 | if options.cargo_watch_all_targets { |
297 | args.push("--all-targets".to_string()); | ||
298 | } | ||
299 | args.extend(options.cargo_watch_args.iter().cloned()); | ||
323 | 300 | ||
324 | let (message_send, message_recv) = unbounded(); | 301 | let (message_send, message_recv) = unbounded(); |
325 | let (cancel_send, cancel_recv) = unbounded(); | 302 | let (cancel_send, cancel_recv) = unbounded(); |
303 | let enabled = options.cargo_watch_enable; | ||
326 | std::thread::spawn(move || { | 304 | std::thread::spawn(move || { |
327 | if !check_enabled { | 305 | if !enabled { |
328 | return; | 306 | return; |
329 | } | 307 | } |
330 | 308 | ||