X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=crates%2Frust-analyzer%2Fsrc%2Fmain_loop.rs;h=d70703ff46bdf7edee00b85e1ab6ce44c209e460;hb=815b43429d85b6c6739f01c3b2ae689f5747a2e8;hp=b5ac55e60d6bea15466dbba84ee3d019587649df;hpb=187bd7d48afda84d6aff578274585d9835cbd4bb;p=rust.git diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index b5ac55e60d6..d70703ff46b 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -19,7 +19,7 @@ from_proto, global_state::{file_id_to_url, url_to_file_id, GlobalState}, handlers, lsp_ext, - lsp_utils::{apply_document_changes, is_cancelled, notification_is, Progress}, + lsp_utils::{apply_document_changes, notification_is, Progress}, mem_docs::DocumentData, reload::{self, BuildDataProgress, ProjectWorkspaceProgress}, Result, @@ -60,6 +60,7 @@ enum Event { #[derive(Debug)] pub(crate) enum Task { Response(lsp_server::Response), + Retry(lsp_server::Request), Diagnostics(Vec<(FileId, Vec)>), PrimeCaches(PrimeCachesProgress), FetchWorkspace(ProjectWorkspaceProgress), @@ -196,7 +197,7 @@ fn handle_event(&mut self, event: Event) -> Result<()> { let was_quiescent = self.is_quiescent(); match event { Event::Lsp(msg) => match msg { - lsp_server::Message::Request(req) => self.on_request(loop_start, req)?, + lsp_server::Message::Request(req) => self.on_request(loop_start, req), lsp_server::Message::Notification(not) => { self.on_notification(not)?; } @@ -208,6 +209,7 @@ fn handle_event(&mut self, event: Event) -> Result<()> { loop { match task { Task::Response(response) => self.respond(response), + Task::Retry(req) => self.on_request(loop_start, req), Task::Diagnostics(diagnostics_per_file) => { for (file_id, diagnostics) in diagnostics_per_file { self.diagnostics.set_native_diagnostics(file_id, diagnostics) @@ -553,7 +555,7 @@ fn handle_event(&mut self, event: Event) -> Result<()> { Ok(()) } - fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> { + fn on_request(&mut self, request_received: Instant, req: Request) { self.register_request(&req, request_received); if self.shutdown_requested { @@ -562,8 +564,7 @@ fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> lsp_server::ErrorCode::InvalidRequest as i32, "Shutdown already requested.".to_owned(), )); - - return Ok(()); + return; } // Avoid flashing a bunch of unresolved references during initial load. @@ -573,21 +574,21 @@ fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> lsp_server::ErrorCode::ContentModified as i32, "waiting for cargo metadata or cargo check".to_owned(), )); - return Ok(()); + return; } RequestDispatcher { req: Some(req), global_state: self } .on_sync_mut::(|s, ()| { s.shutdown_requested = true; Ok(()) - })? - .on_sync_mut::(handlers::handle_workspace_reload)? - .on_sync_mut::(handlers::handle_memory_usage)? - .on_sync_mut::(handlers::handle_shuffle_crate_graph)? - .on_sync::(handlers::handle_join_lines)? - .on_sync::(handlers::handle_on_enter)? - .on_sync::(handlers::handle_selection_range)? - .on_sync::(handlers::handle_matching_brace)? + }) + .on_sync_mut::(handlers::handle_workspace_reload) + .on_sync_mut::(handlers::handle_memory_usage) + .on_sync_mut::(handlers::handle_shuffle_crate_graph) + .on_sync::(handlers::handle_join_lines) + .on_sync::(handlers::handle_on_enter) + .on_sync::(handlers::handle_selection_range) + .on_sync::(handlers::handle_matching_brace) .on::(handlers::handle_analyzer_status) .on::(handlers::handle_syntax_tree) .on::(handlers::handle_view_hir) @@ -605,7 +606,7 @@ fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> .on::(handlers::handle_open_cargo_toml) .on::(handlers::handle_move_item) .on::(handlers::handle_workspace_symbol) - .on::(handlers::handle_on_type_formatting) + .on::(handlers::handle_on_type_formatting) .on::(handlers::handle_document_symbol) .on::(handlers::handle_goto_definition) .on::(handlers::handle_goto_declaration) @@ -644,8 +645,8 @@ fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> .on::(handlers::handle_will_rename_files) .on::(handlers::handle_ssr) .finish(); - Ok(()) } + fn on_notification(&mut self, not: Notification) -> Result<()> { NotificationDispatcher { not: Some(not), global_state: self } .on::(|this, params| { @@ -664,11 +665,11 @@ fn on_notification(&mut self, not: Notification) -> Result<()> { })? .on::(|this, params| { if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) { - if this + let already_exists = this .mem_docs .insert(path.clone(), DocumentData::new(params.text_document.version)) - .is_err() - { + .is_err(); + if already_exists { tracing::error!("duplicate DidOpenTextDocument: {}", path) } this.vfs @@ -687,7 +688,7 @@ fn on_notification(&mut self, not: Notification) -> Result<()> { doc.version = params.text_document.version; } None => { - tracing::error!("unexpected DidChangeTextDocument: {}; send DidOpenTextDocument first", path); + tracing::error!("unexpected DidChangeTextDocument: {}", path); return Ok(()); } }; @@ -721,7 +722,8 @@ fn on_notification(&mut self, not: Notification) -> Result<()> { } if let Ok(abs_path) = from_proto::abs_path(¶ms.text_document.uri) { if reload::should_refresh_for_change(&abs_path, ChangeKind::Modify) { - this.fetch_workspaces_queue.request_op(format!("DidSaveTextDocument {}", abs_path.display())); + this.fetch_workspaces_queue + .request_op(format!("DidSaveTextDocument {}", abs_path.display())); } } Ok(()) @@ -750,7 +752,10 @@ fn on_notification(&mut self, not: Notification) -> Result<()> { // provide a configuration. This is handled in Config::update below. let mut config = Config::clone(&*this.config); if let Err(error) = config.update(json.take()) { - this.show_message(lsp_types::MessageType::WARNING, error.to_string()); + this.show_message( + lsp_types::MessageType::WARNING, + error.to_string(), + ); } this.update_configuration(config); } @@ -791,11 +796,6 @@ fn update_diagnostics(&mut self) { .into_iter() .filter_map(|file_id| { handlers::publish_diagnostics(&snapshot, file_id) - .map_err(|err| { - if !is_cancelled(&*err) { - tracing::error!("failed to compute diagnostics: {:?}", err); - } - }) .ok() .map(|diags| (file_id, diags)) })