Add debugging info when a symbol is not found (#15330)

Antonio Scandurra and Nathan created

Release Notes:

- N/A

Co-authored-by: Nathan <nathan@zed.dev>

Change summary

crates/assistant/src/context.rs | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

Detailed changes

crates/assistant/src/context.rs 🔗

@@ -532,7 +532,21 @@ impl EditOperation {
                     .path_candidates
                     .iter()
                     .find(|item| item.string == symbol)
-                    .context("symbol not found")?;
+                    .with_context(|| {
+                        format!(
+                            "symbol {:?} not found in path {:?}.\ncandidates: {:?}.\nparse status: {:?}. text:\n{}",
+                            symbol,
+                            path,
+                            outline
+                                .path_candidates
+                                .iter()
+                                .map(|candidate| &candidate.string)
+                                .collect::<Vec<_>>(),
+                            *parse_status.borrow(),
+                            buffer.read_with(&cx, |buffer, _| buffer.text()).unwrap_or_else(|_| "error".to_string())
+                        )
+                    })?;
+
                 buffer.update(&mut cx, |buffer, _| {
                     let outline_item = &outline.items[candidate.id];
                     let symbol_range = outline_item.range.to_point(buffer);