From b7a6e5cdc013c5518cfb0a119b2aa457c538f020 Mon Sep 17 00:00:00 2001
From: Young Seo Kim <99856437+yskim308@users.noreply.github.com>
Date: Tue, 3 Nov 2026 21:30:48 +0000
Subject: [PATCH] call_hierarchy: Add gap between call hierarchy name and
detail (#66144)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
## Summary
Closes #64379
### 1: Space between signature and detail
Add `gap_1` in `render_match`.
Before:
after:
### 2: Showing detail in tooltip + bug where tooltip would not show
needs_tooltip was computed from the width of the label text alone (e.g.
func helper), ignoring the separate detail (the package path). So even
when the rendered row (func helper path/to/go/repo/package) was wider
than the modal, the tooltip was never attached.
Fixes:
- Width measurement: when the label doesn’t already contain the detail,
measure label + detail instead of just the label.
- Tooltip content: pass the detail into CallSignatureTooltip and render
it when the label doesn’t already contain it. Complete signature labels
(e.g. Rust’s fn helper(&self) -> i32) already include the detail, so it
isn’t appended twice.
Go example:
Rust example:
Tooltip now correctly shows on hover and includes detail while not
duplicating in the case the label already has it.
## Testing
all tests in `call_hierarchy` pass and I've added two tests:
- Added a regression test that the tooltip appends the separate detail
for name-only labels (e.g. Go package paths).
- Added a regression test that a complete signature label (e.g. Rust)
does not get its detail appended twice.
## Self-review
- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [x] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [x] Tests cover the new or changed behavior.
Release Notes:
- Improved call hierarchy item details: added spacing between the name
and detail, and fixed the hover tooltip to show the full detail
(including package paths) when the row is truncated
---------
Co-authored-by: Kirill Bulatov
---
crates/call_hierarchy/src/call_hierarchy.rs | 159 ++++++++++++++++--
.../src/fake_definition_lsp.rs | 1 +
crates/language/src/language.rs | 12 ++
3 files changed, 158 insertions(+), 14 deletions(-)
diff --git a/crates/call_hierarchy/src/call_hierarchy.rs b/crates/call_hierarchy/src/call_hierarchy.rs
index f635acc9e42..4b0a8ebeead 100644
--- a/crates/call_hierarchy/src/call_hierarchy.rs
+++ b/crates/call_hierarchy/src/call_hierarchy.rs
@@ -50,6 +50,7 @@ pub struct Call {
pub target: Location,
pub site_count: usize,
pub label: Option>,
+ pub label_includes_detail: bool,
pub display: CallDisplay,
}
@@ -60,6 +61,7 @@ pub struct CallDisplay {
pub path: Option,
pub full_signature: SharedString,
pub label_text: Option,
+ pub separate_detail: Option,
pub needs_tooltip: bool,
}
@@ -127,6 +129,7 @@ pub async fn fetch_calls(
target,
site_count,
label: None,
+ label_includes_detail: false,
display: CallDisplay::default(),
}
})
@@ -762,6 +765,7 @@ impl PickerDelegate for CallHierarchyDelegate {
let tooltip_max_width = self.modal_width;
let full_signature = call.display.full_signature.clone();
let full_path = call.display.path.clone();
+ let separate_detail = call.display.separate_detail.clone();
Some(
ListItem::new(ix)
@@ -773,6 +777,7 @@ impl PickerDelegate for CallHierarchyDelegate {
.text_ui(cx)
.child(
h_flex()
+ .gap_1()
.overflow_x_hidden()
.text_size(ThemeSettings::get_global(cx).buffer_font_size(cx))
.child(name_styled)
@@ -790,6 +795,7 @@ impl PickerDelegate for CallHierarchyDelegate {
AnyView::from(cx.new(|_| CallSignatureTooltip {
label: tooltip_label.clone(),
full_signature: full_signature.clone(),
+ separate_detail: separate_detail.clone(),
path: full_path.clone(),
max_width: tooltip_max_width,
}))
@@ -802,6 +808,7 @@ impl PickerDelegate for CallHierarchyDelegate {
struct CallSignatureTooltip {
label: Option<(Arc, SharedString)>,
full_signature: SharedString,
+ separate_detail: Option,
path: Option,
max_width: Pixels,
}
@@ -811,8 +818,9 @@ impl Render for CallSignatureTooltip {
let mut signature_style = buffer_text_style(cx);
signature_style.line_height =
relative(ThemeSettings::get_global(cx).buffer_line_height.value());
+ let separate_detail = self.separate_detail.clone();
let signature = match &self.label {
- Some((label, label_text)) => StyledText::new(label_text.clone())
+ Some((label, label_text)) => StyledText::new(label_text)
.with_default_highlights(
&signature_style,
cx.theme().syntax().resolve_runs(&label.runs),
@@ -823,10 +831,26 @@ impl Render for CallSignatureTooltip {
let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size(cx);
let max_width = self.max_width;
let path = self.path.clone();
+ let detail_styled = separate_detail.map(|detail| {
+ let mut detail_style = signature_style.clone();
+ detail_style.color = cx.theme().colors().text_muted;
+ StyledText::new(detail).with_default_highlights(&detail_style, std::iter::empty())
+ });
+
tooltip_container(cx, move |el, _| {
el.max_w(max_width)
.gap_0p5()
- .child(div().text_size(buffer_font_size).child(signature))
+ .child(
+ h_flex()
+ .gap_1()
+ .flex_wrap()
+ .text_size(buffer_font_size)
+ .child(div().min_w_0().max_w(max_width).child(signature))
+ .children(
+ detail_styled
+ .map(|detail| div().min_w_0().max_w(max_width).child(detail)),
+ ),
+ )
.children(
path.map(|path| Label::new(path).size(LabelSize::Small).color(Color::Muted)),
)
@@ -883,6 +907,7 @@ async fn attach_labels(calls: &mut [Call], project: &Entity, cx: &mut A
};
if let Some(label) = signature_label(&call.item, &language) {
call.label = Some(Arc::new(label));
+ call.label_includes_detail = true;
continue;
}
match fallback_groups
@@ -921,6 +946,9 @@ async fn attach_labels(calls: &mut [Call], project: &Entity, cx: &mut A
continue;
};
for (index, label) in indices.into_iter().zip(labels) {
+ calls[index].label_includes_detail = label
+ .as_ref()
+ .is_some_and(|label| detail_from_label_suffix(label).is_some());
calls[index].label = label.map(Arc::new);
}
}
@@ -948,17 +976,40 @@ async fn load_and_apply_calls(
let buffer_font_size = settings.buffer_font_size(cx);
let path_font_size = TextSize::Small.rems(cx).to_pixels(window.rem_size());
for call in calls.iter_mut() {
- let signature = call
+ let name_text = call
.display
.label_text
- .clone()
- .unwrap_or_else(|| call.display.full_signature.clone());
- let signature_width = shaped_width(
- signature,
+ .as_ref()
+ .unwrap_or(&call.display.name);
+ let detail_text = if call.label_includes_detail {
+ None
+ } else {
+ call.display.detail.as_ref()
+ };
+
+ let gap = rems(0.25).to_pixels(window.rem_size());
+ let name_width = shaped_width(
+ name_text.clone(),
settings.buffer_font.clone(),
buffer_font_size,
window,
- );
+ )
+ .ceil();
+ let detail_width = match detail_text {
+ Some(detail) => {
+ shaped_width(
+ detail.clone(),
+ settings.buffer_font.clone(),
+ buffer_font_size,
+ window,
+ )
+ .ceil()
+ + gap
+ }
+ None => px(0.),
+ };
+ let signature_width = name_width + detail_width;
+
let path_width = call
.display
.path
@@ -1111,13 +1162,18 @@ fn compute_call_display(call: &Call, cx: &App) -> CallDisplay {
let detail = extract_call_detail(call).map(SharedString::from);
let full_signature = SharedString::from(match &detail {
- Some(detail) => format!("{}{detail}", call.item.name),
+ Some(detail) => format!("{} {detail}", call.item.name),
None => call.item.name.clone(),
});
let label_text = call
.label
.as_ref()
.map(|label| SharedString::from(label.text.clone()));
+ let separate_detail = if label_text.is_some() && !call.label_includes_detail {
+ detail.clone()
+ } else {
+ None
+ };
CallDisplay {
name: SharedString::from(call.item.name.clone()),
@@ -1125,6 +1181,7 @@ fn compute_call_display(call: &Call, cx: &App) -> CallDisplay {
path,
full_signature,
label_text,
+ separate_detail,
needs_tooltip: false,
}
}
@@ -1194,11 +1251,7 @@ fn render_item(
..HighlightStyle::default()
};
- let label_carries_detail = call_item
- .label
- .as_ref()
- .is_some_and(|label| detail_from_label_suffix(label).is_some());
- let detail_styled = if label_carries_detail {
+ let detail_styled = if call_item.label_includes_detail {
None
} else {
call_item.display.detail.clone().map(|detail| {
@@ -1545,6 +1598,83 @@ mod tests {
);
}
+ #[gpui::test]
+ async fn test_tooltip_appends_detail_only_when_label_lacks_it(cx: &mut TestAppContext) {
+ init_test(cx);
+
+ let fs = FakeFs::new(cx.executor());
+ fs.insert_tree(path!("/test"), json!({"src": {"main.rs": source()}}))
+ .await;
+ let project = Project::test(fs, [path!("/test").as_ref()], cx).await;
+ let _fake_servers = project.read_with(cx, |project, _| {
+ project.languages().add(rust_lang());
+ project.languages().register_fake_lsp(
+ "Rust",
+ FakeLspAdapter {
+ label_for_symbol: Some(Box::new(|symbol, _| {
+ let (text, filter_range) = match symbol.name.as_str() {
+ "helper" => ("func helper", 5..11),
+ "Foo" => ("type Foo struct {}", 5..8),
+ _ => return None,
+ };
+ Some(CodeLabel::new(text.to_string(), filter_range, Vec::new()))
+ })),
+ ..FakeLspAdapter::default()
+ },
+ )
+ });
+ let mut window_cx = cx
+ .add_empty_window()
+ .update(|window, cx| window.to_async(cx));
+
+ let cases = [
+ (
+ "helper",
+ "github.com/foo/bar",
+ "func helper",
+ Some("github.com/foo/bar"),
+ ),
+ ("Foo", "pkg/path", "type Foo struct {}", None),
+ (
+ "helper",
+ "fn helper(&self) -> i32",
+ "fn helper(&self) -> i32",
+ None,
+ ),
+ ("Widget", "ns::Widget", "ns::Widget", None),
+ ];
+ let mut calls = Vec::new();
+ for (name, detail, _, _) in cases {
+ calls.push(
+ make_call(
+ name,
+ path!("/test/src/main.rs").as_ref(),
+ 5,
+ Some(detail.to_string()),
+ &project,
+ cx,
+ )
+ .await,
+ );
+ }
+
+ attach_labels(&mut calls, &project, &mut window_cx).await;
+
+ for (call, (name, detail, expected_label, expected_detail)) in calls.iter().zip(cases) {
+ let display = cx.update(|cx| compute_call_display(call, cx));
+ assert_eq!(
+ display.label_text.as_deref(),
+ Some(expected_label),
+ "case: name={name}, detail={detail}"
+ );
+ assert_eq!(
+ display.separate_detail.as_deref(),
+ expected_detail,
+ "case: name={name}, detail={detail}"
+ );
+ }
+ }
+
#[test]
fn test_find_symbol_name() {
assert_eq!(find_symbol_name("fn f()", "f"), Some(3));
@@ -2468,6 +2598,7 @@ mod tests {
target,
site_count: 1,
label: None,
+ label_includes_detail: false,
display: CallDisplay::default(),
}
}
diff --git a/crates/edit_prediction_context/src/fake_definition_lsp.rs b/crates/edit_prediction_context/src/fake_definition_lsp.rs
index 02c50ab8eaf..4792c09f636 100644
--- a/crates/edit_prediction_context/src/fake_definition_lsp.rs
+++ b/crates/edit_prediction_context/src/fake_definition_lsp.rs
@@ -44,6 +44,7 @@ pub fn register_fake_definition_server(
..Default::default()
},
label_for_completion: None,
+ label_for_symbol: None,
initializer: Some(Box::new({
move |server| {
server.handle_notification::({
diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs
index 720a087c9ac..2daca9b9cf7 100644
--- a/crates/language/src/language.rs
+++ b/crates/language/src/language.rs
@@ -957,6 +957,8 @@ pub struct FakeLspAdapter {
+ Fn(&lsp::CompletionItem, &Arc) -> Option,
>,
>,
+ pub label_for_symbol:
+ Option) -> Option>>,
}
pub struct Language {
@@ -1636,6 +1638,7 @@ impl Default for FakeLspAdapter {
},
opt_in_languages: HashSet::default(),
label_for_completion: None,
+ label_for_symbol: None,
}
}
}
@@ -1737,6 +1740,15 @@ impl LspAdapter for FakeLspAdapter {
label_for_completion(item, language)
}
+ async fn label_for_symbol(
+ &self,
+ symbol: &Symbol,
+ language: &Arc,
+ ) -> Option {
+ let label_for_symbol = self.label_for_symbol.as_ref()?;
+ label_for_symbol(symbol, language)
+ }
+
fn is_opt_in_for(&self, language: &LanguageName) -> bool {
self.opt_in_languages.contains(language)
}