@@ -35,6 +35,32 @@ fn location_to_file_location(location: &lsp::Location) -> FileLocation {
3535 (path, line)
3636}
3737
38+// TODO: share with symbol picker(symbol.location)
39+// TODO: need to use push_jump() before?
40+fn jump_to_location(
41+ editor: &mut Editor,
42+ location: &lsp::Location,
43+ offset_encoding: OffsetEncoding,
44+ action: Action,
45+) {
46+ let path = location
47+ .uri
48+ .to_file_path()
49+ .expect("unable to convert URI to filepath");
50+ let _id = editor.open(path, action).expect("editor.open failed");
51+ let (view, doc) = current!(editor);
52+ let definition_pos = location.range.start;
53+ // TODO: convert inside server
54+ let new_pos = if let Some(new_pos) = lsp_pos_to_pos(doc.text(), definition_pos, offset_encoding)
55+ {
56+ new_pos
57+ } else {
58+ return;
59+ };
60+ doc.set_selection(view.id, Selection::point(new_pos));
61+ align_view(doc, view, Align::Center);
62+}
63+
3864fn sym_picker(
3965 symbols: Vec<lsp::SymbolInformation>,
4066 current_path: Option<lsp::Url>,
@@ -407,36 +433,11 @@ fn goto_impl(
407433) {
408434 push_jump(editor);
409435
410− // TODO: share with symbol picker(symbol.location)
411− fn jump_to(
412− editor: &mut Editor,
413− location: &lsp::Location,
414− offset_encoding: OffsetEncoding,
415− action: Action,
416− ) {
417− let path = location
418− .uri
419− .to_file_path()
420− .expect("unable to convert URI to filepath");
421− let _id = editor.open(path, action).expect("editor.open failed");
422− let (view, doc) = current!(editor);
423− let definition_pos = location.range.start;
424− // TODO: convert inside server
425− let new_pos =
426− if let Some(new_pos) = lsp_pos_to_pos(doc.text(), definition_pos, offset_encoding) {
427− new_pos
428− } else {
429− return;
430− };
431− doc.set_selection(view.id, Selection::point(new_pos));
432− align_view(doc, view, Align::Center);
433− }
434−
435436 let cwdir = std::env::current_dir().expect("couldn't determine current directory");
436437
437438 match locations.as_slice() {
438439 [location] => {
439− jump_to(editor, location, offset_encoding, Action::Replace);
440+ jump_to_location(editor, location, offset_encoding, Action::Replace);
440441 }
441442 [] => {
442443 editor.set_error("No definition found.");
@@ -464,7 +465,9 @@ fn goto_impl(
464465 let line = location.range.start.line;
465466 format!("{}:{}", file, line).into()
466467 },
467− move |cx, location, action| jump_to(cx.editor, location, offset_encoding, action),
468+ move |cx, location, action| {
469+ jump_to_location(cx.editor, location, offset_encoding, action)
470+ },
468471 move |_editor, location| Some(location_to_file_location(location)),
469472 );
470473 compositor.push(Box::new(overlayed(picker)));