aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/cargo_target_spec.rs12
-rw-r--r--crates/rust-analyzer/src/handlers.rs20
2 files changed, 17 insertions, 15 deletions
diff --git a/crates/rust-analyzer/src/cargo_target_spec.rs b/crates/rust-analyzer/src/cargo_target_spec.rs
index 1ab72bd91..8a8b4a32c 100644
--- a/crates/rust-analyzer/src/cargo_target_spec.rs
+++ b/crates/rust-analyzer/src/cargo_target_spec.rs
@@ -14,6 +14,7 @@ use crate::{global_state::GlobalStateSnapshot, Result};
14#[derive(Clone)] 14#[derive(Clone)]
15pub(crate) struct CargoTargetSpec { 15pub(crate) struct CargoTargetSpec {
16 pub(crate) workspace_root: AbsPathBuf, 16 pub(crate) workspace_root: AbsPathBuf,
17 pub(crate) cargo_toml: AbsPathBuf,
17 pub(crate) package: String, 18 pub(crate) package: String,
18 pub(crate) target: String, 19 pub(crate) target: String,
19 pub(crate) target_kind: TargetKind, 20 pub(crate) target_kind: TargetKind,
@@ -115,12 +116,17 @@ impl CargoTargetSpec {
115 Some(it) => it, 116 Some(it) => it,
116 None => return Ok(None), 117 None => return Ok(None),
117 }; 118 };
119
120 let target_data = &cargo_ws[target];
121 let package_data = &cargo_ws[target_data.package];
118 let res = CargoTargetSpec { 122 let res = CargoTargetSpec {
119 workspace_root: cargo_ws.workspace_root().to_path_buf(), 123 workspace_root: cargo_ws.workspace_root().to_path_buf(),
120 package: cargo_ws.package_flag(&cargo_ws[cargo_ws[target].package]), 124 cargo_toml: package_data.manifest.clone(),
121 target: cargo_ws[target].name.clone(), 125 package: cargo_ws.package_flag(&package_data),
122 target_kind: cargo_ws[target].kind, 126 target: target_data.name.clone(),
127 target_kind: target_data.kind,
123 }; 128 };
129
124 Ok(Some(res)) 130 Ok(Some(res))
125 } 131 }
126 132
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 89c7fd2c7..94e2bfa1b 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -1422,19 +1422,15 @@ pub(crate) fn handle_open_cargo_toml(
1422) -> Result<Option<lsp_types::GotoDefinitionResponse>> { 1422) -> Result<Option<lsp_types::GotoDefinitionResponse>> {
1423 let _p = profile::span("handle_open_cargo_toml"); 1423 let _p = profile::span("handle_open_cargo_toml");
1424 let file_id = from_proto::file_id(&snap, &params.text_document.uri)?; 1424 let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
1425 let maybe_cargo_spec = CargoTargetSpec::for_file(&snap, file_id)?;
1426 if maybe_cargo_spec.is_none() {
1427 return Ok(None);
1428 }
1429 1425
1430 let cargo_spec = maybe_cargo_spec.unwrap(); 1426 let cargo_spec = match CargoTargetSpec::for_file(&snap, file_id)? {
1431 let cargo_toml_path = cargo_spec.workspace_root.join("Cargo.toml"); 1427 Some(it) => it,
1432 if !cargo_toml_path.exists() { 1428 None => return Ok(None),
1433 return Ok(None); 1429 };
1434 } 1430
1435 let cargo_toml_url = to_proto::url_from_abs_path(&cargo_toml_path); 1431 let cargo_toml_url = to_proto::url_from_abs_path(&cargo_spec.cargo_toml);
1436 let cargo_toml_location = Location::new(cargo_toml_url, Range::default()); 1432 let res: lsp_types::GotoDefinitionResponse =
1437 let res = lsp_types::GotoDefinitionResponse::from(cargo_toml_location); 1433 Location::new(cargo_toml_url, Range::default()).into();
1438 Ok(Some(res)) 1434 Ok(Some(res))
1439} 1435}
1440 1436