Skip to content

Commit b66d3ff

Browse files
committed
internal: remove Default from OpQueue
1 parent ac8509a commit b66d3ff

File tree

4 files changed

+380
-255
lines changed

4 files changed

+380
-255
lines changed

crates/rust-analyzer/src/global_state.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ pub(crate) struct FetchWorkspaceRequest {
4646
pub(crate) force_crate_graph_reload: bool,
4747
}
4848

49+
pub(crate) struct FetchWorkspaceResponse {
50+
pub(crate) workspaces: Vec<anyhow::Result<ProjectWorkspace>>,
51+
pub(crate) force_crate_graph_reload: bool,
52+
}
53+
4954
// Enforces drop order
5055
pub(crate) struct Handle<H, C> {
5156
pub(crate) handle: H,
@@ -146,8 +151,7 @@ pub(crate) struct GlobalState {
146151
pub(crate) detached_files: FxHashSet<ManifestPath>,
147152

148153
// op queues
149-
pub(crate) fetch_workspaces_queue:
150-
OpQueue<FetchWorkspaceRequest, Option<(Vec<anyhow::Result<ProjectWorkspace>>, bool)>>,
154+
pub(crate) fetch_workspaces_queue: OpQueue<FetchWorkspaceRequest, FetchWorkspaceResponse>,
151155
pub(crate) fetch_build_data_queue:
152156
OpQueue<(), (Arc<Vec<ProjectWorkspace>>, Vec<anyhow::Result<WorkspaceBuildScripts>>)>,
153157
pub(crate) fetch_proc_macros_queue: OpQueue<Vec<ProcMacroPaths>, bool>,
@@ -502,7 +506,7 @@ impl GlobalState {
502506
mem_docs: self.mem_docs.clone(),
503507
semantic_tokens_cache: Arc::clone(&self.semantic_tokens_cache),
504508
proc_macros_loaded: !self.config.expand_proc_macros()
505-
|| *self.fetch_proc_macros_queue.last_op_result(),
509+
|| self.fetch_proc_macros_queue.last_op_result().copied().unwrap_or(false),
506510
flycheck: self.flycheck.clone(),
507511
}
508512
}

crates/rust-analyzer/src/main_loop.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ use crate::{
2222
diagnostics::{fetch_native_diagnostics, DiagnosticsGeneration, NativeDiagnosticsFetchKind},
2323
discover::{DiscoverArgument, DiscoverCommand, DiscoverProjectMessage},
2424
flycheck::{self, FlycheckMessage},
25-
global_state::{file_id_to_url, url_to_file_id, FetchWorkspaceRequest, GlobalState},
25+
global_state::{
26+
file_id_to_url, url_to_file_id, FetchWorkspaceRequest, FetchWorkspaceResponse, GlobalState,
27+
},
2628
hack_recover_crate_name,
2729
handlers::dispatch::{NotificationDispatcher, RequestDispatcher},
2830
lsp::{
@@ -695,9 +697,9 @@ impl GlobalState {
695697
let (state, msg) = match progress {
696698
ProjectWorkspaceProgress::Begin => (Progress::Begin, None),
697699
ProjectWorkspaceProgress::Report(msg) => (Progress::Report, Some(msg)),
698-
ProjectWorkspaceProgress::End(workspaces, force_reload_crate_graph) => {
699-
self.fetch_workspaces_queue
700-
.op_completed(Some((workspaces, force_reload_crate_graph)));
700+
ProjectWorkspaceProgress::End(workspaces, force_crate_graph_reload) => {
701+
let resp = FetchWorkspaceResponse { workspaces, force_crate_graph_reload };
702+
self.fetch_workspaces_queue.op_completed(resp);
701703
if let Err(e) = self.fetch_workspace_error() {
702704
error!("FetchWorkspaceError: {e}");
703705
}

crates/rust-analyzer/src/op_queue.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ pub(crate) type Cause = String;
2727
pub(crate) struct OpQueue<Args = (), Output = ()> {
2828
op_requested: Option<(Cause, Args)>,
2929
op_in_progress: bool,
30-
last_op_result: Output,
30+
last_op_result: Option<Output>,
3131
}
3232

33-
impl<Args, Output: Default> Default for OpQueue<Args, Output> {
33+
impl<Args, Output> Default for OpQueue<Args, Output> {
3434
fn default() -> Self {
35-
Self { op_requested: None, op_in_progress: false, last_op_result: Default::default() }
35+
Self { op_requested: None, op_in_progress: false, last_op_result: None }
3636
}
3737
}
3838

@@ -56,12 +56,12 @@ impl<Args, Output> OpQueue<Args, Output> {
5656
pub(crate) fn op_completed(&mut self, result: Output) {
5757
assert!(self.op_in_progress);
5858
self.op_in_progress = false;
59-
self.last_op_result = result;
59+
self.last_op_result = Some(result);
6060
}
6161

6262
/// Get the result of the last operation.
63-
pub(crate) fn last_op_result(&self) -> &Output {
64-
&self.last_op_result
63+
pub(crate) fn last_op_result(&self) -> Option<&Output> {
64+
self.last_op_result.as_ref()
6565
}
6666

6767
// Is there an operation that has started, but hasn't yet finished?

0 commit comments

Comments
 (0)