|
|
@ -852,27 +852,21 @@ pub fn exit_select_mode(cx: &mut Context) {
|
|
|
|
cx.doc().mode = Mode::Normal;
|
|
|
|
cx.doc().mode = Mode::Normal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
|
|
|
|
fn goto(cx: &'static mut Context<'static>, locations: Vec<lsp::Location>) {
|
|
|
|
let doc = cx.doc();
|
|
|
|
let doc = cx.doc();
|
|
|
|
|
|
|
|
|
|
|
|
doc.mode = Mode::Normal;
|
|
|
|
doc.mode = Mode::Normal;
|
|
|
|
|
|
|
|
|
|
|
|
log::info!("{:?}", locations);
|
|
|
|
log::info!("{:?}", locations);
|
|
|
|
let filepath = doc.path().unwrap();
|
|
|
|
|
|
|
|
log::info!("{:?}", filepath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match locations.as_slice() {
|
|
|
|
match locations.as_slice() {
|
|
|
|
[location] => {
|
|
|
|
[location] => {
|
|
|
|
if filepath.to_str().unwrap() == location.uri.path() {
|
|
|
|
cx.editor
|
|
|
|
let definition_pos = location.range.start;
|
|
|
|
.open(PathBuf::from(location.uri.path()), cx.executor);
|
|
|
|
let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos);
|
|
|
|
let doc = cx.doc();
|
|
|
|
doc.set_selection(Selection::point(new_pos));
|
|
|
|
let definition_pos = location.range.start;
|
|
|
|
} else {
|
|
|
|
let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos);
|
|
|
|
// open new file
|
|
|
|
doc.set_selection(Selection::point(new_pos));
|
|
|
|
cx.editor
|
|
|
|
|
|
|
|
.open(PathBuf::from(location.uri.path()), cx.executor);
|
|
|
|
|
|
|
|
// TODO: go to position
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[] => (), // maybe show user message that no definition was found?
|
|
|
|
[] => (), // maybe show user message that no definition was found?
|
|
|
|
_locations => {
|
|
|
|
_locations => {
|
|
|
@ -884,14 +878,20 @@ fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
|
|
|
|
format!("{}:{}", file, line).into()
|
|
|
|
format!("{}:{}", file, line).into()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
move |editor: &mut Editor, item| {
|
|
|
|
move |editor: &mut Editor, item| {
|
|
|
|
let doc = &mut editor.view_mut().doc;
|
|
|
|
cx.editor.open(PathBuf::from(item.uri.path()), cx.executor);
|
|
|
|
|
|
|
|
let doc = cx.doc();
|
|
|
|
|
|
|
|
let definition_pos = item.range.start;
|
|
|
|
|
|
|
|
let new_pos =
|
|
|
|
|
|
|
|
helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos);
|
|
|
|
|
|
|
|
doc.set_selection(Selection::point(new_pos));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
cx.push_layer(Box::new(picker));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn goto_definition(cx: &mut Context) {
|
|
|
|
pub fn goto_definition(cx: &'static mut Context<'static>) {
|
|
|
|
let doc = cx.doc();
|
|
|
|
let doc = cx.doc();
|
|
|
|
let language_server = match doc.language_server.as_ref() {
|
|
|
|
let language_server = match doc.language_server.as_ref() {
|
|
|
|
Some(language_server) => language_server,
|
|
|
|
Some(language_server) => language_server,
|
|
|
@ -907,7 +907,7 @@ pub fn goto_definition(cx: &mut Context) {
|
|
|
|
goto(cx, res);
|
|
|
|
goto(cx, res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn goto_type_definition(cx: &mut Context) {
|
|
|
|
pub fn goto_type_definition(cx: &'static mut Context<'static>) {
|
|
|
|
let doc = cx.doc();
|
|
|
|
let doc = cx.doc();
|
|
|
|
let language_server = match doc.language_server.as_ref() {
|
|
|
|
let language_server = match doc.language_server.as_ref() {
|
|
|
|
Some(language_server) => language_server,
|
|
|
|
Some(language_server) => language_server,
|
|
|
@ -923,7 +923,7 @@ pub fn goto_type_definition(cx: &mut Context) {
|
|
|
|
goto(cx, res);
|
|
|
|
goto(cx, res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn goto_implementation(cx: &mut Context) {
|
|
|
|
pub fn goto_implementation(cx: &'static mut Context<'static>) {
|
|
|
|
let doc = cx.doc();
|
|
|
|
let doc = cx.doc();
|
|
|
|
let language_server = match doc.language_server.as_ref() {
|
|
|
|
let language_server = match doc.language_server.as_ref() {
|
|
|
|
Some(language_server) => language_server,
|
|
|
|
Some(language_server) => language_server,
|
|
|
@ -939,7 +939,7 @@ pub fn goto_implementation(cx: &mut Context) {
|
|
|
|
goto(cx, res);
|
|
|
|
goto(cx, res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn goto_reference(cx: &mut Context) {
|
|
|
|
pub fn goto_reference(cx: &'static mut Context<'static>) {
|
|
|
|
let doc = cx.doc();
|
|
|
|
let doc = cx.doc();
|
|
|
|
let language_server = match doc.language_server.as_ref() {
|
|
|
|
let language_server = match doc.language_server.as_ref() {
|
|
|
|
Some(language_server) => language_server,
|
|
|
|
Some(language_server) => language_server,
|
|
|
|