@@ -583,6 +583,30 @@ impl Client {
583 Ok(response.unwrap_or_default())
583 Ok(response.unwrap_or_default())
586+ pub async fn goto_generic(
588+ response: Option<lsp::GotoDefinitionResponse>,
589+ ) -> anyhow::Result<Vec<lsp::Location>> {
590+ let items = match response {
591+ Some(lsp::GotoDefinitionResponse::Scalar(location)) => vec![location],
592+ Some(lsp::GotoDefinitionResponse::Array(location_vec)) => location_vec,
593+ Some(lsp::GotoDefinitionResponse::Link(location_link_vec)) => {
594+ let mut location_vec: Vec<lsp::Location> = Vec::new();
595+ location_link_vec.into_iter().for_each(|location_link| {
596+ let link = lsp::Location {
597+ uri: location_link.target_uri,
598+ range: location_link.target_range,
600+ location_vec.push(link)
586 pub async fn goto_definition(
610 pub async fn goto_definition(
588 text_document: lsp::TextDocumentIdentifier,
612 text_document: lsp::TextDocumentIdentifier,
@@ -603,23 +627,83 @@ impl Client {
604 let response = self.request::<lsp::request::GotoDefinition>(params).await?;
628 let response = self.request::<lsp::request::GotoDefinition>(params).await?;
606− let items = match response {
630+ self.goto_generic(response).await
607− Some(lsp::GotoDefinitionResponse::Scalar(location)) => vec![location],
631+ }
608− Some(lsp::GotoDefinitionResponse::Array(location_vec)) => location_vec,
632+
609− Some(lsp::GotoDefinitionResponse::Link(location_link_vec)) => {
633+ pub async fn goto_type_definition(
635+ text_document: lsp::TextDocumentIdentifier,
636+ position: lsp::Position,
610− let mut location_vec: Vec<lsp::Location> = Vec::new();
637+ ) -> anyhow::Result<Vec<lsp::Location>> {
611− location_link_vec.into_iter().for_each(|location_link| {
638+ let params = lsp::GotoDefinitionParams {
612− let link = lsp::Location {
639+ text_document_position_params: lsp::TextDocumentPositionParams {
613− uri: location_link.target_uri,
640+ text_document,
614− range: location_link.target_range,
641+ position,
616− location_vec.push(link)
643+ work_done_progress_params: lsp::WorkDoneProgressParams {
617− });
644+ work_done_token: None,
620− None => Vec::new(),
646+ partial_result_params: lsp::PartialResultParams {
647+ partial_result_token: None,
623− Ok(items)
651+ let response = self
652+ .request::<lsp::request::GotoTypeDefinition>(params)
655+ self.goto_generic(response).await
658+ pub async fn goto_implementation(
660+ text_document: lsp::TextDocumentIdentifier,
661+ position: lsp::Position,
662+ ) -> anyhow::Result<Vec<lsp::Location>> {
663+ let params = lsp::GotoDefinitionParams {
664+ text_document_position_params: lsp::TextDocumentPositionParams {
668+ work_done_progress_params: lsp::WorkDoneProgressParams {
669+ work_done_token: None,
671+ partial_result_params: lsp::PartialResultParams {
672+ partial_result_token: None,
677+ .request::<lsp::request::GotoImplementation>(params)
680+ self.goto_generic(response).await
683+ pub async fn goto_reference(
685+ text_document: lsp::TextDocumentIdentifier,
686+ position: lsp::Position,
687+ ) -> anyhow::Result<Vec<lsp::Location>> {
688+ let params = lsp::ReferenceParams {
689+ text_document_position: lsp::TextDocumentPositionParams {
693+ context: lsp::ReferenceContext {
694+ include_declaration: true,
696+ work_done_progress_params: lsp::WorkDoneProgressParams {
697+ work_done_token: None,
699+ partial_result_params: lsp::PartialResultParams {
700+ partial_result_token: None,
704+ let response = self.request::<lsp::request::References>(params).await?;
706+ self.goto_generic(response.map(lsp::GotoDefinitionResponse::Array))