diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 7 | ||||
-rw-r--r-- | crates/rust-analyzer/src/op_queue.rs | 26 | ||||
-rw-r--r-- | crates/rust-analyzer/src/reload.rs | 4 |
3 files changed, 24 insertions, 13 deletions
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 52c249713..8679c8599 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs | |||
@@ -81,10 +81,13 @@ pub(crate) struct GlobalState { | |||
81 | pub(crate) status: Status, | 81 | pub(crate) status: Status, |
82 | pub(crate) source_root_config: SourceRootConfig, | 82 | pub(crate) source_root_config: SourceRootConfig, |
83 | pub(crate) proc_macro_client: Option<ProcMacroClient>, | 83 | pub(crate) proc_macro_client: Option<ProcMacroClient>, |
84 | |||
84 | pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>, | 85 | pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>, |
85 | pub(crate) fetch_workspaces_queue: OpQueue<()>, | 86 | pub(crate) fetch_workspaces_queue: OpQueue<(), ()>, |
87 | |||
86 | pub(crate) workspace_build_data: Option<BuildDataResult>, | 88 | pub(crate) workspace_build_data: Option<BuildDataResult>, |
87 | pub(crate) fetch_build_data_queue: OpQueue<BuildDataCollector>, | 89 | pub(crate) fetch_build_data_queue: OpQueue<BuildDataCollector, ()>, |
90 | |||
88 | latest_requests: Arc<RwLock<LatestRequests>>, | 91 | latest_requests: Arc<RwLock<LatestRequests>>, |
89 | } | 92 | } |
90 | 93 | ||
diff --git a/crates/rust-analyzer/src/op_queue.rs b/crates/rust-analyzer/src/op_queue.rs index 761b9ad39..f71b718bc 100644 --- a/crates/rust-analyzer/src/op_queue.rs +++ b/crates/rust-analyzer/src/op_queue.rs | |||
@@ -1,29 +1,37 @@ | |||
1 | //! Bookkeeping to make sure only one long-running operation is executed. | 1 | //! Bookkeeping to make sure only one long-running operation is being executed |
2 | //! at a time. | ||
2 | 3 | ||
3 | pub(crate) struct OpQueue<D> { | 4 | pub(crate) struct OpQueue<Args, Output> { |
4 | op_scheduled: Option<D>, | 5 | op_scheduled: Option<Args>, |
5 | op_in_progress: bool, | 6 | op_in_progress: bool, |
7 | last_op_result: Output, | ||
6 | } | 8 | } |
7 | 9 | ||
8 | impl<D> Default for OpQueue<D> { | 10 | impl<Args, Output: Default> Default for OpQueue<Args, Output> { |
9 | fn default() -> Self { | 11 | fn default() -> Self { |
10 | Self { op_scheduled: None, op_in_progress: false } | 12 | Self { op_scheduled: None, op_in_progress: false, last_op_result: Default::default() } |
11 | } | 13 | } |
12 | } | 14 | } |
13 | 15 | ||
14 | impl<D> OpQueue<D> { | 16 | impl<Args, Output> OpQueue<Args, Output> { |
15 | pub(crate) fn request_op(&mut self, data: D) { | 17 | pub(crate) fn request_op(&mut self, data: Args) { |
16 | self.op_scheduled = Some(data); | 18 | self.op_scheduled = Some(data); |
17 | } | 19 | } |
18 | pub(crate) fn should_start_op(&mut self) -> Option<D> { | 20 | pub(crate) fn should_start_op(&mut self) -> Option<Args> { |
19 | if self.op_in_progress { | 21 | if self.op_in_progress { |
20 | return None; | 22 | return None; |
21 | } | 23 | } |
22 | self.op_in_progress = self.op_scheduled.is_some(); | 24 | self.op_in_progress = self.op_scheduled.is_some(); |
23 | self.op_scheduled.take() | 25 | self.op_scheduled.take() |
24 | } | 26 | } |
25 | pub(crate) fn op_completed(&mut self) { | 27 | pub(crate) fn op_completed(&mut self, result: Output) { |
26 | assert!(self.op_in_progress); | 28 | assert!(self.op_in_progress); |
27 | self.op_in_progress = false; | 29 | self.op_in_progress = false; |
30 | self.last_op_result = result; | ||
31 | } | ||
32 | |||
33 | #[allow(unused)] | ||
34 | pub(crate) fn last_op_result(&self) -> &Output { | ||
35 | &self.last_op_result | ||
28 | } | 36 | } |
29 | } | 37 | } |
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index 76fdbcddd..d12f891bb 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs | |||
@@ -140,7 +140,7 @@ impl GlobalState { | |||
140 | }); | 140 | }); |
141 | } | 141 | } |
142 | pub(crate) fn fetch_build_data_completed(&mut self) { | 142 | pub(crate) fn fetch_build_data_completed(&mut self) { |
143 | self.fetch_build_data_queue.op_completed() | 143 | self.fetch_build_data_queue.op_completed(()) |
144 | } | 144 | } |
145 | 145 | ||
146 | pub(crate) fn fetch_workspaces_request(&mut self) { | 146 | pub(crate) fn fetch_workspaces_request(&mut self) { |
@@ -195,7 +195,7 @@ impl GlobalState { | |||
195 | }); | 195 | }); |
196 | } | 196 | } |
197 | pub(crate) fn fetch_workspaces_completed(&mut self) { | 197 | pub(crate) fn fetch_workspaces_completed(&mut self) { |
198 | self.fetch_workspaces_queue.op_completed() | 198 | self.fetch_workspaces_queue.op_completed(()) |
199 | } | 199 | } |
200 | 200 | ||
201 | pub(crate) fn switch_workspaces( | 201 | pub(crate) fn switch_workspaces( |