call_hierarchy: Add gap between call hierarchy name and detail (#66144)

## Summary

Closes #64379

### 1: Space between signature and detail

Add `gap_1` in `render_match`.  

Before:
<img width="908" height="115" alt="Screenshot 2026-10-26 at 5 39 36 PM"
src="https://github.com/user-attachments/assets/f4d7d582-dd0c-459d-85c8-24744e463f10"
/>

after:
<img width="596" height="119" alt="Screenshot 2026-10-26 at 5 40 09 PM"
src="https://github.com/user-attachments/assets/9d863061-8246-40a0-b8f7-5660db91fdf6"
/>

### 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: 
<img width="1232" height="344" alt="image"
src="https://github.com/user-attachments/assets/a648054b-19eb-44d6-b465-315ccf14af44"
/>

Rust example:
<img width="733" height="142" alt="Screenshot 2026-10-26 at 11 59 51 PM"
src="https://github.com/user-attachments/assets/b854dd54-ce1f-4ef1-9849-bc6c5ae8413d"
/>

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 <kirill@zed.dev>
This commit is contained in:
Young Seo Kim
2026-11-03 21:30:48 +00:00
committed by GitHub
parent ce6c5413f1
commit b7a6e5cdc0
3 changed files with 158 additions and 14 deletions
+145 -14
View File
@@ -50,6 +50,7 @@ pub struct Call {
pub target: Location,
pub site_count: usize,
pub label: Option<Arc<CodeLabel>>,
pub label_includes_detail: bool,
pub display: CallDisplay,
}
@@ -60,6 +61,7 @@ pub struct CallDisplay {
pub path: Option<SharedString>,
pub full_signature: SharedString,
pub label_text: Option<SharedString>,
pub separate_detail: Option<SharedString>,
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<CodeLabel>, SharedString)>,
full_signature: SharedString,
separate_detail: Option<SharedString>,
path: Option<SharedString>,
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<Project>, 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<Project>, 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(),
}
}
@@ -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::<lsp::notification::DidOpenTextDocument, _>({
+12
View File
@@ -957,6 +957,8 @@ pub struct FakeLspAdapter {
+ Fn(&lsp::CompletionItem, &Arc<Language>) -> Option<CodeLabel>,
>,
>,
pub label_for_symbol:
Option<Box<dyn 'static + Send + Sync + Fn(&Symbol, &Arc<Language>) -> Option<CodeLabel>>>,
}
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<Language>,
) -> Option<CodeLabel> {
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)
}