mirror of https://github.com/helix-editor/helix
term: Simplify goto code, address lints.
parent
4240f757c0
commit
cf71625d4e
|
@ -13,7 +13,6 @@ use once_cell::sync::Lazy;
|
||||||
use crate::compositor::Compositor;
|
use crate::compositor::Compositor;
|
||||||
use crate::ui::{self, Popup, Prompt, PromptEvent};
|
use crate::ui::{self, Popup, Prompt, PromptEvent};
|
||||||
|
|
||||||
use lsp_types as lsp;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use smol::Executor;
|
use smol::Executor;
|
||||||
|
@ -26,6 +25,8 @@ use helix_view::{
|
||||||
|
|
||||||
use crossterm::event::{KeyCode, KeyEvent};
|
use crossterm::event::{KeyCode, KeyEvent};
|
||||||
|
|
||||||
|
use helix_lsp::lsp;
|
||||||
|
|
||||||
pub struct Context<'a> {
|
pub struct Context<'a> {
|
||||||
pub count: usize,
|
pub count: usize,
|
||||||
pub editor: &'a mut Editor,
|
pub editor: &'a mut Editor,
|
||||||
|
@ -851,16 +852,16 @@ pub fn exit_select_mode(cx: &mut Context) {
|
||||||
cx.doc().mode = Mode::Normal;
|
cx.doc().mode = Mode::Normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn goto_generic(cx: &mut Context, res: Vec<lsp::Location>) {
|
fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
|
||||||
let doc = cx.doc();
|
let doc = cx.doc();
|
||||||
|
|
||||||
doc.mode = Mode::Normal;
|
doc.mode = Mode::Normal;
|
||||||
|
|
||||||
log::info!("{:?}", res);
|
log::info!("{:?}", locations);
|
||||||
let filepath = doc.path().unwrap();
|
let filepath = doc.path().unwrap();
|
||||||
log::info!("{:?}", filepath);
|
log::info!("{:?}", filepath);
|
||||||
|
|
||||||
match &res.as_slice() {
|
match locations.as_slice() {
|
||||||
[location] => {
|
[location] => {
|
||||||
if filepath.to_str().unwrap() == location.uri.path() {
|
if filepath.to_str().unwrap() == location.uri.path() {
|
||||||
let definition_pos = location.range.start;
|
let definition_pos = location.range.start;
|
||||||
|
@ -874,10 +875,9 @@ pub fn goto_generic(cx: &mut Context, res: Vec<lsp::Location>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[] => (), // maybe show user message that no definition was found?
|
[] => (), // maybe show user message that no definition was found?
|
||||||
_ => {
|
_locations => {
|
||||||
let snapshot = doc.state.clone();
|
|
||||||
let mut picker = ui::Picker::new(
|
let mut picker = ui::Picker::new(
|
||||||
res,
|
locations,
|
||||||
|item| {
|
|item| {
|
||||||
let file = item.uri.as_str();
|
let file = item.uri.as_str();
|
||||||
let line = item.range.start.line.to_string();
|
let line = item.range.start.line.to_string();
|
||||||
|
@ -885,9 +885,6 @@ pub fn goto_generic(cx: &mut Context, res: Vec<lsp::Location>) {
|
||||||
},
|
},
|
||||||
move |editor: &mut Editor, item| {
|
move |editor: &mut Editor, item| {
|
||||||
let doc = &mut editor.view_mut().doc;
|
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
|
// TODO: handle fails
|
||||||
let res =
|
let res =
|
||||||
smol::block_on(language_server.goto_definition(doc.identifier(), pos)).unwrap_or_default();
|
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) {
|
pub fn goto_type_definition(cx: &mut Context) {
|
||||||
|
@ -923,7 +920,7 @@ pub fn goto_type_definition(cx: &mut Context) {
|
||||||
// TODO: handle fails
|
// TODO: handle fails
|
||||||
let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
|
let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
goto_generic(cx, res);
|
goto(cx, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn goto_implementation(cx: &mut Context) {
|
pub fn goto_implementation(cx: &mut Context) {
|
||||||
|
@ -939,7 +936,7 @@ pub fn goto_implementation(cx: &mut Context) {
|
||||||
// TODO: handle fails
|
// TODO: handle fails
|
||||||
let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
|
let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
goto_generic(cx, res);
|
goto(cx, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn goto_reference(cx: &mut Context) {
|
pub fn goto_reference(cx: &mut Context) {
|
||||||
|
@ -955,7 +952,7 @@ pub fn goto_reference(cx: &mut Context) {
|
||||||
// TODO: handle fails
|
// TODO: handle fails
|
||||||
let res =
|
let res =
|
||||||
smol::block_on(language_server.goto_reference(doc.identifier(), pos)).unwrap_or_default();
|
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.
|
// NOTE: Transactions in this module get appended to history when we switch back to normal mode.
|
||||||
|
|
Loading…
Reference in New Issue