@@ -253,17 +253,22 @@ impl ContextPickerCompletionProvider {
) -> Option<Completion> {
let project = workspace.read(cx).project().clone();
- let label = CodeLabel::plain(symbol.name.clone(), None);
-
- let abs_path = match &symbol.path {
- SymbolLocation::InProject(project_path) => {
- project.read(cx).absolute_path(&project_path, cx)?
- }
+ let (abs_path, file_name) = match &symbol.path {
+ SymbolLocation::InProject(project_path) => (
+ project.read(cx).absolute_path(&project_path, cx)?,
+ project_path.path.file_name()?.to_string().into(),
+ ),
SymbolLocation::OutsideProject {
abs_path,
signature: _,
- } => PathBuf::from(abs_path.as_ref()),
+ } => (
+ PathBuf::from(abs_path.as_ref()),
+ abs_path.file_name().map(|f| f.to_string_lossy())?,
+ ),
};
+
+ let label = build_symbol_label(&symbol.name, &file_name, symbol.range.start.0.row + 1, cx);
+
let uri = MentionUri::Symbol {
abs_path,
name: symbol.name.clone(),
@@ -674,6 +679,17 @@ impl ContextPickerCompletionProvider {
}
}
+fn build_symbol_label(symbol_name: &str, file_name: &str, line: u32, cx: &App) -> CodeLabel {
+ let comment_id = cx.theme().syntax().highlight_id("comment").map(HighlightId);
+ let mut label = CodeLabelBuilder::default();
+
+ label.push_str(symbol_name, None);
+ label.push_str(" ", None);
+ label.push_str(&format!("{} L{}", file_name, line), comment_id);
+
+ label.build()
+}
+
fn build_code_label_for_full_path(file_name: &str, directory: Option<&str>, cx: &App) -> CodeLabel {
let comment_id = cx.theme().syntax().highlight_id("comment").map(HighlightId);
let mut label = CodeLabelBuilder::default();
@@ -2473,7 +2473,7 @@ mod tests {
format!("Lorem [@one.txt]({url_one}) Ipsum [@eight.txt]({url_eight}) @symbol ")
);
assert!(editor.has_visible_completions_menu());
- assert_eq!(current_completion_labels(editor), &["MySymbol"]);
+ assert_eq!(current_completion_labels(editor), &["MySymbol one.txt L1"]);
});
editor.update_in(&mut cx, |editor, window, cx| {