Prepare for more stateless status reporting
This commit is contained in:
parent
e3c47ccefc
commit
9143e3925c
@ -67,21 +67,25 @@ pub(crate) struct GlobalState {
|
||||
req_queue: ReqQueue,
|
||||
pub(crate) task_pool: Handle<TaskPool<Task>, Receiver<Task>>,
|
||||
pub(crate) loader: Handle<Box<dyn vfs::loader::Handle>, Receiver<vfs::loader::Message>>,
|
||||
pub(crate) vfs_config_version: u32,
|
||||
pub(crate) flycheck: Vec<FlycheckHandle>,
|
||||
pub(crate) flycheck_sender: Sender<flycheck::Message>,
|
||||
pub(crate) flycheck_receiver: Receiver<flycheck::Message>,
|
||||
pub(crate) config: Arc<Config>,
|
||||
pub(crate) analysis_host: AnalysisHost,
|
||||
pub(crate) diagnostics: DiagnosticCollection,
|
||||
pub(crate) mem_docs: FxHashMap<VfsPath, DocumentData>,
|
||||
pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>,
|
||||
pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
|
||||
pub(crate) shutdown_requested: bool,
|
||||
pub(crate) status: Status,
|
||||
pub(crate) source_root_config: SourceRootConfig,
|
||||
pub(crate) proc_macro_client: Option<ProcMacroClient>,
|
||||
|
||||
pub(crate) flycheck: Vec<FlycheckHandle>,
|
||||
pub(crate) flycheck_sender: Sender<flycheck::Message>,
|
||||
pub(crate) flycheck_receiver: Receiver<flycheck::Message>,
|
||||
|
||||
pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
|
||||
pub(crate) vfs_config_version: u32,
|
||||
pub(crate) vfs_progress_n_total: usize,
|
||||
pub(crate) vfs_progress_n_done: usize,
|
||||
|
||||
/// For both `workspaces` and `workspace_build_data`, the field stores the
|
||||
/// data we actually use, while the `OpQueue` stores the result of the last
|
||||
/// fetch.
|
||||
@ -129,23 +133,27 @@ impl GlobalState {
|
||||
GlobalState {
|
||||
sender,
|
||||
req_queue: ReqQueue::default(),
|
||||
vfs_config_version: 0,
|
||||
task_pool,
|
||||
loader,
|
||||
flycheck: Vec::new(),
|
||||
flycheck_sender,
|
||||
flycheck_receiver,
|
||||
config: Arc::new(config),
|
||||
analysis_host,
|
||||
diagnostics: Default::default(),
|
||||
mem_docs: FxHashMap::default(),
|
||||
semantic_tokens_cache: Arc::new(Default::default()),
|
||||
vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))),
|
||||
shutdown_requested: false,
|
||||
status: Status::default(),
|
||||
source_root_config: SourceRootConfig::default(),
|
||||
proc_macro_client: None,
|
||||
|
||||
flycheck: Vec::new(),
|
||||
flycheck_sender,
|
||||
flycheck_receiver,
|
||||
|
||||
vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))),
|
||||
vfs_config_version: 0,
|
||||
vfs_progress_n_total: 0,
|
||||
vfs_progress_n_done: 0,
|
||||
|
||||
workspaces: Arc::new(Vec::new()),
|
||||
fetch_workspaces_queue: OpQueue::default(),
|
||||
workspace_build_data: None,
|
||||
|
@ -314,31 +314,23 @@ impl GlobalState {
|
||||
}
|
||||
}
|
||||
vfs::loader::Message::Progress { n_total, n_done, config_version } => {
|
||||
self.vfs_progress_n_total = n_total;
|
||||
self.vfs_progress_n_done = n_done;
|
||||
always!(config_version <= self.vfs_config_version);
|
||||
if n_total == 0 {
|
||||
new_status = Status::Invalid;
|
||||
let state = if n_done == 0 {
|
||||
Progress::Begin
|
||||
} else if n_done < n_total {
|
||||
Progress::Report
|
||||
} else {
|
||||
let state = if n_done == 0 {
|
||||
new_status = Status::Loading;
|
||||
Progress::Begin
|
||||
} else if n_done < n_total {
|
||||
Progress::Report
|
||||
} else {
|
||||
assert_eq!(n_done, n_total);
|
||||
new_status = Status::Ready {
|
||||
partial: self.config.run_build_scripts()
|
||||
&& self.workspace_build_data.is_none()
|
||||
|| config_version < self.vfs_config_version,
|
||||
};
|
||||
Progress::End
|
||||
};
|
||||
self.report_progress(
|
||||
"roots scanned",
|
||||
state,
|
||||
Some(format!("{}/{}", n_done, n_total)),
|
||||
Some(Progress::fraction(n_done, n_total)),
|
||||
)
|
||||
}
|
||||
assert_eq!(n_done, n_total);
|
||||
Progress::End
|
||||
};
|
||||
self.report_progress(
|
||||
"roots scanned",
|
||||
state,
|
||||
Some(format!("{}/{}", n_done, n_total)),
|
||||
Some(Progress::fraction(n_done, n_total)),
|
||||
)
|
||||
}
|
||||
}
|
||||
// Coalesce many VFS event into a single loop turn
|
||||
@ -497,8 +489,9 @@ impl GlobalState {
|
||||
|
||||
RequestDispatcher { req: Some(req), global_state: self }
|
||||
.on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| {
|
||||
self.fetch_workspaces_request();
|
||||
self.fetch_workspaces_if_needed();
|
||||
s.fetch_workspaces_request();
|
||||
s.fetch_workspaces_if_needed();
|
||||
Ok(())
|
||||
})?
|
||||
.on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
|
||||
.on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?
|
||||
|
Loading…
x
Reference in New Issue
Block a user