@@ -3474,6 +3474,58 @@ fn buffer_picker(cx: &mut Context) {
34743474 cx.push_layer(Box::new(overlayed(picker)));
34753475}
34763476
3477+fn sym_picker(
3478+ symbols: Vec<lsp::SymbolInformation>,
3479+ current_path: Option<lsp::Url>,
3480+ offset_encoding: OffsetEncoding,
3481+) -> FilePicker<lsp::SymbolInformation> {
3482+ // TODO: drop current_path comparison and instead use workspace: bool flag?
3483+ let current_path2 = current_path.clone();
3484+ let mut picker = FilePicker::new(
3485+ symbols,
3486+ move |symbol| {
3487+ if current_path.as_ref() == Some(&symbol.location.uri) {
3488+ symbol.name.as_str().into()
3489+ } else {
3490+ let path = symbol.location.uri.to_file_path().unwrap();
3491+ let relative_path = helix_core::path::get_relative_path(path.as_path())
3492+ .to_string_lossy()
3493+ .into_owned();
3494+ format!("{} ({})", &symbol.name, relative_path).into()
3495+ }
3496+ },
3497+ move |cx, symbol, action| {
3498+ if current_path2.as_ref() == Some(&symbol.location.uri) {
3499+ push_jump(cx.editor);
3500+ } else {
3501+ let path = symbol.location.uri.to_file_path().unwrap();
3502+ cx.editor.open(path, action).expect("editor.open failed");
3503+ }
3504+
3505+ let (view, doc) = current!(cx.editor);
3506+
3507+ if let Some(range) =
3508+ lsp_range_to_range(doc.text(), symbol.location.range, offset_encoding)
3509+ {
3510+ // we flip the range so that the cursor sits on the start of the symbol
3511+ // (for example start of the function).
3512+ doc.set_selection(view.id, Selection::single(range.head, range.anchor));
3513+ align_view(doc, view, Align::Center);
3514+ }
3515+ },
3516+ move |_editor, symbol| {
3517+ let path = symbol.location.uri.to_file_path().unwrap();
3518+ let line = Some((
3519+ symbol.location.range.start.line as usize,
3520+ symbol.location.range.end.line as usize,
3521+ ));
3522+ Some((path, line))
3523+ },
3524+ );
3525+ picker.truncate_start = false;
3526+ picker
3527+}
3528+
34773529fn symbol_picker(cx: &mut Context) {
34783530 fn nested_to_flat(
34793531 list: &mut Vec<lsp::SymbolInformation>,
@@ -3499,6 +3551,7 @@ fn symbol_picker(cx: &mut Context) {
34993551 Some(language_server) => language_server,
35003552 None => return,
35013553 };
3554+ let current_url = doc.url();
35023555 let offset_encoding = language_server.offset_encoding();
35033556
35043557 let future = language_server.document_symbols(doc.identifier());
@@ -3523,32 +3576,7 @@ fn symbol_picker(cx: &mut Context) {
35233576 }
35243577 };
35253578
3526− let mut picker = FilePicker::new(
3527− symbols,
3528− |symbol| (&symbol.name).into(),
3529− move |cx, symbol, _action| {
3530− push_jump(cx.editor);
3531− let (view, doc) = current!(cx.editor);
3532−
3533− if let Some(range) =
3534− lsp_range_to_range(doc.text(), symbol.location.range, offset_encoding)
3535− {
3536− // we flip the range so that the cursor sits on the start of the symbol
3537− // (for example start of the function).
3538− doc.set_selection(view.id, Selection::single(range.head, range.anchor));
3539− align_view(doc, view, Align::Center);
3540− }
3541− },
3542− move |_editor, symbol| {
3543− let path = symbol.location.uri.to_file_path().unwrap();
3544− let line = Some((
3545− symbol.location.range.start.line as usize,
3546− symbol.location.range.end.line as usize,
3547− ));
3548− Some((path, line))
3549− },
3550− );
3551− picker.truncate_start = false;
3579+ let picker = sym_picker(symbols, current_url, offset_encoding);
35523580 compositor.push(Box::new(overlayed(picker)))
35533581 }
35543582 },
@@ -3557,7 +3585,7 @@ fn symbol_picker(cx: &mut Context) {
35573585
35583586fn workspace_symbol_picker(cx: &mut Context) {
35593587 let doc = doc!(cx.editor);
3560− let current_path = doc.path().cloned();
3588+ let current_url = doc.url();
35613589 let language_server = match doc.language_server() {
35623590 Some(language_server) => language_server,
35633591 None => return,
@@ -3571,43 +3599,7 @@ fn workspace_symbol_picker(cx: &mut Context) {
35713599 compositor: &mut Compositor,
35723600 response: Option<Vec<lsp::SymbolInformation>>| {
35733601 if let Some(symbols) = response {
3574− let mut picker = FilePicker::new(
3575− symbols,
3576− move |symbol| {
3577− let path = symbol.location.uri.to_file_path().unwrap();
3578− if current_path.as_ref().map(|p| p == &path).unwrap_or(false) {
3579− (&symbol.name).into()
3580− } else {
3581− let relative_path = helix_core::path::get_relative_path(path.as_path())
3582− .to_string_lossy()
3583− .into_owned();
3584− format!("{} ({})", &symbol.name, relative_path).into()
3585− }
3586− },
3587− move |cx, symbol, action| {
3588− let path = symbol.location.uri.to_file_path().unwrap();
3589− cx.editor.open(path, action).expect("editor.open failed");
3590− let (view, doc) = current!(cx.editor);
3591−
3592− if let Some(range) =
3593− lsp_range_to_range(doc.text(), symbol.location.range, offset_encoding)
3594− {
3595− // we flip the range so that the cursor sits on the start of the symbol
3596− // (for example start of the function).
3597− doc.set_selection(view.id, Selection::single(range.head, range.anchor));
3598− align_view(doc, view, Align::Center);
3599− }
3600− },
3601− move |_editor, symbol| {
3602− let path = symbol.location.uri.to_file_path().unwrap();
3603− let line = Some((
3604− symbol.location.range.start.line as usize,
3605− symbol.location.range.end.line as usize,
3606− ));
3607− Some((path, line))
3608− },
3609− );
3610− picker.truncate_start = false;
3602+ let picker = sym_picker(symbols, current_url, offset_encoding);
36113603 compositor.push(Box::new(overlayed(picker)))
36123604 }
36133605 },
@@ -4266,6 +4258,7 @@ fn goto_impl(
42664258) {
42674259 push_jump(editor);
42684260
4261+ // TODO: share with symbol picker(symbol.location)
42694262 fn jump_to(
42704263 editor: &mut Editor,
42714264 location: &lsp::Location,
@@ -4324,6 +4317,7 @@ fn goto_impl(
43244317 },
43254318 move |cx, location, action| jump_to(cx.editor, location, offset_encoding, action),
43264319 |_editor, location| {
4320+ // TODO: share code for symbol.location and location
43274321 let path = location.uri.to_file_path().unwrap();
43284322 let line = Some((
43294323 location.range.start.line as usize,