Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Fix invalid excerpt panic in `Editor::hover_links` (#40387)
Lukas Wirth87adc96e0fc4
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 8e3f594f185..5b0d4b68a5f 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -3899,6 +3899,9 @@ impl Editor {}}).collect::<Vec<_>>();+ if selection_ranges.is_empty() {+ return;+ }let ranges = match columnar_state {ColumnarSelectionState::FromMouse { .. } => {diff --git a/crates/editor/src/hover_links.rs b/crates/editor/src/hover_links.rsindex 9b6247a9715..d51617b6371 100644--- a/crates/editor/src/hover_links.rs+++ b/crates/editor/src/hover_links.rs@@ -493,22 +493,15 @@ pub fn show_link_definition(}let trigger_anchor = trigger_point.anchor();- let Some((buffer, buffer_position)) = editor- .buffer- .read(cx)- .text_anchor_for_position(*trigger_anchor, cx)- else {+ let anchor = snapshot.buffer_snapshot().anchor_before(*trigger_anchor);+ let Some(buffer) = editor.buffer().read(cx).buffer_for_anchor(anchor, cx) else {return;};-- let Some((excerpt_id, _, _)) = editor- .buffer()- .read(cx)- .excerpt_containing(*trigger_anchor, cx)- else {- return;- };-+ let Anchor {+ excerpt_id,+ text_anchor,+ ..+ } = anchor;let same_kind = hovered_link_state.preferred_kind == preferred_kind|| hovered_link_state.links@@ -538,7 +531,7 @@ pub fn show_link_definition(async move {let result = match &trigger_point {TriggerPoint::Text(_) => {- if let Some((url_range, url)) = find_url(&buffer, buffer_position, cx.clone()) {+ if let Some((url_range, url)) = find_url(&buffer, text_anchor, cx.clone()) {this.read_with(cx, |_, _| {let range = maybe!({let start =@@ -550,7 +543,7 @@ pub fn show_link_definition(}).ok()} else if let Some((filename_range, filename)) =- find_file(&buffer, project.clone(), buffer_position, cx).await+ find_file(&buffer, project.clone(), text_anchor, cx).await{let range = maybe!({let start =@@ -562,7 +555,7 @@ pub fn show_link_definition(Some((range, vec![HoverLink::File(filename)]))} else if let Some(provider) = provider {let task = cx.update(|_, cx| {- provider.definitions(&buffer, buffer_position, preferred_kind, cx)+ provider.definitions(&buffer, text_anchor, preferred_kind, cx)})?;if let Some(task) = task {task.await.ok().flatten().map(|definition_result| {