mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Merge #6760
6760: Open Cargo.toml opens more specific manifest r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
e2e6b709e6
2 changed files with 17 additions and 15 deletions
|
@ -14,6 +14,7 @@ use crate::{global_state::GlobalStateSnapshot, Result};
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct CargoTargetSpec {
|
pub(crate) struct CargoTargetSpec {
|
||||||
pub(crate) workspace_root: AbsPathBuf,
|
pub(crate) workspace_root: AbsPathBuf,
|
||||||
|
pub(crate) cargo_toml: AbsPathBuf,
|
||||||
pub(crate) package: String,
|
pub(crate) package: String,
|
||||||
pub(crate) target: String,
|
pub(crate) target: String,
|
||||||
pub(crate) target_kind: TargetKind,
|
pub(crate) target_kind: TargetKind,
|
||||||
|
@ -115,12 +116,17 @@ impl CargoTargetSpec {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let target_data = &cargo_ws[target];
|
||||||
|
let package_data = &cargo_ws[target_data.package];
|
||||||
let res = CargoTargetSpec {
|
let res = CargoTargetSpec {
|
||||||
workspace_root: cargo_ws.workspace_root().to_path_buf(),
|
workspace_root: cargo_ws.workspace_root().to_path_buf(),
|
||||||
package: cargo_ws.package_flag(&cargo_ws[cargo_ws[target].package]),
|
cargo_toml: package_data.manifest.clone(),
|
||||||
target: cargo_ws[target].name.clone(),
|
package: cargo_ws.package_flag(&package_data),
|
||||||
target_kind: cargo_ws[target].kind,
|
target: target_data.name.clone(),
|
||||||
|
target_kind: target_data.kind,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Some(res))
|
Ok(Some(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1422,19 +1422,15 @@ pub(crate) fn handle_open_cargo_toml(
|
||||||
) -> Result<Option<lsp_types::GotoDefinitionResponse>> {
|
) -> Result<Option<lsp_types::GotoDefinitionResponse>> {
|
||||||
let _p = profile::span("handle_open_cargo_toml");
|
let _p = profile::span("handle_open_cargo_toml");
|
||||||
let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?;
|
let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?;
|
||||||
let maybe_cargo_spec = CargoTargetSpec::for_file(&snap, file_id)?;
|
|
||||||
if maybe_cargo_spec.is_none() {
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
let cargo_spec = maybe_cargo_spec.unwrap();
|
let cargo_spec = match CargoTargetSpec::for_file(&snap, file_id)? {
|
||||||
let cargo_toml_path = cargo_spec.workspace_root.join("Cargo.toml");
|
Some(it) => it,
|
||||||
if !cargo_toml_path.exists() {
|
None => return Ok(None),
|
||||||
return Ok(None);
|
};
|
||||||
}
|
|
||||||
let cargo_toml_url = to_proto::url_from_abs_path(&cargo_toml_path);
|
let cargo_toml_url = to_proto::url_from_abs_path(&cargo_spec.cargo_toml);
|
||||||
let cargo_toml_location = Location::new(cargo_toml_url, Range::default());
|
let res: lsp_types::GotoDefinitionResponse =
|
||||||
let res = lsp_types::GotoDefinitionResponse::from(cargo_toml_location);
|
Location::new(cargo_toml_url, Range::default()).into();
|
||||||
Ok(Some(res))
|
Ok(Some(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue