Skip to content

Commit 9143e39

Browse files
committed
Prepare for more stateless status reporting
1 parent e3c47cc commit 9143e39

File tree

2 files changed

+36
-35
lines changed

2 files changed

+36
-35
lines changed

crates/rust-analyzer/src/global_state.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,25 @@ pub(crate) struct GlobalState {
6767
req_queue: ReqQueue,
6868
pub(crate) task_pool: Handle<TaskPool<Task>, Receiver<Task>>,
6969
pub(crate) loader: Handle<Box<dyn vfs::loader::Handle>, Receiver<vfs::loader::Message>>,
70-
pub(crate) vfs_config_version: u32,
71-
pub(crate) flycheck: Vec<FlycheckHandle>,
72-
pub(crate) flycheck_sender: Sender<flycheck::Message>,
73-
pub(crate) flycheck_receiver: Receiver<flycheck::Message>,
7470
pub(crate) config: Arc<Config>,
7571
pub(crate) analysis_host: AnalysisHost,
7672
pub(crate) diagnostics: DiagnosticCollection,
7773
pub(crate) mem_docs: FxHashMap<VfsPath, DocumentData>,
7874
pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>,
79-
pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
8075
pub(crate) shutdown_requested: bool,
8176
pub(crate) status: Status,
8277
pub(crate) source_root_config: SourceRootConfig,
8378
pub(crate) proc_macro_client: Option<ProcMacroClient>,
8479

80+
pub(crate) flycheck: Vec<FlycheckHandle>,
81+
pub(crate) flycheck_sender: Sender<flycheck::Message>,
82+
pub(crate) flycheck_receiver: Receiver<flycheck::Message>,
83+
84+
pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
85+
pub(crate) vfs_config_version: u32,
86+
pub(crate) vfs_progress_n_total: usize,
87+
pub(crate) vfs_progress_n_done: usize,
88+
8589
/// For both `workspaces` and `workspace_build_data`, the field stores the
8690
/// data we actually use, while the `OpQueue` stores the result of the last
8791
/// fetch.
@@ -129,23 +133,27 @@ impl GlobalState {
129133
GlobalState {
130134
sender,
131135
req_queue: ReqQueue::default(),
132-
vfs_config_version: 0,
133136
task_pool,
134137
loader,
135-
flycheck: Vec::new(),
136-
flycheck_sender,
137-
flycheck_receiver,
138138
config: Arc::new(config),
139139
analysis_host,
140140
diagnostics: Default::default(),
141141
mem_docs: FxHashMap::default(),
142142
semantic_tokens_cache: Arc::new(Default::default()),
143-
vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))),
144143
shutdown_requested: false,
145144
status: Status::default(),
146145
source_root_config: SourceRootConfig::default(),
147146
proc_macro_client: None,
148147

148+
flycheck: Vec::new(),
149+
flycheck_sender,
150+
flycheck_receiver,
151+
152+
vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))),
153+
vfs_config_version: 0,
154+
vfs_progress_n_total: 0,
155+
vfs_progress_n_done: 0,
156+
149157
workspaces: Arc::new(Vec::new()),
150158
fetch_workspaces_queue: OpQueue::default(),
151159
workspace_build_data: None,

crates/rust-analyzer/src/main_loop.rs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -314,31 +314,23 @@ impl GlobalState {
314314
}
315315
}
316316
vfs::loader::Message::Progress { n_total, n_done, config_version } => {
317+
self.vfs_progress_n_total = n_total;
318+
self.vfs_progress_n_done = n_done;
317319
always!(config_version <= self.vfs_config_version);
318-
if n_total == 0 {
319-
new_status = Status::Invalid;
320+
let state = if n_done == 0 {
321+
Progress::Begin
322+
} else if n_done < n_total {
323+
Progress::Report
320324
} else {
321-
let state = if n_done == 0 {
322-
new_status = Status::Loading;
323-
Progress::Begin
324-
} else if n_done < n_total {
325-
Progress::Report
326-
} else {
327-
assert_eq!(n_done, n_total);
328-
new_status = Status::Ready {
329-
partial: self.config.run_build_scripts()
330-
&& self.workspace_build_data.is_none()
331-
|| config_version < self.vfs_config_version,
332-
};
333-
Progress::End
334-
};
335-
self.report_progress(
336-
"roots scanned",
337-
state,
338-
Some(format!("{}/{}", n_done, n_total)),
339-
Some(Progress::fraction(n_done, n_total)),
340-
)
341-
}
325+
assert_eq!(n_done, n_total);
326+
Progress::End
327+
};
328+
self.report_progress(
329+
"roots scanned",
330+
state,
331+
Some(format!("{}/{}", n_done, n_total)),
332+
Some(Progress::fraction(n_done, n_total)),
333+
)
342334
}
343335
}
344336
// Coalesce many VFS event into a single loop turn
@@ -497,8 +489,9 @@ impl GlobalState {
497489

498490
RequestDispatcher { req: Some(req), global_state: self }
499491
.on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| {
500-
self.fetch_workspaces_request();
501-
self.fetch_workspaces_if_needed();
492+
s.fetch_workspaces_request();
493+
s.fetch_workspaces_if_needed();
494+
Ok(())
502495
})?
503496
.on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
504497
.on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?

0 commit comments

Comments
 (0)