mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
internal: more visibility into why things happen
This commit is contained in:
parent
6f037da8cb
commit
3f4235d59b
@ -192,7 +192,8 @@ impl GlobalState {
|
|||||||
if let Some(path) = vfs.file_path(file.file_id).as_path() {
|
if let Some(path) = vfs.file_path(file.file_id).as_path() {
|
||||||
let path = path.to_path_buf();
|
let path = path.to_path_buf();
|
||||||
if reload::should_refresh_for_change(&path, file.change_kind) {
|
if reload::should_refresh_for_change(&path, file.change_kind) {
|
||||||
self.fetch_workspaces_queue.request_op();
|
self.fetch_workspaces_queue
|
||||||
|
.request_op(format!("vfs file change: {}", path.display()));
|
||||||
}
|
}
|
||||||
fs_changes.push((path, file.change_kind));
|
fs_changes.push((path, file.change_kind));
|
||||||
if file.is_created_or_deleted() {
|
if file.is_created_or_deleted() {
|
||||||
|
@ -149,9 +149,9 @@ impl GlobalState {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.fetch_workspaces_queue.request_op();
|
self.fetch_workspaces_queue.request_op("startup".to_string());
|
||||||
if self.fetch_workspaces_queue.should_start_op() {
|
if let Some(cause) = self.fetch_workspaces_queue.should_start_op() {
|
||||||
self.fetch_workspaces();
|
self.fetch_workspaces(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
while let Some(event) = self.next_event(&inbox) {
|
while let Some(event) = self.next_event(&inbox) {
|
||||||
@ -240,7 +240,8 @@ impl GlobalState {
|
|||||||
let workspaces_updated = !Arc::ptr_eq(&old, &self.workspaces);
|
let workspaces_updated = !Arc::ptr_eq(&old, &self.workspaces);
|
||||||
|
|
||||||
if self.config.run_build_scripts() && workspaces_updated {
|
if self.config.run_build_scripts() && workspaces_updated {
|
||||||
self.fetch_build_data_queue.request_op()
|
self.fetch_build_data_queue
|
||||||
|
.request_op(format!("workspace updated"));
|
||||||
}
|
}
|
||||||
|
|
||||||
(Progress::End, None)
|
(Progress::End, None)
|
||||||
@ -312,7 +313,8 @@ impl GlobalState {
|
|||||||
|
|
||||||
self.prime_caches_queue.op_completed(());
|
self.prime_caches_queue.op_completed(());
|
||||||
if cancelled {
|
if cancelled {
|
||||||
self.prime_caches_queue.request_op();
|
self.prime_caches_queue
|
||||||
|
.request_op("restart after cancelation".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -443,7 +445,7 @@ impl GlobalState {
|
|||||||
flycheck.update();
|
flycheck.update();
|
||||||
}
|
}
|
||||||
if self.config.prefill_caches() {
|
if self.config.prefill_caches() {
|
||||||
self.prime_caches_queue.request_op();
|
self.prime_caches_queue.request_op("became quiescent".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,14 +495,15 @@ impl GlobalState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.config.cargo_autoreload() {
|
if self.config.cargo_autoreload() {
|
||||||
if self.fetch_workspaces_queue.should_start_op() {
|
if let Some(cause) = self.fetch_workspaces_queue.should_start_op() {
|
||||||
self.fetch_workspaces();
|
self.fetch_workspaces(cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.fetch_build_data_queue.should_start_op() {
|
if let Some(cause) = self.fetch_build_data_queue.should_start_op() {
|
||||||
self.fetch_build_data();
|
self.fetch_build_data(cause);
|
||||||
}
|
}
|
||||||
if self.prime_caches_queue.should_start_op() {
|
if let Some(cause) = self.prime_caches_queue.should_start_op() {
|
||||||
|
tracing::debug!(%cause, "will prime caches");
|
||||||
let num_worker_threads = self.config.prime_caches_num_threads();
|
let num_worker_threads = self.config.prime_caches_num_threads();
|
||||||
|
|
||||||
self.task_pool.handle.spawn_with_sender({
|
self.task_pool.handle.spawn_with_sender({
|
||||||
@ -569,7 +572,7 @@ impl GlobalState {
|
|||||||
|
|
||||||
RequestDispatcher { req: Some(req), global_state: self }
|
RequestDispatcher { req: Some(req), global_state: self }
|
||||||
.on_sync_mut::<lsp_ext::ReloadWorkspace>(|s, ()| {
|
.on_sync_mut::<lsp_ext::ReloadWorkspace>(|s, ()| {
|
||||||
s.fetch_workspaces_queue.request_op();
|
s.fetch_workspaces_queue.request_op("reload workspace request".to_string());
|
||||||
Ok(())
|
Ok(())
|
||||||
})?
|
})?
|
||||||
.on_sync_mut::<lsp_types::request::Shutdown>(|s, ()| {
|
.on_sync_mut::<lsp_types::request::Shutdown>(|s, ()| {
|
||||||
@ -714,7 +717,7 @@ impl GlobalState {
|
|||||||
}
|
}
|
||||||
if let Ok(abs_path) = from_proto::abs_path(¶ms.text_document.uri) {
|
if let Ok(abs_path) = from_proto::abs_path(¶ms.text_document.uri) {
|
||||||
if reload::should_refresh_for_change(&abs_path, ChangeKind::Modify) {
|
if reload::should_refresh_for_change(&abs_path, ChangeKind::Modify) {
|
||||||
this.fetch_workspaces_queue.request_op();
|
this.fetch_workspaces_queue.request_op(format!("DidSaveTextDocument {}", abs_path.display()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1,29 +1,30 @@
|
|||||||
//! Bookkeeping to make sure only one long-running operation is being executed
|
//! Bookkeeping to make sure only one long-running operation is being executed
|
||||||
//! at a time.
|
//! at a time.
|
||||||
|
|
||||||
|
pub(crate) type Cause = String;
|
||||||
|
|
||||||
pub(crate) struct OpQueue<Output> {
|
pub(crate) struct OpQueue<Output> {
|
||||||
op_requested: bool,
|
op_requested: Option<Cause>,
|
||||||
op_in_progress: bool,
|
op_in_progress: bool,
|
||||||
last_op_result: Output,
|
last_op_result: Output,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Output: Default> Default for OpQueue<Output> {
|
impl<Output: Default> Default for OpQueue<Output> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self { op_requested: false, op_in_progress: false, last_op_result: Default::default() }
|
Self { op_requested: None, op_in_progress: false, last_op_result: Default::default() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Output> OpQueue<Output> {
|
impl<Output> OpQueue<Output> {
|
||||||
pub(crate) fn request_op(&mut self) {
|
pub(crate) fn request_op(&mut self, reason: Cause) {
|
||||||
self.op_requested = true;
|
self.op_requested = Some(reason);
|
||||||
}
|
}
|
||||||
pub(crate) fn should_start_op(&mut self) -> bool {
|
pub(crate) fn should_start_op(&mut self) -> Option<Cause> {
|
||||||
if self.op_in_progress {
|
if self.op_in_progress {
|
||||||
return false;
|
return None;
|
||||||
}
|
}
|
||||||
self.op_in_progress = self.op_requested;
|
self.op_in_progress = self.op_requested.is_some();
|
||||||
self.op_requested = false;
|
self.op_requested.take()
|
||||||
self.op_in_progress
|
|
||||||
}
|
}
|
||||||
pub(crate) fn op_completed(&mut self, result: Output) {
|
pub(crate) fn op_completed(&mut self, result: Output) {
|
||||||
assert!(self.op_in_progress);
|
assert!(self.op_in_progress);
|
||||||
@ -38,6 +39,6 @@ impl<Output> OpQueue<Output> {
|
|||||||
self.op_in_progress
|
self.op_in_progress
|
||||||
}
|
}
|
||||||
pub(crate) fn op_requested(&self) -> bool {
|
pub(crate) fn op_requested(&self) -> bool {
|
||||||
self.op_requested
|
self.op_requested.is_some()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ use crate::{
|
|||||||
global_state::GlobalState,
|
global_state::GlobalState,
|
||||||
lsp_ext,
|
lsp_ext,
|
||||||
main_loop::Task,
|
main_loop::Task,
|
||||||
|
op_queue::Cause,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -49,7 +50,7 @@ impl GlobalState {
|
|||||||
self.analysis_host.update_lru_capacity(self.config.lru_capacity());
|
self.analysis_host.update_lru_capacity(self.config.lru_capacity());
|
||||||
}
|
}
|
||||||
if self.config.linked_projects() != old_config.linked_projects() {
|
if self.config.linked_projects() != old_config.linked_projects() {
|
||||||
self.fetch_workspaces_queue.request_op()
|
self.fetch_workspaces_queue.request_op("linked projects changed".to_string())
|
||||||
} else if self.config.flycheck() != old_config.flycheck() {
|
} else if self.config.flycheck() != old_config.flycheck() {
|
||||||
self.reload_flycheck();
|
self.reload_flycheck();
|
||||||
}
|
}
|
||||||
@ -92,8 +93,8 @@ impl GlobalState {
|
|||||||
status
|
status
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn fetch_workspaces(&mut self) {
|
pub(crate) fn fetch_workspaces(&mut self, cause: Cause) {
|
||||||
tracing::info!("will fetch workspaces");
|
tracing::info!(%cause, "will fetch workspaces");
|
||||||
|
|
||||||
self.task_pool.handle.spawn_with_sender({
|
self.task_pool.handle.spawn_with_sender({
|
||||||
let linked_projects = self.config.linked_projects();
|
let linked_projects = self.config.linked_projects();
|
||||||
@ -144,7 +145,8 @@ impl GlobalState {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn fetch_build_data(&mut self) {
|
pub(crate) fn fetch_build_data(&mut self, cause: Cause) {
|
||||||
|
tracing::debug!(%cause, "will fetch build data");
|
||||||
let workspaces = Arc::clone(&self.workspaces);
|
let workspaces = Arc::clone(&self.workspaces);
|
||||||
let config = self.config.cargo();
|
let config = self.config.cargo();
|
||||||
self.task_pool.handle.spawn_with_sender(move |sender| {
|
self.task_pool.handle.spawn_with_sender(move |sender| {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user