mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
remove duplicate data from CrateOrigin
This commit is contained in:
parent
a654955159
commit
df261c10b9
4 changed files with 26 additions and 39 deletions
|
@ -131,13 +131,13 @@ impl ChangeFixture {
|
|||
current_source_root_kind = *kind;
|
||||
}
|
||||
|
||||
if let Some((krate, origin)) = meta.krate {
|
||||
if let Some((krate, origin, version)) = meta.krate {
|
||||
let crate_name = CrateName::normalize_dashes(&krate);
|
||||
let crate_id = crate_graph.add_crate_root(
|
||||
file_id,
|
||||
meta.edition,
|
||||
Some(crate_name.clone().into()),
|
||||
None,
|
||||
version,
|
||||
meta.cfg.clone(),
|
||||
meta.cfg,
|
||||
meta.env,
|
||||
|
@ -212,7 +212,7 @@ impl ChangeFixture {
|
|||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
Vec::new(),
|
||||
CrateOrigin::Lang("core".to_string()),
|
||||
CrateOrigin::Lang,
|
||||
);
|
||||
|
||||
for krate in all_crates {
|
||||
|
@ -247,7 +247,7 @@ impl ChangeFixture {
|
|||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
proc_macro,
|
||||
CrateOrigin::Lang("proc-macro".to_string()),
|
||||
CrateOrigin::Lang,
|
||||
);
|
||||
|
||||
for krate in all_crates {
|
||||
|
@ -329,7 +329,7 @@ enum SourceRootKind {
|
|||
#[derive(Debug)]
|
||||
struct FileMeta {
|
||||
path: String,
|
||||
krate: Option<(String, CrateOrigin)>,
|
||||
krate: Option<(String, CrateOrigin, Option<String>)>,
|
||||
deps: Vec<String>,
|
||||
extern_prelude: Vec<String>,
|
||||
cfg: CfgOptions,
|
||||
|
@ -338,24 +338,20 @@ struct FileMeta {
|
|||
introduce_new_source_root: Option<SourceRootKind>,
|
||||
}
|
||||
|
||||
fn parse_crate(crate_str: String) -> (String, CrateOrigin) {
|
||||
fn parse_crate(crate_str: String) -> (String, CrateOrigin, Option<String>) {
|
||||
if let Some((a, b)) = crate_str.split_once("@") {
|
||||
(
|
||||
a.to_owned(),
|
||||
match b.split_once(":") {
|
||||
let (version, origin) = match b.split_once(":") {
|
||||
Some(("CratesIo", data)) => match data.split_once(",") {
|
||||
Some((version, url)) => CrateOrigin::CratesIo {
|
||||
name: a.to_owned(),
|
||||
repo: Some(url.to_owned()),
|
||||
version: version.to_owned(),
|
||||
},
|
||||
Some((version, url)) => {
|
||||
(version, CrateOrigin::CratesIo { repo: Some(url.to_owned()) })
|
||||
}
|
||||
_ => panic!("Bad crates.io parameter: {}", data),
|
||||
},
|
||||
_ => panic!("Bad string for crate origin: {}", b),
|
||||
},
|
||||
)
|
||||
};
|
||||
(a.to_owned(), origin, Some(version.to_string()))
|
||||
} else {
|
||||
(crate_str, CrateOrigin::Unknown)
|
||||
(crate_str, CrateOrigin::Unknown, None)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -116,9 +116,9 @@ impl ops::Deref for CrateName {
|
|||
#[derive(Debug, Clone)]
|
||||
pub enum CrateOrigin {
|
||||
/// Crates that are from crates.io official registry,
|
||||
CratesIo { name: String, version: String, repo: Option<String> },
|
||||
CratesIo { repo: Option<String> },
|
||||
/// Crates that are provided by the language, like std, core, proc-macro, ...
|
||||
Lang(String),
|
||||
Lang,
|
||||
/// Crates that we don't know their origin.
|
||||
// Idealy this enum should cover all cases, and then we remove this variant.
|
||||
Unknown,
|
||||
|
|
|
@ -117,10 +117,10 @@ pub(crate) fn def_to_moniker(
|
|||
},
|
||||
kind: if krate == from_crate { MonikerKind::Export } else { MonikerKind::Import },
|
||||
package_information: {
|
||||
let (name, repo, version) = match krate.origin(db) {
|
||||
CrateOrigin::CratesIo { repo, name, version } => (name, repo?, version),
|
||||
CrateOrigin::Lang(name) => (
|
||||
name,
|
||||
let name = krate.display_name(db)?.to_string();
|
||||
let (repo, version) = match krate.origin(db) {
|
||||
CrateOrigin::CratesIo { repo } => (repo?, krate.version(db)?),
|
||||
CrateOrigin::Lang => (
|
||||
"https://github.com/rust-lang/rust/".to_string(),
|
||||
"compiler_version".to_string(),
|
||||
),
|
||||
|
|
|
@ -474,12 +474,8 @@ fn project_json_to_crate_graph(
|
|||
cfg_options,
|
||||
env,
|
||||
proc_macro.unwrap_or_default(),
|
||||
if let Some(name) = &krate.display_name {
|
||||
CrateOrigin::CratesIo {
|
||||
repo: krate.repository.clone(),
|
||||
name: name.crate_name().to_string(),
|
||||
version: krate.version.clone().unwrap_or_default(),
|
||||
}
|
||||
if krate.display_name.is_some() {
|
||||
CrateOrigin::CratesIo { repo: krate.repository.clone() }
|
||||
} else {
|
||||
CrateOrigin::Unknown
|
||||
},
|
||||
|
@ -832,7 +828,6 @@ fn add_target_crate_root(
|
|||
.iter()
|
||||
.map(|feat| CfgFlag::KeyValue { key: "feature".into(), value: feat.0.into() }),
|
||||
);
|
||||
let crate_name = display_name.crate_name().to_string();
|
||||
crate_graph.add_crate_root(
|
||||
file_id,
|
||||
edition,
|
||||
|
@ -842,11 +837,7 @@ fn add_target_crate_root(
|
|||
potential_cfg_options,
|
||||
env,
|
||||
proc_macro,
|
||||
CrateOrigin::CratesIo {
|
||||
name: crate_name,
|
||||
repo: pkg.repository.clone(),
|
||||
version: pkg.version.to_string(),
|
||||
},
|
||||
CrateOrigin::CratesIo { repo: pkg.repository.clone() },
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -890,7 +881,7 @@ fn sysroot_to_crate_graph(
|
|||
cfg_options.clone(),
|
||||
env,
|
||||
proc_macro,
|
||||
CrateOrigin::Lang(sysroot[krate].name.clone()),
|
||||
CrateOrigin::Lang,
|
||||
);
|
||||
Some((krate, crate_id))
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue