Auto merge of #13296 - Strum355:package-information-package-name, r=Veykril
Fix PackageInformation having the crate name instead of package name The `PackageInformation` type from the LSIF PR used the _crate_ name instead of the _package_ name. This caused issues when looking up crates by this name on the Sourcegraph backend, where we sync crate contents, for crates such as actix-web and many of its components (actix-files, actix-http etc etc), see screenshot 1 for the observed symptom. This PR hasnt been tested on other entry points besides cargo (such as project json). See screenshot 2 for the change in behaviour via SCIP snapshot comparison. <details> <summary>Screenshot 1</summary> ![crates.io giving 404](https://user-images.githubusercontent.com/18282288/192286637-8bf7c333-4441-4e60-8cce-de7eaa11ee9f.png) </details> <details> <summary>Screenshot 2</summary> ![before and after from SCIP snapshot output](https://user-images.githubusercontent.com/18282288/192287733-d7e73ff0-abbc-4ae5-82d0-bf9dc45d755c.png) </details> Follow-up PR to my question over at the [rust-lang Zulip](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/canonical.20crate.20name.20confusion.20for.20monikers), excuse any incorrect usages of the term package vs crate.
This commit is contained in:
commit
8805d05d01
@ -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)
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ 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 +648,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 +660,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 +672,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 +698,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 +710,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 +733,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 +745,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 +757,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 +780,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 +792,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(
|
||||
|
@ -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);
|
||||
|
@ -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 => {
|
||||
|
@ -185,6 +185,9 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
|
||||
),
|
||||
origin: CratesIo {
|
||||
repo: None,
|
||||
name: Some(
|
||||
"hello-world",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
@ -260,6 +263,9 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
|
||||
),
|
||||
origin: CratesIo {
|
||||
repo: None,
|
||||
name: Some(
|
||||
"hello-world",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
@ -335,6 +341,9 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
|
||||
),
|
||||
origin: CratesIo {
|
||||
repo: None,
|
||||
name: Some(
|
||||
"hello-world",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
@ -410,6 +419,9 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
|
||||
),
|
||||
origin: CratesIo {
|
||||
repo: None,
|
||||
name: Some(
|
||||
"hello-world",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
@ -477,6 +489,9 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
|
||||
repo: Some(
|
||||
"https://github.com/rust-lang/libc",
|
||||
),
|
||||
name: Some(
|
||||
"libc",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
@ -567,6 +582,9 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
|
||||
),
|
||||
origin: CratesIo {
|
||||
repo: None,
|
||||
name: Some(
|
||||
"hello-world",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
@ -644,6 +662,9 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
|
||||
),
|
||||
origin: CratesIo {
|
||||
repo: None,
|
||||
name: Some(
|
||||
"hello-world",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
@ -721,6 +742,9 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
|
||||
),
|
||||
origin: CratesIo {
|
||||
repo: None,
|
||||
name: Some(
|
||||
"hello-world",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
@ -798,6 +822,9 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
|
||||
),
|
||||
origin: CratesIo {
|
||||
repo: None,
|
||||
name: Some(
|
||||
"hello-world",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
@ -865,6 +892,9 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
|
||||
repo: Some(
|
||||
"https://github.com/rust-lang/libc",
|
||||
),
|
||||
name: Some(
|
||||
"libc",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
@ -946,6 +976,9 @@ fn cargo_hello_world_project_model() {
|
||||
),
|
||||
origin: CratesIo {
|
||||
repo: None,
|
||||
name: Some(
|
||||
"hello-world",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
@ -1023,6 +1056,9 @@ fn cargo_hello_world_project_model() {
|
||||
),
|
||||
origin: CratesIo {
|
||||
repo: None,
|
||||
name: Some(
|
||||
"hello-world",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
@ -1100,6 +1136,9 @@ fn cargo_hello_world_project_model() {
|
||||
),
|
||||
origin: CratesIo {
|
||||
repo: None,
|
||||
name: Some(
|
||||
"hello-world",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
@ -1177,6 +1216,9 @@ fn cargo_hello_world_project_model() {
|
||||
),
|
||||
origin: CratesIo {
|
||||
repo: None,
|
||||
name: Some(
|
||||
"hello-world",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
@ -1244,6 +1286,9 @@ fn cargo_hello_world_project_model() {
|
||||
repo: Some(
|
||||
"https://github.com/rust-lang/libc",
|
||||
),
|
||||
name: Some(
|
||||
"libc",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
@ -1804,6 +1849,9 @@ fn rust_project_hello_world_project_model() {
|
||||
),
|
||||
origin: CratesIo {
|
||||
repo: None,
|
||||
name: Some(
|
||||
"hello_world",
|
||||
),
|
||||
},
|
||||
is_proc_macro: false,
|
||||
},
|
||||
|
@ -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()) },
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user