mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Use Strings for display names
This commit is contained in:
parent
307c6fec61
commit
80386ca5be
5 changed files with 15 additions and 15 deletions
|
@ -149,15 +149,17 @@ fn with_files(
|
||||||
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(CrateName::new(&krate).unwrap()),
|
Some(krate.clone()),
|
||||||
meta.cfg,
|
meta.cfg,
|
||||||
meta.env,
|
meta.env,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
);
|
);
|
||||||
let prev = crates.insert(krate.clone(), crate_id);
|
let crate_name = CrateName::new(&krate).unwrap();
|
||||||
|
let prev = crates.insert(crate_name.clone(), crate_id);
|
||||||
assert!(prev.is_none());
|
assert!(prev.is_none());
|
||||||
for dep in meta.deps {
|
for dep in meta.deps {
|
||||||
crate_deps.push((krate.clone(), dep))
|
let dep = CrateName::new(&dep).unwrap();
|
||||||
|
crate_deps.push((crate_name.clone(), dep))
|
||||||
}
|
}
|
||||||
} else if meta.path == "/main.rs" || meta.path == "/lib.rs" {
|
} else if meta.path == "/main.rs" || meta.path == "/lib.rs" {
|
||||||
assert!(default_crate_root.is_none());
|
assert!(default_crate_root.is_none());
|
||||||
|
|
|
@ -67,7 +67,7 @@ pub struct CrateGraph {
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct CrateId(pub u32);
|
pub struct CrateId(pub u32);
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct CrateName(SmolStr);
|
pub struct CrateName(SmolStr);
|
||||||
|
|
||||||
impl CrateName {
|
impl CrateName {
|
||||||
|
@ -124,7 +124,7 @@ pub struct CrateData {
|
||||||
/// The name to display to the end user.
|
/// The name to display to the end user.
|
||||||
/// This actual crate name can be different in a particular dependent crate
|
/// This actual crate name can be different in a particular dependent crate
|
||||||
/// or may even be missing for some cases, such as a dummy crate for the code snippet.
|
/// or may even be missing for some cases, such as a dummy crate for the code snippet.
|
||||||
pub display_name: Option<CrateName>,
|
pub display_name: Option<String>,
|
||||||
pub cfg_options: CfgOptions,
|
pub cfg_options: CfgOptions,
|
||||||
pub env: Env,
|
pub env: Env,
|
||||||
pub dependencies: Vec<Dependency>,
|
pub dependencies: Vec<Dependency>,
|
||||||
|
@ -153,7 +153,7 @@ impl CrateGraph {
|
||||||
&mut self,
|
&mut self,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
edition: Edition,
|
edition: Edition,
|
||||||
display_name: Option<CrateName>,
|
display_name: Option<String>,
|
||||||
cfg_options: CfgOptions,
|
cfg_options: CfgOptions,
|
||||||
env: Env,
|
env: Env,
|
||||||
proc_macro: Vec<(SmolStr, Arc<dyn ra_tt::TokenExpander>)>,
|
proc_macro: Vec<(SmolStr, Arc<dyn ra_tt::TokenExpander>)>,
|
||||||
|
|
|
@ -31,7 +31,7 @@ use hir_ty::{
|
||||||
ApplicationTy, Canonical, GenericPredicate, InEnvironment, Substs, TraitEnvironment, Ty,
|
ApplicationTy, Canonical, GenericPredicate, InEnvironment, Substs, TraitEnvironment, Ty,
|
||||||
TyDefId, TypeCtor,
|
TyDefId, TypeCtor,
|
||||||
};
|
};
|
||||||
use ra_db::{CrateId, CrateName, Edition, FileId};
|
use ra_db::{CrateId, Edition, FileId};
|
||||||
use ra_prof::profile;
|
use ra_prof::profile;
|
||||||
use ra_syntax::ast::{self, AttrsOwner, NameOwner};
|
use ra_syntax::ast::{self, AttrsOwner, NameOwner};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
@ -94,8 +94,8 @@ impl Crate {
|
||||||
db.crate_graph()[self.id].edition
|
db.crate_graph()[self.id].edition
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn display_name(self, db: &dyn HirDatabase) -> Option<CrateName> {
|
pub fn display_name(self, db: &dyn HirDatabase) -> Option<String> {
|
||||||
db.crate_graph()[self.id].display_name.as_ref().cloned()
|
db.crate_graph()[self.id].display_name.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn query_external_importables(
|
pub fn query_external_importables(
|
||||||
|
|
|
@ -130,7 +130,7 @@ impl MockAnalysis {
|
||||||
let other_crate = crate_graph.add_crate_root(
|
let other_crate = crate_graph.add_crate_root(
|
||||||
file_id,
|
file_id,
|
||||||
edition,
|
edition,
|
||||||
Some(CrateName::new(crate_name).unwrap()),
|
Some(crate_name.to_string()),
|
||||||
cfg,
|
cfg,
|
||||||
env,
|
env,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
|
|
|
@ -309,13 +309,11 @@ impl ProjectWorkspace {
|
||||||
|
|
||||||
let env = Env::default();
|
let env = Env::default();
|
||||||
let proc_macro = vec![];
|
let proc_macro = vec![];
|
||||||
let crate_name = CrateName::new(&sysroot[krate].name)
|
let name = sysroot[krate].name.clone();
|
||||||
.expect("Sysroot crate names should not contain dashes");
|
|
||||||
|
|
||||||
let crate_id = crate_graph.add_crate_root(
|
let crate_id = crate_graph.add_crate_root(
|
||||||
file_id,
|
file_id,
|
||||||
Edition::Edition2018,
|
Edition::Edition2018,
|
||||||
Some(crate_name),
|
Some(name),
|
||||||
cfg_options.clone(),
|
cfg_options.clone(),
|
||||||
env,
|
env,
|
||||||
proc_macro,
|
proc_macro,
|
||||||
|
@ -389,7 +387,7 @@ impl ProjectWorkspace {
|
||||||
let crate_id = crate_graph.add_crate_root(
|
let crate_id = crate_graph.add_crate_root(
|
||||||
file_id,
|
file_id,
|
||||||
edition,
|
edition,
|
||||||
Some(CrateName::normalize_dashes(&cargo[pkg].name)),
|
Some(cargo[pkg].name.clone()),
|
||||||
cfg_options,
|
cfg_options,
|
||||||
env,
|
env,
|
||||||
proc_macro.clone(),
|
proc_macro.clone(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue