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