aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/cargo_target_spec.rs12
-rw-r--r--crates/rust-analyzer/src/handlers.rs10
2 files changed, 12 insertions, 10 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 7bfbc6103..6250171ba 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -1342,13 +1342,9 @@ pub(crate) fn handle_open_cargo_toml(
1342 None => return Ok(None), 1342 None => return Ok(None),
1343 }; 1343 };
1344 1344
1345 let cargo_toml_path = cargo_spec.workspace_root.join("Cargo.toml"); 1345 let cargo_toml_url = to_proto::url_from_abs_path(&cargo_spec.cargo_toml);
1346 if !cargo_toml_path.exists() { 1346 let res: lsp_types::GotoDefinitionResponse =
1347 return Ok(None); 1347 Location::new(cargo_toml_url, Range::default()).into();
1348 }
1349 let cargo_toml_url = to_proto::url_from_abs_path(&cargo_toml_path);
1350 let cargo_toml_location = Location::new(cargo_toml_url, Range::default());
1351 let res = lsp_types::GotoDefinitionResponse::from(cargo_toml_location);
1352 Ok(Some(res)) 1348 Ok(Some(res))
1353} 1349}
1354 1350