diff options
| author | bors <bors@rust-lang.org> | 2022-09-27 13:07:05 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-09-27 13:07:05 +0000 |
| commit | 8805d05d01f961476b815e38ce054de1c950119d (patch) | |
| tree | e59a38a9a323821083ea4a01e306859dbfec2623 | |
| parent | b01cdd89d581b2580396b846784d92c1cc128e05 (diff) | |
| parent | 651c586035dfb4cf244aa9e9dacabfee9f579564 (diff) | |
| download | rust-8805d05d01f961476b815e38ce054de1c950119d.tar.gz rust-8805d05d01f961476b815e38ce054de1c950119d.zip | |
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>  </details> <details> <summary>Screenshot 2</summary>  </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.
| -rw-r--r-- | crates/base-db/src/fixture.rs | 8 | ||||
| -rw-r--r-- | crates/base-db/src/input.rs | 22 | ||||
| -rw-r--r-- | crates/ide/src/lib.rs | 2 | ||||
| -rw-r--r-- | crates/ide/src/moniker.rs | 10 | ||||
| -rw-r--r-- | crates/project-model/src/tests.rs | 48 | ||||
| -rw-r--r-- | crates/project-model/src/workspace.rs | 19 |
6 files changed, 85 insertions, 24 deletions
diff --git a/crates/base-db/src/fixture.rs b/crates/base-db/src/fixture.rs index 8e6e6a11abd..5b7828a2699 100644 --- a/crates/base-db/src/fixture.rs +++ b/crates/base-db/src/fixture.rs @@ -196,7 +196,7 @@ impl ChangeFixture { 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 @@ impl ChangeFixture { 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) } diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs index b388e47dee6..e7f0c4ec29b 100644 --- a/crates/base-db/src/input.rs +++ b/crates/base-db/src/input.rs @@ -136,7 +136,7 @@ impl ops::Deref for CrateName { #[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 @@ mod tests { 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 @@ mod tests { 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 @@ mod tests { 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 @@ mod tests { 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 @@ mod tests { 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 @@ mod tests { 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 @@ mod tests { 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 @@ mod tests { 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 @@ mod tests { 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 @@ mod tests { Env::default(), Ok(Vec::new()), false, - CrateOrigin::CratesIo { repo: None }, + CrateOrigin::CratesIo { repo: None, name: None }, ); assert!(graph .add_dep( diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index c1ef25b592b..7820b67142f 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -236,7 +236,7 @@ impl Analysis { 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); diff --git a/crates/ide/src/moniker.rs b/crates/ide/src/moniker.rs index 600a526300c..852a8fd8376 100644 --- a/crates/ide/src/moniker.rs +++ b/crates/ide/src/moniker.rs @@ -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 => { diff --git a/crates/project-model/src/tests.rs b/crates/project-model/src/tests.rs index 813f0a7ce9f..e2444e24974 100644 --- a/crates/project-model/src/tests.rs +++ b/crates/project-model/src/tests.rs @@ -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, }, diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs index 2c0af99940f..d9d3cab4561 100644 --- a/crates/project-model/src/workspace.rs +++ b/crates/project-model/src/workspace.rs @@ -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()) }, ) } |
