aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Hrastnik2021-02-21 22:22:38 +0000
committerBlaž Hrastnik2021-03-16 14:03:10 +0000
commitd3ddc8dea6844f836199196c44b08e63fdf837d0 (patch)
treec8708cb3a4cad12392fc70991253ddb77f1a8f7f
parentd8599f3a140eca7cd14f47e9b64f1ae9d829a0eb (diff)
wip
-rw-r--r--helix-lsp/src/client.rs39
-rw-r--r--helix-term/helix.log0
-rw-r--r--helix-term/src/commands.rs2
-rw-r--r--helix-term/src/keymap.rs8
-rw-r--r--helix-term/test2.txt1
5 files changed, 48 insertions, 2 deletions
diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs
index a9b7fe20..a747dc55 100644
--- a/helix-lsp/src/client.rs
+++ b/helix-lsp/src/client.rs
@@ -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)
+ }
}
diff --git a/helix-term/helix.log b/helix-term/helix.log
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/helix-term/helix.log
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 353d79cc..98e79b44 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -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::*;
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index 67490003..d9fe348f 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -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,
),
)
}
diff --git a/helix-term/test2.txt b/helix-term/test2.txt
new file mode 100644
index 00000000..aa674488
--- /dev/null
+++ b/helix-term/test2.txt
@@ -0,0 +1 @@
+awdwadwadwa njvkrnvjre eahdwau kjvreng