From cf71625d4e879ef2e453a33b2eba41bc23174aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Thu, 11 Mar 2021 13:15:25 +0900 Subject: [PATCH] term: Simplify goto code, address lints. --- helix-term/src/commands.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 87d7ea79..5a99d795 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -13,7 +13,6 @@ use once_cell::sync::Lazy; use crate::compositor::Compositor; use crate::ui::{self, Popup, Prompt, PromptEvent}; -use lsp_types as lsp; use std::path::PathBuf; use smol::Executor; @@ -26,6 +25,8 @@ use helix_view::{ use crossterm::event::{KeyCode, KeyEvent}; +use helix_lsp::lsp; + pub struct Context<'a> { pub count: usize, pub editor: &'a mut Editor, @@ -851,16 +852,16 @@ pub fn exit_select_mode(cx: &mut Context) { cx.doc().mode = Mode::Normal; } -pub fn goto_generic(cx: &mut Context, res: Vec) { +fn goto(cx: &mut Context, locations: Vec) { let doc = cx.doc(); doc.mode = Mode::Normal; - log::info!("{:?}", res); + log::info!("{:?}", locations); let filepath = doc.path().unwrap(); log::info!("{:?}", filepath); - match &res.as_slice() { + match locations.as_slice() { [location] => { if filepath.to_str().unwrap() == location.uri.path() { let definition_pos = location.range.start; @@ -874,10 +875,9 @@ pub fn goto_generic(cx: &mut Context, res: Vec) { } } [] => (), // maybe show user message that no definition was found? - _ => { - let snapshot = doc.state.clone(); + _locations => { let mut picker = ui::Picker::new( - res, + locations, |item| { let file = item.uri.as_str(); let line = item.range.start.line.to_string(); @@ -885,9 +885,6 @@ pub fn goto_generic(cx: &mut Context, res: Vec) { }, move |editor: &mut Editor, item| { let doc = &mut editor.view_mut().doc; - - // revert state to what it was before the last update - doc.state = snapshot.clone(); }, ); } @@ -907,7 +904,7 @@ pub fn goto_definition(cx: &mut Context) { // TODO: handle fails let res = smol::block_on(language_server.goto_definition(doc.identifier(), pos)).unwrap_or_default(); - goto_generic(cx, res); + goto(cx, res); } pub fn goto_type_definition(cx: &mut Context) { @@ -923,7 +920,7 @@ pub fn goto_type_definition(cx: &mut Context) { // TODO: handle fails let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos)) .unwrap_or_default(); - goto_generic(cx, res); + goto(cx, res); } pub fn goto_implementation(cx: &mut Context) { @@ -939,7 +936,7 @@ pub fn goto_implementation(cx: &mut Context) { // TODO: handle fails let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos)) .unwrap_or_default(); - goto_generic(cx, res); + goto(cx, res); } pub fn goto_reference(cx: &mut Context) { @@ -955,7 +952,7 @@ pub fn goto_reference(cx: &mut Context) { // TODO: handle fails let res = smol::block_on(language_server.goto_reference(doc.identifier(), pos)).unwrap_or_default(); - goto_generic(cx, res); + goto(cx, res); } // NOTE: Transactions in this module get appended to history when we switch back to normal mode.