From 03a7abc48fb13723bdf8132aa46bc9a5ecf0225b Mon Sep 17 00:00:00 2001 From: mo8it Date: Fri, 9 Aug 2024 23:24:57 +0200 Subject: [PATCH 1/9] Use Sender directly instead of a boxed closure --- .../rust-analyzer/crates/rust-analyzer/src/flycheck.rs | 8 ++++---- .../rust-analyzer/crates/rust-analyzer/src/reload.rs | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs index c2b943d1d6f4..168f9702d1c8 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs @@ -109,7 +109,7 @@ pub(crate) struct FlycheckHandle { impl FlycheckHandle { pub(crate) fn spawn( id: usize, - sender: Box, + sender: Sender, config: FlycheckConfig, sysroot_root: Option, workspace_root: AbsPathBuf, @@ -199,7 +199,7 @@ enum StateChange { struct FlycheckActor { /// The workspace id of this flycheck instance. id: usize, - sender: Box, + sender: Sender, config: FlycheckConfig, manifest_path: Option, /// Either the workspace root of the workspace we are flychecking, @@ -235,7 +235,7 @@ pub(crate) const SAVED_FILE_PLACEHOLDER: &str = "$saved_file"; impl FlycheckActor { fn new( id: usize, - sender: Box, + sender: Sender, config: FlycheckConfig, sysroot_root: Option, workspace_root: AbsPathBuf, @@ -479,7 +479,7 @@ impl FlycheckActor { } fn send(&self, check_task: FlycheckMessage) { - (self.sender)(check_task); + self.sender.send(check_task).unwrap(); } } diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs index e432f5d5cff7..dee34b1b393d 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs @@ -758,7 +758,7 @@ impl GlobalState { self.flycheck = match invocation_strategy { crate::flycheck::InvocationStrategy::Once => vec![FlycheckHandle::spawn( 0, - Box::new(move |msg| sender.send(msg).unwrap()), + sender, config, None, self.config.root_path().clone(), @@ -793,10 +793,9 @@ impl GlobalState { )) }) .map(|(id, (root, manifest_path), sysroot_root)| { - let sender = sender.clone(); FlycheckHandle::spawn( id, - Box::new(move |msg| sender.send(msg).unwrap()), + sender.clone(), config.clone(), sysroot_root, root.to_path_buf(), From f4b1b4bb829daa9463092522d9dc253b9e141fd4 Mon Sep 17 00:00:00 2001 From: mo8it Date: Fri, 9 Aug 2024 23:40:32 +0200 Subject: [PATCH 2/9] Use Sender instead of boxed closure in vfs --- src/tools/rust-analyzer/Cargo.lock | 1 + .../crates/load-cargo/src/lib.rs | 3 +- .../crates/rust-analyzer/src/global_state.rs | 3 +- .../crates/vfs-notify/src/lib.rs | 59 +++++++++++-------- src/tools/rust-analyzer/crates/vfs/Cargo.toml | 1 + .../rust-analyzer/crates/vfs/src/loader.rs | 2 +- 6 files changed, 38 insertions(+), 31 deletions(-) diff --git a/src/tools/rust-analyzer/Cargo.lock b/src/tools/rust-analyzer/Cargo.lock index b6bf516af154..265590fe2e84 100644 --- a/src/tools/rust-analyzer/Cargo.lock +++ b/src/tools/rust-analyzer/Cargo.lock @@ -2317,6 +2317,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" name = "vfs" version = "0.0.0" dependencies = [ + "crossbeam-channel", "fst", "indexmap", "nohash-hasher", diff --git a/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs b/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs index eed7d9360e0c..db4e10f7ba1e 100644 --- a/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs +++ b/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs @@ -64,8 +64,7 @@ pub fn load_workspace( let (sender, receiver) = unbounded(); let mut vfs = vfs::Vfs::default(); let mut loader = { - let loader = - vfs_notify::NotifyHandle::spawn(Box::new(move |msg| sender.send(msg).unwrap())); + let loader = vfs_notify::NotifyHandle::spawn(sender); Box::new(loader) }; diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs index df809c072355..bb883a9eaf5c 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs @@ -185,8 +185,7 @@ impl GlobalState { pub(crate) fn new(sender: Sender, config: Config) -> GlobalState { let loader = { let (sender, receiver) = unbounded::(); - let handle: vfs_notify::NotifyHandle = - vfs::loader::Handle::spawn(Box::new(move |msg| sender.send(msg).unwrap())); + let handle: vfs_notify::NotifyHandle = vfs::loader::Handle::spawn(sender); let handle = Box::new(handle) as Box; Handle { handle, receiver } }; diff --git a/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs b/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs index 57e83ac0a89b..7b0f67024c6f 100644 --- a/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs +++ b/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs @@ -119,18 +119,19 @@ impl NotifyActor { self.watched_dir_entries.clear(); self.watched_file_entries.clear(); - let send = |msg| (self.sender)(msg); - send(loader::Message::Progress { - n_total, - n_done: LoadingProgress::Started, - config_version, - dir: None, - }); + self.sender + .send(loader::Message::Progress { + n_total, + n_done: LoadingProgress::Started, + config_version, + dir: None, + }) + .unwrap(); let (entry_tx, entry_rx) = unbounded(); let (watch_tx, watch_rx) = unbounded(); let processed = AtomicUsize::new(0); - config.load.into_par_iter().enumerate().for_each(move |(i, entry)| { + config.load.into_par_iter().enumerate().for_each(|(i, entry)| { let do_watch = config.watch.contains(&i); if do_watch { _ = entry_tx.send(entry.clone()); @@ -140,25 +141,31 @@ impl NotifyActor { entry, do_watch, |file| { - send(loader::Message::Progress { - n_total, - n_done: LoadingProgress::Progress( - processed.load(std::sync::atomic::Ordering::Relaxed), - ), - dir: Some(file), - config_version, - }) + self.sender + .send(loader::Message::Progress { + n_total, + n_done: LoadingProgress::Progress( + processed + .load(std::sync::atomic::Ordering::Relaxed), + ), + dir: Some(file), + config_version, + }) + .unwrap() }, ); - send(loader::Message::Loaded { files }); - send(loader::Message::Progress { - n_total, - n_done: LoadingProgress::Progress( - processed.fetch_add(1, std::sync::atomic::Ordering::AcqRel) + 1, - ), - config_version, - dir: None, - }); + self.sender.send(loader::Message::Loaded { files }).unwrap(); + self.sender + .send(loader::Message::Progress { + n_total, + n_done: LoadingProgress::Progress( + processed.fetch_add(1, std::sync::atomic::Ordering::AcqRel) + + 1, + ), + config_version, + dir: None, + }) + .unwrap(); }); for path in watch_rx { self.watch(&path); @@ -317,7 +324,7 @@ impl NotifyActor { } fn send(&self, msg: loader::Message) { - (self.sender)(msg); + self.sender.send(msg).unwrap(); } } diff --git a/src/tools/rust-analyzer/crates/vfs/Cargo.toml b/src/tools/rust-analyzer/crates/vfs/Cargo.toml index c6f34e2af082..e8a6195036ed 100644 --- a/src/tools/rust-analyzer/crates/vfs/Cargo.toml +++ b/src/tools/rust-analyzer/crates/vfs/Cargo.toml @@ -18,6 +18,7 @@ tracing.workspace = true fst = "0.4.7" indexmap.workspace = true nohash-hasher.workspace = true +crossbeam-channel.workspace = true paths.workspace = true stdx.workspace = true diff --git a/src/tools/rust-analyzer/crates/vfs/src/loader.rs b/src/tools/rust-analyzer/crates/vfs/src/loader.rs index 30c08a9ff2b9..f24354cb493c 100644 --- a/src/tools/rust-analyzer/crates/vfs/src/loader.rs +++ b/src/tools/rust-analyzer/crates/vfs/src/loader.rs @@ -72,7 +72,7 @@ pub enum Message { } /// Type that will receive [`Messages`](Message) from a [`Handle`]. -pub type Sender = Box; +pub type Sender = crossbeam_channel::Sender; /// Interface for reading and watching files. pub trait Handle: fmt::Debug { From 58c614f5b4892b946fad8222f16b01bb6fab3919 Mon Sep 17 00:00:00 2001 From: mo8it Date: Fri, 9 Aug 2024 23:48:03 +0200 Subject: [PATCH 3/9] Use crossbeam-channel from the workspace --- src/tools/rust-analyzer/crates/ide-db/Cargo.toml | 2 +- .../crates/rust-analyzer/Cargo.toml | 16 ++++++++-------- src/tools/rust-analyzer/crates/stdx/Cargo.toml | 2 +- .../rust-analyzer/crates/vfs-notify/Cargo.toml | 2 +- .../rust-analyzer/lib/lsp-server/Cargo.toml | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/tools/rust-analyzer/crates/ide-db/Cargo.toml b/src/tools/rust-analyzer/crates/ide-db/Cargo.toml index 6714a99f80eb..8f3cae2fa170 100644 --- a/src/tools/rust-analyzer/crates/ide-db/Cargo.toml +++ b/src/tools/rust-analyzer/crates/ide-db/Cargo.toml @@ -14,7 +14,7 @@ doctest = false [dependencies] cov-mark = "2.0.0-pre.1" -crossbeam-channel = "0.5.5" +crossbeam-channel.workspace = true tracing.workspace = true rayon.workspace = true fst = { version = "0.4.7", default-features = false } diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml b/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml index f0878b25dd30..eb95f42d755c 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml +++ b/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml @@ -21,7 +21,7 @@ path = "src/bin/main.rs" [dependencies] anyhow.workspace = true -crossbeam-channel = "0.5.5" +crossbeam-channel.workspace = true dirs = "5.0.1" dissimilar.workspace = true itertools.workspace = true @@ -90,13 +90,13 @@ jemalloc = ["jemallocator", "profile/jemalloc"] force-always-assert = ["always-assert/force"] sysroot-abi = [] in-rust-tree = [ - "sysroot-abi", - "syntax/in-rust-tree", - "parser/in-rust-tree", - "hir/in-rust-tree", - "hir-def/in-rust-tree", - "hir-ty/in-rust-tree", - "load-cargo/in-rust-tree", + "sysroot-abi", + "syntax/in-rust-tree", + "parser/in-rust-tree", + "hir/in-rust-tree", + "hir-def/in-rust-tree", + "hir-ty/in-rust-tree", + "load-cargo/in-rust-tree", ] [lints] diff --git a/src/tools/rust-analyzer/crates/stdx/Cargo.toml b/src/tools/rust-analyzer/crates/stdx/Cargo.toml index 77c9f3cb1486..bf0d6df9ad81 100644 --- a/src/tools/rust-analyzer/crates/stdx/Cargo.toml +++ b/src/tools/rust-analyzer/crates/stdx/Cargo.toml @@ -17,7 +17,7 @@ backtrace = { version = "0.3.67", optional = true } always-assert = { version = "0.2.0", features = ["tracing"] } jod-thread = "0.1.2" libc.workspace = true -crossbeam-channel = "0.5.5" +crossbeam-channel.workspace = true itertools.workspace = true # Think twice before adding anything here diff --git a/src/tools/rust-analyzer/crates/vfs-notify/Cargo.toml b/src/tools/rust-analyzer/crates/vfs-notify/Cargo.toml index d2f7079915ff..09296dc6dd53 100644 --- a/src/tools/rust-analyzer/crates/vfs-notify/Cargo.toml +++ b/src/tools/rust-analyzer/crates/vfs-notify/Cargo.toml @@ -15,7 +15,7 @@ doctest = false [dependencies] tracing.workspace = true walkdir = "2.3.2" -crossbeam-channel = "0.5.5" +crossbeam-channel.workspace = true notify = "6.1.1" rayon = "1.10.0" diff --git a/src/tools/rust-analyzer/lib/lsp-server/Cargo.toml b/src/tools/rust-analyzer/lib/lsp-server/Cargo.toml index a89eb4b144c6..fb3411c8ab43 100644 --- a/src/tools/rust-analyzer/lib/lsp-server/Cargo.toml +++ b/src/tools/rust-analyzer/lib/lsp-server/Cargo.toml @@ -10,11 +10,11 @@ edition = "2021" log = "0.4.17" serde_json = "1.0.108" serde = { version = "1.0.192", features = ["derive"] } -crossbeam-channel = "0.5.8" +crossbeam-channel.workspace = true [dev-dependencies] lsp-types = "=0.95" ctrlc = "3.4.1" [lints] -workspace = true \ No newline at end of file +workspace = true From 7341b88e6f1fd39e4650aa26530ac53b1888d9ca Mon Sep 17 00:00:00 2001 From: mo8it Date: Fri, 9 Aug 2024 23:59:42 +0200 Subject: [PATCH 4/9] Remove unneeded `send` method --- .../crates/rust-analyzer/src/flycheck.rs | 26 ++++++++++--------- .../crates/rust-analyzer/src/global_state.rs | 12 +++------ .../crates/vfs-notify/src/lib.rs | 22 +++++++--------- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs index 168f9702d1c8..0ea782e1dee7 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs @@ -256,7 +256,7 @@ impl FlycheckActor { } fn report_progress(&self, progress: Progress) { - self.send(FlycheckMessage::Progress { id: self.id, progress }); + self.sender.send(FlycheckMessage::Progress { id: self.id, progress }).unwrap(); } fn next_event(&self, inbox: &Receiver) -> Option { @@ -329,7 +329,9 @@ impl FlycheckActor { ); } if self.status == FlycheckStatus::Started { - self.send(FlycheckMessage::ClearDiagnostics { id: self.id }); + self.sender + .send(FlycheckMessage::ClearDiagnostics { id: self.id }) + .unwrap(); } self.report_progress(Progress::DidFinish(res)); self.status = FlycheckStatus::Finished; @@ -351,13 +353,17 @@ impl FlycheckActor { "diagnostic received" ); if self.status == FlycheckStatus::Started { - self.send(FlycheckMessage::ClearDiagnostics { id: self.id }); + self.sender + .send(FlycheckMessage::ClearDiagnostics { id: self.id }) + .unwrap(); } - self.send(FlycheckMessage::AddDiagnostic { - id: self.id, - workspace_root: self.root.clone(), - diagnostic: msg, - }); + self.sender + .send(FlycheckMessage::AddDiagnostic { + id: self.id, + workspace_root: self.root.clone(), + diagnostic: msg, + }) + .unwrap(); self.status = FlycheckStatus::DiagnosticSent; } }, @@ -477,10 +483,6 @@ impl FlycheckActor { cmd.args(args); Some(cmd) } - - fn send(&self, check_task: FlycheckMessage) { - self.sender.send(check_task).unwrap(); - } } #[allow(clippy::large_enum_variant)] diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs index bb883a9eaf5c..71f489672711 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs @@ -504,7 +504,7 @@ impl GlobalState { handler: ReqHandler, ) { let request = self.req_queue.outgoing.register(R::METHOD.to_owned(), params, handler); - self.send(request.into()); + self.sender.send(request.into()).unwrap(); } pub(crate) fn complete_request(&mut self, response: lsp_server::Response) { @@ -521,7 +521,7 @@ impl GlobalState { params: N::Params, ) { let not = lsp_server::Notification::new(N::METHOD.to_owned(), params); - self.send(not.into()); + self.sender.send(not.into()).unwrap(); } pub(crate) fn register_request( @@ -544,13 +544,13 @@ impl GlobalState { let duration = start.elapsed(); tracing::debug!("handled {} - ({}) in {:0.2?}", method, response.id, duration); - self.send(response.into()); + self.sender.send(response.into()).unwrap(); } } pub(crate) fn cancel(&mut self, request_id: lsp_server::RequestId) { if let Some(response) = self.req_queue.incoming.cancel(request_id) { - self.send(response.into()); + self.sender.send(response.into()).unwrap(); } } @@ -558,10 +558,6 @@ impl GlobalState { self.req_queue.incoming.is_completed(&request.id) } - fn send(&self, message: lsp_server::Message) { - self.sender.send(message).unwrap() - } - pub(crate) fn publish_diagnostics( &mut self, uri: Url, diff --git a/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs b/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs index 7b0f67024c6f..2bd4eb671353 100644 --- a/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs +++ b/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs @@ -180,17 +180,19 @@ impl NotifyActor { } } } - self.send(loader::Message::Progress { - n_total, - n_done: LoadingProgress::Finished, - config_version, - dir: None, - }); + self.sender + .send(loader::Message::Progress { + n_total, + n_done: LoadingProgress::Finished, + config_version, + dir: None, + }) + .unwrap(); } Message::Invalidate(path) => { let contents = read(path.as_path()); let files = vec![(path, contents)]; - self.send(loader::Message::Changed { files }); + self.sender.send(loader::Message::Changed { files }).unwrap(); } }, Event::NotifyEvent(event) => { @@ -238,7 +240,7 @@ impl NotifyActor { Some((path, contents)) }) .collect(); - self.send(loader::Message::Changed { files }); + self.sender.send(loader::Message::Changed { files }).unwrap(); } } } @@ -322,10 +324,6 @@ impl NotifyActor { log_notify_error(watcher.watch(path, RecursiveMode::NonRecursive)); } } - - fn send(&self, msg: loader::Message) { - self.sender.send(msg).unwrap(); - } } fn read(path: &AbsPath) -> Option> { From 97a6fc65f17febf77b88f08a19b9b461fb7126bc Mon Sep 17 00:00:00 2001 From: mo8it Date: Sun, 11 Aug 2024 14:58:50 +0200 Subject: [PATCH 5/9] Fix deadlock --- src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs b/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs index 2bd4eb671353..bf96788d373d 100644 --- a/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs +++ b/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs @@ -131,6 +131,7 @@ impl NotifyActor { let (entry_tx, entry_rx) = unbounded(); let (watch_tx, watch_rx) = unbounded(); let processed = AtomicUsize::new(0); + config.load.into_par_iter().enumerate().for_each(|(i, entry)| { let do_watch = config.watch.contains(&i); if do_watch { @@ -167,9 +168,13 @@ impl NotifyActor { }) .unwrap(); }); + + drop(watch_tx); for path in watch_rx { self.watch(&path); } + + drop(entry_tx); for entry in entry_rx { match entry { loader::Entry::Files(files) => { @@ -180,6 +185,7 @@ impl NotifyActor { } } } + self.sender .send(loader::Message::Progress { n_total, From 94bd4da3f107952a6128f094858f19f13417a204 Mon Sep 17 00:00:00 2001 From: mo8it Date: Mon, 12 Aug 2024 10:42:35 +0200 Subject: [PATCH 6/9] Revert "Remove unneeded `send` method" This reverts commit 567bde603cfeedb5cfc44e441578c5416bfc4f35. --- .../crates/rust-analyzer/src/flycheck.rs | 26 +++++++++---------- .../crates/rust-analyzer/src/global_state.rs | 12 ++++++--- .../crates/vfs-notify/src/lib.rs | 22 +++++++++------- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs index 0ea782e1dee7..168f9702d1c8 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs @@ -256,7 +256,7 @@ impl FlycheckActor { } fn report_progress(&self, progress: Progress) { - self.sender.send(FlycheckMessage::Progress { id: self.id, progress }).unwrap(); + self.send(FlycheckMessage::Progress { id: self.id, progress }); } fn next_event(&self, inbox: &Receiver) -> Option { @@ -329,9 +329,7 @@ impl FlycheckActor { ); } if self.status == FlycheckStatus::Started { - self.sender - .send(FlycheckMessage::ClearDiagnostics { id: self.id }) - .unwrap(); + self.send(FlycheckMessage::ClearDiagnostics { id: self.id }); } self.report_progress(Progress::DidFinish(res)); self.status = FlycheckStatus::Finished; @@ -353,17 +351,13 @@ impl FlycheckActor { "diagnostic received" ); if self.status == FlycheckStatus::Started { - self.sender - .send(FlycheckMessage::ClearDiagnostics { id: self.id }) - .unwrap(); + self.send(FlycheckMessage::ClearDiagnostics { id: self.id }); } - self.sender - .send(FlycheckMessage::AddDiagnostic { - id: self.id, - workspace_root: self.root.clone(), - diagnostic: msg, - }) - .unwrap(); + self.send(FlycheckMessage::AddDiagnostic { + id: self.id, + workspace_root: self.root.clone(), + diagnostic: msg, + }); self.status = FlycheckStatus::DiagnosticSent; } }, @@ -483,6 +477,10 @@ impl FlycheckActor { cmd.args(args); Some(cmd) } + + fn send(&self, check_task: FlycheckMessage) { + self.sender.send(check_task).unwrap(); + } } #[allow(clippy::large_enum_variant)] diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs index 71f489672711..bb883a9eaf5c 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs @@ -504,7 +504,7 @@ impl GlobalState { handler: ReqHandler, ) { let request = self.req_queue.outgoing.register(R::METHOD.to_owned(), params, handler); - self.sender.send(request.into()).unwrap(); + self.send(request.into()); } pub(crate) fn complete_request(&mut self, response: lsp_server::Response) { @@ -521,7 +521,7 @@ impl GlobalState { params: N::Params, ) { let not = lsp_server::Notification::new(N::METHOD.to_owned(), params); - self.sender.send(not.into()).unwrap(); + self.send(not.into()); } pub(crate) fn register_request( @@ -544,13 +544,13 @@ impl GlobalState { let duration = start.elapsed(); tracing::debug!("handled {} - ({}) in {:0.2?}", method, response.id, duration); - self.sender.send(response.into()).unwrap(); + self.send(response.into()); } } pub(crate) fn cancel(&mut self, request_id: lsp_server::RequestId) { if let Some(response) = self.req_queue.incoming.cancel(request_id) { - self.sender.send(response.into()).unwrap(); + self.send(response.into()); } } @@ -558,6 +558,10 @@ impl GlobalState { self.req_queue.incoming.is_completed(&request.id) } + fn send(&self, message: lsp_server::Message) { + self.sender.send(message).unwrap() + } + pub(crate) fn publish_diagnostics( &mut self, uri: Url, diff --git a/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs b/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs index bf96788d373d..5788fac54749 100644 --- a/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs +++ b/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs @@ -186,19 +186,17 @@ impl NotifyActor { } } - self.sender - .send(loader::Message::Progress { - n_total, - n_done: LoadingProgress::Finished, - config_version, - dir: None, - }) - .unwrap(); + self.send(loader::Message::Progress { + n_total, + n_done: LoadingProgress::Finished, + config_version, + dir: None, + }); } Message::Invalidate(path) => { let contents = read(path.as_path()); let files = vec![(path, contents)]; - self.sender.send(loader::Message::Changed { files }).unwrap(); + self.send(loader::Message::Changed { files }); } }, Event::NotifyEvent(event) => { @@ -246,7 +244,7 @@ impl NotifyActor { Some((path, contents)) }) .collect(); - self.sender.send(loader::Message::Changed { files }).unwrap(); + self.send(loader::Message::Changed { files }); } } } @@ -330,6 +328,10 @@ impl NotifyActor { log_notify_error(watcher.watch(path, RecursiveMode::NonRecursive)); } } + + fn send(&self, msg: loader::Message) { + self.sender.send(msg).unwrap(); + } } fn read(path: &AbsPath) -> Option> { From 7586ba6bfb0e046e4a9f902fe28132b8290445c0 Mon Sep 17 00:00:00 2001 From: mo8it Date: Mon, 12 Aug 2024 10:44:00 +0200 Subject: [PATCH 7/9] Add track_caller --- src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs b/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs index 5788fac54749..cc10793ba47b 100644 --- a/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs +++ b/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs @@ -329,6 +329,7 @@ impl NotifyActor { } } + #[track_caller] fn send(&self, msg: loader::Message) { self.sender.send(msg).unwrap(); } From 285285d3fd9c931f1425bb13f320569b84d40139 Mon Sep 17 00:00:00 2001 From: mo8it Date: Mon, 12 Aug 2024 10:54:46 +0200 Subject: [PATCH 8/9] Add more track_caller --- src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs | 1 + .../rust-analyzer/crates/rust-analyzer/src/global_state.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs index 168f9702d1c8..acd6c3fcd2dd 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs @@ -478,6 +478,7 @@ impl FlycheckActor { Some(cmd) } + #[track_caller] fn send(&self, check_task: FlycheckMessage) { self.sender.send(check_task).unwrap(); } diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs index bb883a9eaf5c..88ff25e5d120 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs @@ -558,8 +558,9 @@ impl GlobalState { self.req_queue.incoming.is_completed(&request.id) } + #[track_caller] fn send(&self, message: lsp_server::Message) { - self.sender.send(message).unwrap() + self.sender.send(message).unwrap(); } pub(crate) fn publish_diagnostics( From f7c4716dbfd77e94af774b4531213519821faba6 Mon Sep 17 00:00:00 2001 From: mo8it Date: Mon, 12 Aug 2024 10:55:04 +0200 Subject: [PATCH 9/9] Use the send method --- .../crates/vfs-notify/src/lib.rs | 54 ++++++++----------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs b/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs index cc10793ba47b..fa2b6669664c 100644 --- a/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs +++ b/src/tools/rust-analyzer/crates/vfs-notify/src/lib.rs @@ -119,14 +119,12 @@ impl NotifyActor { self.watched_dir_entries.clear(); self.watched_file_entries.clear(); - self.sender - .send(loader::Message::Progress { - n_total, - n_done: LoadingProgress::Started, - config_version, - dir: None, - }) - .unwrap(); + self.send(loader::Message::Progress { + n_total, + n_done: LoadingProgress::Started, + config_version, + dir: None, + }); let (entry_tx, entry_rx) = unbounded(); let (watch_tx, watch_rx) = unbounded(); @@ -142,31 +140,25 @@ impl NotifyActor { entry, do_watch, |file| { - self.sender - .send(loader::Message::Progress { - n_total, - n_done: LoadingProgress::Progress( - processed - .load(std::sync::atomic::Ordering::Relaxed), - ), - dir: Some(file), - config_version, - }) - .unwrap() + self.send(loader::Message::Progress { + n_total, + n_done: LoadingProgress::Progress( + processed.load(std::sync::atomic::Ordering::Relaxed), + ), + dir: Some(file), + config_version, + }); }, ); - self.sender.send(loader::Message::Loaded { files }).unwrap(); - self.sender - .send(loader::Message::Progress { - n_total, - n_done: LoadingProgress::Progress( - processed.fetch_add(1, std::sync::atomic::Ordering::AcqRel) - + 1, - ), - config_version, - dir: None, - }) - .unwrap(); + self.send(loader::Message::Loaded { files }); + self.send(loader::Message::Progress { + n_total, + n_done: LoadingProgress::Progress( + processed.fetch_add(1, std::sync::atomic::Ordering::AcqRel) + 1, + ), + config_version, + dir: None, + }); }); drop(watch_tx);