on master help sign in
term: Simplify goto code, address lints.
commitcf71625d4e879ef2e453a33b2eba41bc23174aa2 authorBlaž Hrastnik <blaz@mxxn.io> dateThu 11 Mar 2021, 13:15 (6 years ago) parent4240f75
1 file changed+11−14
helix-term/src/commands.rs+11−14
helix-term/src/commands.rs+11−14
@@ -13,7 +13,6 @@ use once_cell::sync::Lazy;
1313use crate::compositor::Compositor;
1414use crate::ui::{self, Popup, Prompt, PromptEvent};
1515
16−use lsp_types as lsp;
1716use std::path::PathBuf;
1817
1918use smol::Executor;
@@ -26,6 +25,8 @@ use helix_view::{
2625
2726use crossterm::event::{KeyCode, KeyEvent};
2827
28+use helix_lsp::lsp;
29+
2930pub struct Context<'a> {
3031 pub count: usize,
3132 pub editor: &'a mut Editor,
@@ -851,16 +852,16 @@ pub fn exit_select_mode(cx: &mut Context) {
851852 cx.doc().mode = Mode::Normal;
852853}
853854
854−pub fn goto_generic(cx: &mut Context, res: Vec<lsp::Location>) {
855+fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
855856 let doc = cx.doc();
856857
857858 doc.mode = Mode::Normal;
858859
859− log::info!("{:?}", res);
860+ log::info!("{:?}", locations);
860861 let filepath = doc.path().unwrap();
861862 log::info!("{:?}", filepath);
862863
863− match &res.as_slice() {
864+ match locations.as_slice() {
864865 [location] => {
865866 if filepath.to_str().unwrap() == location.uri.path() {
866867 let definition_pos = location.range.start;
@@ -874,10 +875,9 @@ pub fn goto_generic(cx: &mut Context, res: Vec<lsp::Location>) {
874875 }
875876 }
876877 [] => (), // maybe show user message that no definition was found?
877− _ => {
878− let snapshot = doc.state.clone();
878+ _locations => {
879879 let mut picker = ui::Picker::new(
880− res,
880+ locations,
881881 |item| {
882882 let file = item.uri.as_str();
883883 let line = item.range.start.line.to_string();
@@ -885,9 +885,6 @@ pub fn goto_generic(cx: &mut Context, res: Vec<lsp::Location>) {
885885 },
886886 move |editor: &mut Editor, item| {
887887 let doc = &mut editor.view_mut().doc;
888−
889− // revert state to what it was before the last update
890− doc.state = snapshot.clone();
891888 },
892889 );
893890 }
@@ -907,7 +904,7 @@ pub fn goto_definition(cx: &mut Context) {
907904 // TODO: handle fails
908905 let res =
909906 smol::block_on(language_server.goto_definition(doc.identifier(), pos)).unwrap_or_default();
910− goto_generic(cx, res);
907+ goto(cx, res);
911908}
912909
913910pub fn goto_type_definition(cx: &mut Context) {
@@ -923,7 +920,7 @@ pub fn goto_type_definition(cx: &mut Context) {
923920 // TODO: handle fails
924921 let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
925922 .unwrap_or_default();
926− goto_generic(cx, res);
923+ goto(cx, res);
927924}
928925
929926pub fn goto_implementation(cx: &mut Context) {
@@ -939,7 +936,7 @@ pub fn goto_implementation(cx: &mut Context) {
939936 // TODO: handle fails
940937 let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
941938 .unwrap_or_default();
942− goto_generic(cx, res);
939+ goto(cx, res);
943940}
944941
945942pub fn goto_reference(cx: &mut Context) {
@@ -955,7 +952,7 @@ pub fn goto_reference(cx: &mut Context) {
955952 // TODO: handle fails
956953 let res =
957954 smol::block_on(language_server.goto_reference(doc.identifier(), pos)).unwrap_or_default();
958− goto_generic(cx, res);
955+ goto(cx, res);
959956}
960957
961958// NOTE: Transactions in this module get appended to history when we switch back to normal mode.