From 763d57c94a8a7b8cb9c98eba71d5879419562e39 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 11 Feb 2022 13:16:17 +0100 Subject: [PATCH] Don't return error when definition, completions, etc. are unavailable Co-Authored-By: Nathan Sobo --- crates/editor/src/multi_buffer.rs | 7 ++++-- crates/project/src/project.rs | 38 +++++++++++++------------------ 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/crates/editor/src/multi_buffer.rs b/crates/editor/src/multi_buffer.rs index 8e0cdbe5bf..be6a313a13 100644 --- a/crates/editor/src/multi_buffer.rs +++ b/crates/editor/src/multi_buffer.rs @@ -2297,7 +2297,7 @@ impl History { T: IntoIterator, &'a language::Transaction)>, { assert_eq!(self.transaction_depth, 0); - self.undo_stack.push(Transaction { + let transaction = Transaction { id: self.next_transaction_id.tick(), buffer_transactions: buffer_transactions .into_iter() @@ -2306,7 +2306,10 @@ impl History { first_edit_at: now, last_edit_at: now, suppress_grouping: false, - }); + }; + if !transaction.buffer_transactions.is_empty() { + self.undo_stack.push(transaction); + } } fn finalize_last_transaction(&mut self) { diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 356a515c1a..c12535f557 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1065,13 +1065,10 @@ impl Project { { lang_server = server.clone(); } else { - return Task::ready(Err(anyhow!( - "buffer {} does not have a language server", - buffer.remote_id() - ))); + return Task::ready(Ok(Default::default())); }; } else { - return Task::ready(Err(anyhow!("buffer does not have a language"))); + return Task::ready(Ok(Default::default())); } local_buffers.push((buffer_handle, buffer_abs_path, lang_server)); @@ -1079,10 +1076,7 @@ impl Project { remote_buffers.get_or_insert(Vec::new()).push(buffer_handle); } } else { - return Task::ready(Err(anyhow!( - "buffer {} does not belong to any worktree", - buffer.remote_id() - ))); + return Task::ready(Ok(Default::default())); } } @@ -1163,7 +1157,7 @@ impl Project { worktree = file.worktree.clone(); buffer_abs_path = file.as_local().map(|f| f.abs_path(cx)); } else { - return Task::ready(Err(anyhow!("buffer does not belong to any worktree"))); + return Task::ready(Ok(Default::default())); }; let position = position.to_point_utf16(source_buffer); @@ -1180,10 +1174,10 @@ impl Project { { lang_server = server.clone(); } else { - return Task::ready(Err(anyhow!("buffer does not have a language server"))); + return Task::ready(Ok(Default::default())); }; } else { - return Task::ready(Err(anyhow!("buffer does not have a language"))); + return Task::ready(Ok(Default::default())); } cx.spawn(|this, mut cx| async move { @@ -1282,7 +1276,7 @@ impl Project { }) }) } else { - Task::ready(Err(anyhow!("project does not have a remote id"))) + Task::ready(Ok(Default::default())) } } @@ -1302,7 +1296,7 @@ impl Project { worktree = file.worktree.clone(); buffer_abs_path = file.as_local().map(|f| f.abs_path(cx)); } else { - return Task::ready(Err(anyhow!("buffer does not belong to any worktree"))); + return Task::ready(Ok(Default::default())); }; let position = position.to_point_utf16(source_buffer); @@ -1313,7 +1307,7 @@ impl Project { let lang_server = if let Some(server) = source_buffer.language_server().cloned() { server } else { - return Task::ready(Err(anyhow!("buffer does not have a language server"))); + return Task::ready(Ok(Default::default())); }; cx.spawn(|_, cx| async move { @@ -1385,7 +1379,7 @@ impl Project { .collect() }) } else { - Task::ready(Err(anyhow!("project does not have a remote id"))) + Task::ready(Ok(Default::default())) } } @@ -1403,7 +1397,7 @@ impl Project { let lang_server = if let Some(language_server) = buffer.language_server() { language_server.clone() } else { - return Task::ready(Ok(Default::default())); + return Task::ready(Err(anyhow!("buffer does not have a language server"))); }; cx.spawn(|_, mut cx| async move { @@ -1478,7 +1472,7 @@ impl Project { worktree = file.worktree.clone(); buffer_abs_path = file.as_local().map(|f| f.abs_path(cx)); } else { - return Task::ready(Err(anyhow!("buffer does not belong to any worktree"))); + return Task::ready(Ok(Default::default())); }; let position = position.to_point_utf16(source_buffer); @@ -1496,10 +1490,10 @@ impl Project { { lang_server = server.clone(); } else { - return Task::ready(Err(anyhow!("buffer does not have a language server"))); + return Task::ready(Ok(Default::default())); }; } else { - return Task::ready(Err(anyhow!("buffer does not have a language"))); + return Task::ready(Ok(Default::default())); } cx.foreground().spawn(async move { @@ -1556,7 +1550,7 @@ impl Project { .collect() }) } else { - Task::ready(Err(anyhow!("project does not have a remote id"))) + Task::ready(Ok(Default::default())) } } @@ -1577,7 +1571,7 @@ impl Project { let lang_server = if let Some(language_server) = buffer.language_server() { language_server.clone() } else { - return Task::ready(Ok(Default::default())); + return Task::ready(Err(anyhow!("buffer does not have a language server"))); }; let position = action.position.to_point_utf16(buffer).to_lsp_position(); let fs = self.fs.clone();