mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
parent
dda942debe
commit
3990d971e5
3 changed files with 22 additions and 22 deletions
|
@ -29,27 +29,27 @@ pub struct CheckConfig {
|
||||||
pub all_targets: bool,
|
pub all_targets: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// CheckWatcher wraps the shared state and communication machinery used for
|
/// Flycheck wraps the shared state and communication machinery used for
|
||||||
/// running `cargo check` (or other compatible command) and providing
|
/// running `cargo check` (or other compatible command) and providing
|
||||||
/// diagnostics based on the output.
|
/// diagnostics based on the output.
|
||||||
/// The spawned thread is shut down when this struct is dropped.
|
/// The spawned thread is shut down when this struct is dropped.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CheckWatcher {
|
pub struct Flycheck {
|
||||||
// XXX: drop order is significant
|
// XXX: drop order is significant
|
||||||
cmd_send: Sender<CheckCommand>,
|
cmd_send: Sender<CheckCommand>,
|
||||||
handle: Option<jod_thread::JoinHandle<()>>,
|
handle: Option<jod_thread::JoinHandle<()>>,
|
||||||
pub task_recv: Receiver<CheckTask>,
|
pub task_recv: Receiver<CheckTask>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CheckWatcher {
|
impl Flycheck {
|
||||||
pub fn new(config: CheckConfig, workspace_root: PathBuf) -> CheckWatcher {
|
pub fn new(config: CheckConfig, workspace_root: PathBuf) -> Flycheck {
|
||||||
let (task_send, task_recv) = unbounded::<CheckTask>();
|
let (task_send, task_recv) = unbounded::<CheckTask>();
|
||||||
let (cmd_send, cmd_recv) = unbounded::<CheckCommand>();
|
let (cmd_send, cmd_recv) = unbounded::<CheckCommand>();
|
||||||
let handle = jod_thread::spawn(move || {
|
let handle = jod_thread::spawn(move || {
|
||||||
let mut check = CheckWatcherThread::new(config, workspace_root);
|
let mut check = FlycheckThread::new(config, workspace_root);
|
||||||
check.run(&task_send, &cmd_recv);
|
check.run(&task_send, &cmd_recv);
|
||||||
});
|
});
|
||||||
CheckWatcher { task_recv, cmd_send, handle: Some(handle) }
|
Flycheck { task_recv, cmd_send, handle: Some(handle) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Schedule a re-start of the cargo check worker.
|
/// Schedule a re-start of the cargo check worker.
|
||||||
|
@ -75,7 +75,7 @@ pub enum CheckCommand {
|
||||||
Update,
|
Update,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CheckWatcherThread {
|
struct FlycheckThread {
|
||||||
options: CheckConfig,
|
options: CheckConfig,
|
||||||
workspace_root: PathBuf,
|
workspace_root: PathBuf,
|
||||||
last_update_req: Option<Instant>,
|
last_update_req: Option<Instant>,
|
||||||
|
@ -89,9 +89,9 @@ struct CheckWatcherThread {
|
||||||
check_process: Option<jod_thread::JoinHandle<()>>,
|
check_process: Option<jod_thread::JoinHandle<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CheckWatcherThread {
|
impl FlycheckThread {
|
||||||
fn new(options: CheckConfig, workspace_root: PathBuf) -> CheckWatcherThread {
|
fn new(options: CheckConfig, workspace_root: PathBuf) -> FlycheckThread {
|
||||||
CheckWatcherThread {
|
FlycheckThread {
|
||||||
options,
|
options,
|
||||||
workspace_root,
|
workspace_root,
|
||||||
last_update_req: None,
|
last_update_req: None,
|
||||||
|
|
|
@ -243,7 +243,7 @@ pub fn main_loop(
|
||||||
Err(RecvError) => return Err("vfs died".into()),
|
Err(RecvError) => return Err("vfs died".into()),
|
||||||
},
|
},
|
||||||
recv(libdata_receiver) -> data => Event::Lib(data.unwrap()),
|
recv(libdata_receiver) -> data => Event::Lib(data.unwrap()),
|
||||||
recv(world_state.check_watcher.as_ref().map_or(&never(), |it| &it.task_recv)) -> task => match task {
|
recv(world_state.flycheck.as_ref().map_or(&never(), |it| &it.task_recv)) -> task => match task {
|
||||||
Ok(task) => Event::CheckWatcher(task),
|
Ok(task) => Event::CheckWatcher(task),
|
||||||
Err(RecvError) => return Err("check watcher died".into()),
|
Err(RecvError) => return Err("check watcher died".into()),
|
||||||
}
|
}
|
||||||
|
@ -484,8 +484,8 @@ fn loop_turn(
|
||||||
&& loop_state.in_flight_libraries == 0
|
&& loop_state.in_flight_libraries == 0
|
||||||
{
|
{
|
||||||
loop_state.workspace_loaded = true;
|
loop_state.workspace_loaded = true;
|
||||||
if let Some(check_watcher) = &world_state.check_watcher {
|
if let Some(flycheck) = &world_state.flycheck {
|
||||||
check_watcher.update();
|
flycheck.update();
|
||||||
}
|
}
|
||||||
pool.execute({
|
pool.execute({
|
||||||
let subs = loop_state.subscriptions.subscriptions();
|
let subs = loop_state.subscriptions.subscriptions();
|
||||||
|
@ -657,8 +657,8 @@ fn on_notification(
|
||||||
};
|
};
|
||||||
let not = match notification_cast::<req::DidSaveTextDocument>(not) {
|
let not = match notification_cast::<req::DidSaveTextDocument>(not) {
|
||||||
Ok(_params) => {
|
Ok(_params) => {
|
||||||
if let Some(check_watcher) = &state.check_watcher {
|
if let Some(flycheck) = &state.flycheck {
|
||||||
check_watcher.update();
|
flycheck.update();
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use std::{
|
||||||
use crossbeam_channel::{unbounded, Receiver};
|
use crossbeam_channel::{unbounded, Receiver};
|
||||||
use lsp_types::Url;
|
use lsp_types::Url;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckConfig, CheckWatcher};
|
use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckConfig, Flycheck};
|
||||||
use ra_ide::{
|
use ra_ide::{
|
||||||
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, InlayHintsConfig, LibraryData,
|
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, InlayHintsConfig, LibraryData,
|
||||||
SourceRootId,
|
SourceRootId,
|
||||||
|
@ -31,7 +31,7 @@ use crate::{
|
||||||
use ra_db::ExternSourceId;
|
use ra_db::ExternSourceId;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
|
|
||||||
fn create_watcher(workspaces: &[ProjectWorkspace], config: &Config) -> Option<CheckWatcher> {
|
fn create_flycheck(workspaces: &[ProjectWorkspace], config: &Config) -> Option<Flycheck> {
|
||||||
let check_config = config.check.as_ref()?;
|
let check_config = config.check.as_ref()?;
|
||||||
|
|
||||||
// FIXME: Figure out the multi-workspace situation
|
// FIXME: Figure out the multi-workspace situation
|
||||||
|
@ -43,7 +43,7 @@ fn create_watcher(workspaces: &[ProjectWorkspace], config: &Config) -> Option<Ch
|
||||||
})
|
})
|
||||||
.map(|cargo| {
|
.map(|cargo| {
|
||||||
let cargo_project_root = cargo.workspace_root().to_path_buf();
|
let cargo_project_root = cargo.workspace_root().to_path_buf();
|
||||||
Some(CheckWatcher::new(check_config.clone(), cargo_project_root))
|
Some(Flycheck::new(check_config.clone(), cargo_project_root))
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
log::warn!("Cargo check watching only supported for cargo workspaces, disabling");
|
log::warn!("Cargo check watching only supported for cargo workspaces, disabling");
|
||||||
|
@ -78,7 +78,7 @@ pub struct WorldState {
|
||||||
pub vfs: Arc<RwLock<Vfs>>,
|
pub vfs: Arc<RwLock<Vfs>>,
|
||||||
pub task_receiver: Receiver<VfsTask>,
|
pub task_receiver: Receiver<VfsTask>,
|
||||||
pub latest_requests: Arc<RwLock<LatestRequests>>,
|
pub latest_requests: Arc<RwLock<LatestRequests>>,
|
||||||
pub check_watcher: Option<CheckWatcher>,
|
pub flycheck: Option<Flycheck>,
|
||||||
pub diagnostics: DiagnosticCollection,
|
pub diagnostics: DiagnosticCollection,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ impl WorldState {
|
||||||
});
|
});
|
||||||
change.set_crate_graph(crate_graph);
|
change.set_crate_graph(crate_graph);
|
||||||
|
|
||||||
let check_watcher = create_watcher(&workspaces, &config);
|
let flycheck = create_flycheck(&workspaces, &config);
|
||||||
|
|
||||||
let mut analysis_host = AnalysisHost::new(lru_capacity);
|
let mut analysis_host = AnalysisHost::new(lru_capacity);
|
||||||
analysis_host.apply_change(change);
|
analysis_host.apply_change(change);
|
||||||
|
@ -216,7 +216,7 @@ impl WorldState {
|
||||||
vfs: Arc::new(RwLock::new(vfs)),
|
vfs: Arc::new(RwLock::new(vfs)),
|
||||||
task_receiver,
|
task_receiver,
|
||||||
latest_requests: Default::default(),
|
latest_requests: Default::default(),
|
||||||
check_watcher,
|
flycheck,
|
||||||
diagnostics: Default::default(),
|
diagnostics: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ impl WorldState {
|
||||||
) {
|
) {
|
||||||
self.feature_flags = Arc::new(feature_flags);
|
self.feature_flags = Arc::new(feature_flags);
|
||||||
self.analysis_host.update_lru_capacity(lru_capacity);
|
self.analysis_host.update_lru_capacity(lru_capacity);
|
||||||
self.check_watcher = create_watcher(&self.workspaces, &config);
|
self.flycheck = create_flycheck(&self.workspaces, &config);
|
||||||
self.config = config;
|
self.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue