Skip to content

Commit 8cce752

Browse files
bors[bot]matklad
andauthored
Merge #3802
3802: Crisper name r=matklad a=matklad https://www.flycheck.org/en/latest/ bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents fae6cec + b5306ea commit 8cce752

File tree

3 files changed

+34
-33
lines changed

3 files changed

+34
-33
lines changed

crates/ra_flycheck/src/lib.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,32 @@ pub use crate::conv::url_from_path_with_drive_lowercasing;
2424

2525
#[derive(Clone, Debug)]
2626
pub struct CheckConfig {
27-
pub enable: bool,
2827
pub args: Vec<String>,
2928
pub command: String,
3029
pub all_targets: bool,
3130
}
3231

33-
/// CheckWatcher wraps the shared state and communication machinery used for
32+
/// Flycheck wraps the shared state and communication machinery used for
3433
/// running `cargo check` (or other compatible command) and providing
3534
/// diagnostics based on the output.
3635
/// The spawned thread is shut down when this struct is dropped.
3736
#[derive(Debug)]
38-
pub struct CheckWatcher {
37+
pub struct Flycheck {
3938
// XXX: drop order is significant
4039
cmd_send: Sender<CheckCommand>,
41-
handle: Option<jod_thread::JoinHandle<()>>,
40+
handle: jod_thread::JoinHandle<()>,
4241
pub task_recv: Receiver<CheckTask>,
4342
}
4443

45-
impl CheckWatcher {
46-
pub fn new(config: CheckConfig, workspace_root: PathBuf) -> CheckWatcher {
44+
impl Flycheck {
45+
pub fn new(config: CheckConfig, workspace_root: PathBuf) -> Flycheck {
4746
let (task_send, task_recv) = unbounded::<CheckTask>();
4847
let (cmd_send, cmd_recv) = unbounded::<CheckCommand>();
4948
let handle = jod_thread::spawn(move || {
50-
let mut check = CheckWatcherThread::new(config, workspace_root);
49+
let mut check = FlycheckThread::new(config, workspace_root);
5150
check.run(&task_send, &cmd_recv);
5251
});
53-
CheckWatcher { task_recv, cmd_send, handle: Some(handle) }
52+
Flycheck { task_recv, cmd_send, handle }
5453
}
5554

5655
/// Schedule a re-start of the cargo check worker.
@@ -76,7 +75,7 @@ pub enum CheckCommand {
7675
Update,
7776
}
7877

79-
struct CheckWatcherThread {
78+
struct FlycheckThread {
8079
options: CheckConfig,
8180
workspace_root: PathBuf,
8281
last_update_req: Option<Instant>,
@@ -90,9 +89,9 @@ struct CheckWatcherThread {
9089
check_process: Option<jod_thread::JoinHandle<()>>,
9190
}
9291

93-
impl CheckWatcherThread {
94-
fn new(options: CheckConfig, workspace_root: PathBuf) -> CheckWatcherThread {
95-
CheckWatcherThread {
92+
impl FlycheckThread {
93+
fn new(options: CheckConfig, workspace_root: PathBuf) -> FlycheckThread {
94+
FlycheckThread {
9695
options,
9796
workspace_root,
9897
last_update_req: None,
@@ -216,9 +215,6 @@ impl CheckWatcherThread {
216215
// First, clear and cancel the old thread
217216
self.message_recv = never();
218217
self.check_process = None;
219-
if !self.options.enable {
220-
return;
221-
}
222218

223219
let mut args: Vec<String> = vec![
224220
self.options.command.clone(),

crates/rust-analyzer/src/main_loop.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,14 @@ fn get_config(
101101
chaining_hints: config.inlay_hints_chaining,
102102
max_length: config.inlay_hints_max_length,
103103
},
104-
check: CheckConfig {
105-
enable: config.cargo_watch_enable,
106-
args: config.cargo_watch_args.clone(),
107-
command: config.cargo_watch_command.clone(),
108-
all_targets: config.cargo_watch_all_targets,
104+
check: if config.cargo_watch_enable {
105+
Some(CheckConfig {
106+
args: config.cargo_watch_args.clone(),
107+
command: config.cargo_watch_command.clone(),
108+
all_targets: config.cargo_watch_all_targets,
109+
})
110+
} else {
111+
None
109112
},
110113
rustfmt_args: config.rustfmt_args.clone(),
111114
vscode_lldb: config.vscode_lldb,
@@ -240,7 +243,7 @@ pub fn main_loop(
240243
Err(RecvError) => return Err("vfs died".into()),
241244
},
242245
recv(libdata_receiver) -> data => Event::Lib(data.unwrap()),
243-
recv(world_state.check_watcher.as_ref().map_or(&never(), |it| &it.task_recv)) -> task => match task {
246+
recv(world_state.flycheck.as_ref().map_or(&never(), |it| &it.task_recv)) -> task => match task {
244247
Ok(task) => Event::CheckWatcher(task),
245248
Err(RecvError) => return Err("check watcher died".into()),
246249
}
@@ -481,8 +484,8 @@ fn loop_turn(
481484
&& loop_state.in_flight_libraries == 0
482485
{
483486
loop_state.workspace_loaded = true;
484-
if let Some(check_watcher) = &world_state.check_watcher {
485-
check_watcher.update();
487+
if let Some(flycheck) = &world_state.flycheck {
488+
flycheck.update();
486489
}
487490
pool.execute({
488491
let subs = loop_state.subscriptions.subscriptions();
@@ -654,8 +657,8 @@ fn on_notification(
654657
};
655658
let not = match notification_cast::<req::DidSaveTextDocument>(not) {
656659
Ok(_params) => {
657-
if let Some(check_watcher) = &state.check_watcher {
658-
check_watcher.update();
660+
if let Some(flycheck) = &state.flycheck {
661+
flycheck.update();
659662
}
660663
return Ok(());
661664
}

crates/rust-analyzer/src/world.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
use crossbeam_channel::{unbounded, Receiver};
1212
use lsp_types::Url;
1313
use parking_lot::RwLock;
14-
use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckConfig, CheckWatcher};
14+
use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckConfig, Flycheck};
1515
use ra_ide::{
1616
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, InlayHintsConfig, LibraryData,
1717
SourceRootId,
@@ -31,7 +31,9 @@ use crate::{
3131
use ra_db::ExternSourceId;
3232
use rustc_hash::{FxHashMap, FxHashSet};
3333

34-
fn create_watcher(workspaces: &[ProjectWorkspace], config: &Config) -> Option<CheckWatcher> {
34+
fn create_flycheck(workspaces: &[ProjectWorkspace], config: &Config) -> Option<Flycheck> {
35+
let check_config = config.check.as_ref()?;
36+
3537
// FIXME: Figure out the multi-workspace situation
3638
workspaces
3739
.iter()
@@ -41,7 +43,7 @@ fn create_watcher(workspaces: &[ProjectWorkspace], config: &Config) -> Option<Ch
4143
})
4244
.map(|cargo| {
4345
let cargo_project_root = cargo.workspace_root().to_path_buf();
44-
Some(CheckWatcher::new(config.check.clone(), cargo_project_root))
46+
Some(Flycheck::new(check_config.clone(), cargo_project_root))
4547
})
4648
.unwrap_or_else(|| {
4749
log::warn!("Cargo check watching only supported for cargo workspaces, disabling");
@@ -56,7 +58,7 @@ pub struct Config {
5658
pub line_folding_only: bool,
5759
pub inlay_hints: InlayHintsConfig,
5860
pub rustfmt_args: Vec<String>,
59-
pub check: CheckConfig,
61+
pub check: Option<CheckConfig>,
6062
pub vscode_lldb: bool,
6163
pub proc_macro_srv: Option<String>,
6264
}
@@ -76,7 +78,7 @@ pub struct WorldState {
7678
pub vfs: Arc<RwLock<Vfs>>,
7779
pub task_receiver: Receiver<VfsTask>,
7880
pub latest_requests: Arc<RwLock<LatestRequests>>,
79-
pub check_watcher: Option<CheckWatcher>,
81+
pub flycheck: Option<Flycheck>,
8082
pub diagnostics: DiagnosticCollection,
8183
}
8284

@@ -201,7 +203,7 @@ impl WorldState {
201203
});
202204
change.set_crate_graph(crate_graph);
203205

204-
let check_watcher = create_watcher(&workspaces, &config);
206+
let flycheck = create_flycheck(&workspaces, &config);
205207

206208
let mut analysis_host = AnalysisHost::new(lru_capacity);
207209
analysis_host.apply_change(change);
@@ -214,7 +216,7 @@ impl WorldState {
214216
vfs: Arc::new(RwLock::new(vfs)),
215217
task_receiver,
216218
latest_requests: Default::default(),
217-
check_watcher,
219+
flycheck,
218220
diagnostics: Default::default(),
219221
}
220222
}
@@ -227,7 +229,7 @@ impl WorldState {
227229
) {
228230
self.feature_flags = Arc::new(feature_flags);
229231
self.analysis_host.update_lru_capacity(lru_capacity);
230-
self.check_watcher = create_watcher(&self.workspaces, &config);
232+
self.flycheck = create_flycheck(&self.workspaces, &config);
231233
self.config = config;
232234
}
233235

0 commit comments

Comments
 (0)