Fix PackageInformation having the crate name instead of package name

This commit is contained in:
Noah Santschi-Cooney 2022-09-26 14:09:54 +01:00
parent 1a24003eb6
commit aa093f5a58
No known key found for this signature in database
GPG Key ID: 3B22282472C8AE48
5 changed files with 40 additions and 24 deletions

View File

@ -196,7 +196,7 @@ pub fn parse_with_proc_macros(
Env::default(),
Ok(Vec::new()),
false,
CrateOrigin::CratesIo { repo: None },
CrateOrigin::CratesIo { repo: None, name: None },
);
} else {
for (from, to, prelude) in crate_deps {
@ -270,7 +270,7 @@ pub fn parse_with_proc_macros(
Env::default(),
Ok(proc_macro),
true,
CrateOrigin::CratesIo { repo: None },
CrateOrigin::CratesIo { repo: None, name: None },
);
for krate in all_crates {
@ -398,7 +398,7 @@ fn parse_crate(crate_str: String) -> (String, CrateOrigin, Option<String>) {
let (version, origin) = match b.split_once(':') {
Some(("CratesIo", data)) => match data.split_once(',') {
Some((version, url)) => {
(version, CrateOrigin::CratesIo { repo: Some(url.to_owned()) })
(version, CrateOrigin::CratesIo { repo: Some(url.to_owned()), name: None })
}
_ => panic!("Bad crates.io parameter: {}", data),
},
@ -409,7 +409,7 @@ fn parse_crate(crate_str: String) -> (String, CrateOrigin, Option<String>) {
let crate_origin = match &*crate_str {
"std" => CrateOrigin::Lang(LangCrateOrigin::Std),
"core" => CrateOrigin::Lang(LangCrateOrigin::Core),
_ => CrateOrigin::CratesIo { repo: None },
_ => CrateOrigin::CratesIo { repo: None, name: None },
};
(crate_str, crate_origin, None)
}

View File

@ -136,7 +136,10 @@ fn deref(&self) -> &str {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CrateOrigin {
/// Crates that are from crates.io official registry,
CratesIo { repo: Option<String> },
CratesIo {
repo: Option<String>,
name: Option<String>,
},
/// Crates that are provided by the language, like std, core, proc-macro, ...
Lang(LangCrateOrigin),
}
@ -648,7 +651,7 @@ fn detect_cyclic_dependency_indirect() {
Env::default(),
Ok(Vec::new()),
false,
CrateOrigin::CratesIo { repo: None },
CrateOrigin::CratesIo { repo: None, name: None },
);
let crate2 = graph.add_crate_root(
FileId(2u32),
@ -660,7 +663,7 @@ fn detect_cyclic_dependency_indirect() {
Env::default(),
Ok(Vec::new()),
false,
CrateOrigin::CratesIo { repo: None },
CrateOrigin::CratesIo { repo: None, name: None },
);
let crate3 = graph.add_crate_root(
FileId(3u32),
@ -672,7 +675,7 @@ fn detect_cyclic_dependency_indirect() {
Env::default(),
Ok(Vec::new()),
false,
CrateOrigin::CratesIo { repo: None },
CrateOrigin::CratesIo { repo: None, name: None },
);
assert!(graph
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
@ -698,7 +701,7 @@ fn detect_cyclic_dependency_direct() {
Env::default(),
Ok(Vec::new()),
false,
CrateOrigin::CratesIo { repo: None },
CrateOrigin::CratesIo { repo: None, name: None },
);
let crate2 = graph.add_crate_root(
FileId(2u32),
@ -710,7 +713,7 @@ fn detect_cyclic_dependency_direct() {
Env::default(),
Ok(Vec::new()),
false,
CrateOrigin::CratesIo { repo: None },
CrateOrigin::CratesIo { repo: None, name: None },
);
assert!(graph
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
@ -733,7 +736,7 @@ fn it_works() {
Env::default(),
Ok(Vec::new()),
false,
CrateOrigin::CratesIo { repo: None },
CrateOrigin::CratesIo { repo: None, name: None },
);
let crate2 = graph.add_crate_root(
FileId(2u32),
@ -745,7 +748,7 @@ fn it_works() {
Env::default(),
Ok(Vec::new()),
false,
CrateOrigin::CratesIo { repo: None },
CrateOrigin::CratesIo { repo: None, name: None },
);
let crate3 = graph.add_crate_root(
FileId(3u32),
@ -757,7 +760,7 @@ fn it_works() {
Env::default(),
Ok(Vec::new()),
false,
CrateOrigin::CratesIo { repo: None },
CrateOrigin::CratesIo { repo: None, name: None },
);
assert!(graph
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
@ -780,7 +783,7 @@ fn dashes_are_normalized() {
Env::default(),
Ok(Vec::new()),
false,
CrateOrigin::CratesIo { repo: None },
CrateOrigin::CratesIo { repo: None, name: None },
);
let crate2 = graph.add_crate_root(
FileId(2u32),
@ -792,7 +795,7 @@ fn dashes_are_normalized() {
Env::default(),
Ok(Vec::new()),
false,
CrateOrigin::CratesIo { repo: None },
CrateOrigin::CratesIo { repo: None, name: None },
);
assert!(graph
.add_dep(

View File

@ -236,7 +236,7 @@ pub fn from_single_file(text: String) -> (Analysis, FileId) {
Env::default(),
Ok(Vec::new()),
false,
CrateOrigin::CratesIo { repo: None },
CrateOrigin::CratesIo { repo: None, name: None },
);
change.change_file(file_id, Some(Arc::new(text)));
change.set_crate_graph(crate_graph);

View File

@ -253,10 +253,14 @@ pub(crate) fn def_to_moniker(
},
kind: if krate == from_crate { MonikerKind::Export } else { MonikerKind::Import },
package_information: {
let name = krate.display_name(db)?.to_string();
let (repo, version) = match krate.origin(db) {
CrateOrigin::CratesIo { repo } => (repo?, krate.version(db)?),
let (name, repo, version) = match krate.origin(db) {
CrateOrigin::CratesIo { repo, name } => (
name.unwrap_or(krate.display_name(db)?.canonical_name().to_string()),
repo?,
krate.version(db)?,
),
CrateOrigin::Lang(lang) => (
krate.display_name(db)?.canonical_name().to_string(),
"https://github.com/rust-lang/rust/".to_string(),
match lang {
LangCrateOrigin::Other => {

View File

@ -518,9 +518,15 @@ fn project_json_to_crate_graph(
proc_macro,
krate.is_proc_macro,
if krate.display_name.is_some() {
CrateOrigin::CratesIo { repo: krate.repository.clone() }
CrateOrigin::CratesIo {
repo: krate.repository.clone(),
name: krate
.display_name
.clone()
.map(|n| n.canonical_name().to_string()),
}
} else {
CrateOrigin::CratesIo { repo: None }
CrateOrigin::CratesIo { repo: None, name: None }
},
),
)
@ -740,14 +746,17 @@ fn detached_files_to_crate_graph(
let detached_file_crate = crate_graph.add_crate_root(
file_id,
Edition::CURRENT,
display_name,
display_name.clone(),
None,
cfg_options.clone(),
cfg_options.clone(),
Env::default(),
Ok(Vec::new()),
false,
CrateOrigin::CratesIo { repo: None },
CrateOrigin::CratesIo {
repo: None,
name: display_name.map(|n| n.canonical_name().to_string()),
},
);
public_deps.add(detached_file_crate, &mut crate_graph);
@ -923,7 +932,7 @@ fn add_target_crate_root(
env,
proc_macro,
is_proc_macro,
CrateOrigin::CratesIo { repo: pkg.repository.clone() },
CrateOrigin::CratesIo { repo: pkg.repository.clone(), name: Some(pkg.name.clone()) },
)
}