diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-08 13:30:16 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-08 13:30:16 +0000 |
commit | e2e6b709e60f22279b755ceae74e579520c9ae3b (patch) | |
tree | 5b9e1f4abf35d7c988422eb8342741c9b340fc3a /crates | |
parent | 2aa7f2ece517a5202421f7a4a7cdd99bd1862ac8 (diff) | |
parent | 944f30bd694be71d76e1a175033e19409fe9f8b4 (diff) |
Merge #6760
6760: Open Cargo.toml opens more specific manifest r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/cargo_target_spec.rs | 12 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 20 |
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)] |
15 | pub(crate) struct CargoTargetSpec { | 15 | pub(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, ¶ms.text_document.uri)?; | 1424 | let file_id = from_proto::file_id(&snap, ¶ms.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 | ||