goto_request wip

This commit is contained in:
Jan Hrastnik 2021-03-10 23:35:12 +01:00 committed by Blaž Hrastnik
parent 3869d7713e
commit a5f9080a9c
2 changed files with 22 additions and 22 deletions

1
Cargo.lock generated
View file

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

View file

@ -583,10 +583,26 @@ impl Client {
Ok(response.unwrap_or_default())
}
pub async fn goto_generic(
pub async fn goto_request<T: lsp::request::Request>(
&self,
response: Option<lsp::GotoDefinitionResponse>,
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(location_vec)) => location_vec,
@ -612,22 +628,7 @@ impl Client {
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?;
self.goto_generic(response).await
self.goto_request(response).await
}
pub async fn goto_type_definition(
@ -652,7 +653,7 @@ impl Client {
.request::<lsp::request::GotoTypeDefinition>(params)
.await?;
self.goto_generic(response).await
self.goto_request(response).await
}
pub async fn goto_implementation(
@ -677,7 +678,7 @@ impl Client {
.request::<lsp::request::GotoImplementation>(params)
.await?;
self.goto_generic(response).await
self.goto_request(response).await
}
pub async fn goto_reference(
@ -703,7 +704,7 @@ impl Client {
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
}
}