@@ -237,6 +237,7 @@ impl Command {
237237 code_action, "Perform code action",
238238 buffer_picker, "Open buffer picker",
239239 symbol_picker, "Open symbol picker",
240+ workspace_symbol_picker, "Open workspace symbol picker",
240241 last_picker, "Open last picker",
241242 prepend_to_line, "Insert at start of line",
242243 append_to_line, "Insert at end of line",
@@ -2723,7 +2724,7 @@ fn symbol_picker(cx: &mut Context) {
27232724 }
27242725 };
27252726
2726− let picker = FilePicker::new(
2727+ let mut picker = FilePicker::new(
27272728 symbols,
27282729 |symbol| (&symbol.name).into(),
27292730 move |editor: &mut Editor, symbol, _action| {
@@ -2748,6 +2749,69 @@ fn symbol_picker(cx: &mut Context) {
27482749 Some((path, line))
27492750 },
27502751 );
2752+ picker.truncate_start = false;
2753+ compositor.push(Box::new(picker))
2754+ }
2755+ },
2756+ )
2757+}
2758+
2759+fn workspace_symbol_picker(cx: &mut Context) {
2760+ let (_, doc) = current!(cx.editor);
2761+
2762+ let language_server = match doc.language_server() {
2763+ Some(language_server) => language_server,
2764+ None => return,
2765+ };
2766+ let offset_encoding = language_server.offset_encoding();
2767+
2768+ let future = language_server.workspace_symbols("".to_string());
2769+
2770+ let current_path = doc_mut!(cx.editor).path().cloned();
2771+ cx.callback(
2772+ future,
2773+ move |_editor: &mut Editor,
2774+ compositor: &mut Compositor,
2775+ response: Option<Vec<lsp::SymbolInformation>>| {
2776+ if let Some(symbols) = response {
2777+ let mut picker = FilePicker::new(
2778+ symbols,
2779+ move |symbol| {
2780+ let path = symbol.location.uri.to_file_path().unwrap();
2781+ if current_path.as_ref().map(|p| p == &path).unwrap_or(false) {
2782+ (&symbol.name).into()
2783+ } else {
2784+ let relative_path = helix_core::path::get_relative_path(path.as_path())
2785+ .to_str()
2786+ .unwrap()
2787+ .to_owned();
2788+ format!("{} ({})", &symbol.name, relative_path).into()
2789+ }
2790+ },
2791+ move |editor: &mut Editor, symbol, action| {
2792+ let path = symbol.location.uri.to_file_path().unwrap();
2793+ editor.open(path, action).expect("editor.open failed");
2794+ let (view, doc) = current!(editor);
2795+
2796+ if let Some(range) =
2797+ lsp_range_to_range(doc.text(), symbol.location.range, offset_encoding)
2798+ {
2799+ // we flip the range so that the cursor sits on the start of the symbol
2800+ // (for example start of the function).
2801+ doc.set_selection(view.id, Selection::single(range.head, range.anchor));
2802+ align_view(doc, view, Align::Center);
2803+ }
2804+ },
2805+ move |_editor, symbol| {
2806+ let path = symbol.location.uri.to_file_path().unwrap();
2807+ let line = Some((
2808+ symbol.location.range.start.line as usize,
2809+ symbol.location.range.end.line as usize,
2810+ ));
2811+ Some((path, line))
2812+ },
2813+ );
2814+ picker.truncate_start = false;
27512815 compositor.push(Box::new(picker))
27522816 }
27532817 },