goto_request wip

pull/8/head
Jan Hrastnik 4 years ago committed by Blaž Hrastnik
parent 3869d7713e
commit a5f9080a9c

1
Cargo.lock generated

@ -550,7 +550,6 @@ dependencies = [
"helix-view", "helix-view",
"ignore", "ignore",
"log", "log",
"lsp-types",
"num_cpus", "num_cpus",
"once_cell", "once_cell",
"pulldown-cmark", "pulldown-cmark",

@ -583,10 +583,26 @@ impl Client {
Ok(response.unwrap_or_default()) Ok(response.unwrap_or_default())
} }
pub async fn goto_generic( pub async fn goto_request<T: lsp::request::Request>(
&self, &self,
response: Option<lsp::GotoDefinitionResponse>, text_document: lsp::TextDocumentIdentifier,
position: lsp::Position,
) -> anyhow::Result<Vec<lsp::Location>> { ) -> 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 { let items = match response {
Some(lsp::GotoDefinitionResponse::Scalar(location)) => vec![location], Some(lsp::GotoDefinitionResponse::Scalar(location)) => vec![location],
Some(lsp::GotoDefinitionResponse::Array(location_vec)) => location_vec, Some(lsp::GotoDefinitionResponse::Array(location_vec)) => location_vec,
@ -612,22 +628,7 @@ impl Client {
text_document: lsp::TextDocumentIdentifier, text_document: lsp::TextDocumentIdentifier,
position: lsp::Position, position: lsp::Position,
) -> anyhow::Result<Vec<lsp::Location>> { ) -> anyhow::Result<Vec<lsp::Location>> {
let params = lsp::GotoDefinitionParams { self.goto_request(response).await
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?;
self.goto_generic(response).await
} }
pub async fn goto_type_definition( pub async fn goto_type_definition(
@ -652,7 +653,7 @@ impl Client {
.request::<lsp::request::GotoTypeDefinition>(params) .request::<lsp::request::GotoTypeDefinition>(params)
.await?; .await?;
self.goto_generic(response).await self.goto_request(response).await
} }
pub async fn goto_implementation( pub async fn goto_implementation(
@ -677,7 +678,7 @@ impl Client {
.request::<lsp::request::GotoImplementation>(params) .request::<lsp::request::GotoImplementation>(params)
.await?; .await?;
self.goto_generic(response).await self.goto_request(response).await
} }
pub async fn goto_reference( pub async fn goto_reference(
@ -703,7 +704,7 @@ impl Client {
let response = self.request::<lsp::request::References>(params).await?; let response = self.request::<lsp::request::References>(params).await?;
self.goto_generic(response.map(lsp::GotoDefinitionResponse::Array)) self.goto_request(response.map(lsp::GotoDefinitionResponse::Array))
.await .await
} }
} }

Loading…
Cancel
Save