aboutsummaryrefslogtreecommitdiff
path: root/helix-lsp/src/client.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-16 14:09:04 +0000
committerGitHub2021-03-16 14:09:04 +0000
commit8dc0b18e35cdfdd76f435dcd43c1cfd5a3f0c7f7 (patch)
treea26c6025d45658b4d85d6917ea82489d6ba8fb2e /helix-lsp/src/client.rs
parentd8599f3a140eca7cd14f47e9b64f1ae9d829a0eb (diff)
parente3ec5e31ec005e33da4c848b4272e81a6d21a5f0 (diff)
Merge pull request #8 from helix-editor/gd
Goto
Diffstat (limited to 'helix-lsp/src/client.rs')
-rw-r--r--helix-lsp/src/client.rs94
1 files changed, 94 insertions, 0 deletions
diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs
index a9b7fe20..97e5cfad 100644
--- a/helix-lsp/src/client.rs
+++ b/helix-lsp/src/client.rs
@@ -582,4 +582,98 @@ impl Client {
Ok(response.unwrap_or_default())
}
+
+ async fn goto_request<
+ T: lsp::request::Request<
+ Params = lsp::GotoDefinitionParams,
+ Result = Option<lsp::GotoDefinitionResponse>,
+ >,
+ >(
+ &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::<T>(params).await?;
+
+ let items = match response {
+ Some(lsp::GotoDefinitionResponse::Scalar(location)) => vec![location],
+ Some(lsp::GotoDefinitionResponse::Array(locations)) => locations,
+ Some(lsp::GotoDefinitionResponse::Link(locations)) => locations
+ .into_iter()
+ .map(|location_link| lsp::Location {
+ uri: location_link.target_uri,
+ range: location_link.target_range,
+ })
+ .collect(),
+ None => Vec::new(),
+ };
+
+ Ok(items)
+ }
+
+ pub async fn goto_definition(
+ &self,
+ text_document: lsp::TextDocumentIdentifier,
+ position: lsp::Position,
+ ) -> anyhow::Result<Vec<lsp::Location>> {
+ self.goto_request::<lsp::request::GotoDefinition>(text_document, position)
+ .await
+ }
+
+ pub async fn goto_type_definition(
+ &self,
+ text_document: lsp::TextDocumentIdentifier,
+ position: lsp::Position,
+ ) -> anyhow::Result<Vec<lsp::Location>> {
+ self.goto_request::<lsp::request::GotoTypeDefinition>(text_document, position)
+ .await
+ }
+
+ pub async fn goto_implementation(
+ &self,
+ text_document: lsp::TextDocumentIdentifier,
+ position: lsp::Position,
+ ) -> anyhow::Result<Vec<lsp::Location>> {
+ self.goto_request::<lsp::request::GotoImplementation>(text_document, position)
+ .await
+ }
+
+ pub async fn goto_reference(
+ &self,
+ text_document: lsp::TextDocumentIdentifier,
+ position: lsp::Position,
+ ) -> anyhow::Result<Vec<lsp::Location>> {
+ let params = lsp::ReferenceParams {
+ text_document_position: lsp::TextDocumentPositionParams {
+ text_document,
+ position,
+ },
+ context: lsp::ReferenceContext {
+ include_declaration: true,
+ },
+ 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::References>(params).await?;
+
+ Ok(response.unwrap_or_default())
+ }
}