Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
janhrastnik authored and archseer committed Mar 16, 2021
1 parent d8599f3 commit d3ddc8d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
39 changes: 39 additions & 0 deletions helix-lsp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,4 +582,43 @@ impl Client {

Ok(response.unwrap_or_default())
}

pub async fn goto_definition(
&self,
text_document: lsp::TextDocumentIdentifier,
position: lsp::Position,
) -> anyhow::Result<Vec<lsp::Location>> {
let params = lsp::GotoDefinitionParams {
text_document_position_params: lsp::TextDocumentPositionParams {
text_document,
position,
},
work_done_progress_params: lsp::WorkDoneProgressParams {
work_done_token: None,
},
partial_result_params: lsp::PartialResultParams {
partial_result_token: None,
},
};

let response = self.request::<lsp::request::GotoDefinition>(params).await?;

let items = match response {
Some(lsp::GotoDefinitionResponse::Scalar(location)) => vec![location],
Some(lsp::GotoDefinitionResponse::Array(location_vec)) => location_vec,
Some(lsp::GotoDefinitionResponse::Link(location_link_vec)) => {
let mut location_vec: Vec<lsp::Location> = Vec::new();
location_link_vec.into_iter().for_each(|location_link| {
let link = lsp::Location {
uri: location_link.target_uri,
range: location_link.target_range,
};
location_vec.append(&mut link);
});
location_vec
}
};

Ok(items)
}
}
Empty file added helix-term/helix.log
Empty file.
2 changes: 2 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,8 @@ pub fn exit_select_mode(cx: &mut Context) {
cx.doc().mode = Mode::Normal;
}

pub fn goto_definition(cx: &mut Context) {}

// NOTE: Transactions in this module get appended to history when we switch back to normal mode.
pub mod insert {
use super::*;
Expand Down
8 changes: 6 additions & 2 deletions helix-term/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,12 @@ pub fn default() -> Keymaps {
code: KeyCode::Esc,
modifiers: Modifiers::NONE
} => commands::normal_mode as Command,
key!('g') => commands::move_file_start as Command,
key!('e') => commands::move_file_end as Command,
key!('g') => commands::move_file_start,
key!('e') => commands::move_file_end,
key!('d') => commands::goto_definition,
key!('t') => commands::goto_type_definition,
key!('r') => commands::goto_reference,
key!('i') => commands::goto_implementation,
),
)
}
1 change: 1 addition & 0 deletions helix-term/test2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
awdwadwadwa njvkrnvjre eahdwau kjvreng

0 comments on commit d3ddc8d

Please sign in to comment.