From d3ddc8dea6844f836199196c44b08e63fdf837d0 Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Sun, 21 Feb 2021 23:22:38 +0100 Subject: wip --- helix-lsp/src/client.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'helix-lsp') 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> { + 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::(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 = 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) + } } -- cgit v1.2.3-70-g09d2