aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_db/src/fixture.rs6
-rw-r--r--crates/ra_db/src/input.rs12
-rw-r--r--crates/ra_hir_def/src/nameres.rs9
-rw-r--r--crates/ra_ide/src/hover.rs2
-rw-r--r--crates/ra_ide/src/mock_analysis.rs2
-rw-r--r--crates/ra_project_model/src/lib.rs7
6 files changed, 28 insertions, 10 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs
index 3dc86ca2d..3464f43df 100644
--- a/crates/ra_db/src/fixture.rs
+++ b/crates/ra_db/src/fixture.rs
@@ -64,7 +64,9 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId
64 crate_graph.add_crate_root( 64 crate_graph.add_crate_root(
65 file_id, 65 file_id,
66 meta.edition, 66 meta.edition,
67 meta.krate, 67 meta.krate.map(|name| {
68 CrateName::new(&name).expect("Fixture crate name should not contain dashes")
69 }),
68 meta.cfg, 70 meta.cfg,
69 meta.env, 71 meta.env,
70 Default::default(), 72 Default::default(),
@@ -124,7 +126,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
124 let crate_id = crate_graph.add_crate_root( 126 let crate_id = crate_graph.add_crate_root(
125 file_id, 127 file_id,
126 meta.edition, 128 meta.edition,
127 Some(krate.clone()), 129 Some(CrateName::new(&krate).unwrap()),
128 meta.cfg, 130 meta.cfg,
129 meta.env, 131 meta.env,
130 Default::default(), 132 Default::default(),
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index 06d40db96..bde843001 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -14,6 +14,7 @@ use rustc_hash::FxHashMap;
14use rustc_hash::FxHashSet; 14use rustc_hash::FxHashSet;
15 15
16use crate::{RelativePath, RelativePathBuf}; 16use crate::{RelativePath, RelativePathBuf};
17use fmt::Display;
17 18
18/// `FileId` is an integer which uniquely identifies a file. File paths are 19/// `FileId` is an integer which uniquely identifies a file. File paths are
19/// messy and system-dependent, so most of the code should work directly with 20/// messy and system-dependent, so most of the code should work directly with
@@ -83,6 +84,7 @@ pub struct CrateGraph {
83#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 84#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
84pub struct CrateId(pub u32); 85pub struct CrateId(pub u32);
85 86
87#[derive(Debug, Clone, PartialEq, Eq)]
86pub struct CrateName(SmolStr); 88pub struct CrateName(SmolStr);
87 89
88impl CrateName { 90impl CrateName {
@@ -103,6 +105,12 @@ impl CrateName {
103 } 105 }
104} 106}
105 107
108impl Display for CrateName {
109 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
110 write!(f, "{}", self.0)
111 }
112}
113
106#[derive(Debug, Clone, PartialEq, Eq)] 114#[derive(Debug, Clone, PartialEq, Eq)]
107pub struct CrateData { 115pub struct CrateData {
108 pub root_file_id: FileId, 116 pub root_file_id: FileId,
@@ -110,7 +118,7 @@ pub struct CrateData {
110 /// The name to display to the end user. 118 /// The name to display to the end user.
111 /// This actual crate name can be different in a particular dependent crate 119 /// This actual crate name can be different in a particular dependent crate
112 /// or may even be missing for some cases, such as a dummy crate for the code snippet. 120 /// or may even be missing for some cases, such as a dummy crate for the code snippet.
113 pub display_name: Option<String>, 121 pub display_name: Option<CrateName>,
114 pub cfg_options: CfgOptions, 122 pub cfg_options: CfgOptions,
115 pub env: Env, 123 pub env: Env,
116 pub extern_source: ExternSource, 124 pub extern_source: ExternSource,
@@ -150,7 +158,7 @@ impl CrateGraph {
150 &mut self, 158 &mut self,
151 file_id: FileId, 159 file_id: FileId,
152 edition: Edition, 160 edition: Edition,
153 display_name: Option<String>, 161 display_name: Option<CrateName>,
154 cfg_options: CfgOptions, 162 cfg_options: CfgOptions,
155 env: Env, 163 env: Env,
156 extern_source: ExternSource, 164 extern_source: ExternSource,
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index 81eac52ad..03515309e 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -177,8 +177,13 @@ pub struct ModuleData {
177 177
178impl CrateDefMap { 178impl CrateDefMap {
179 pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> { 179 pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
180 let _p = profile("crate_def_map_query") 180 let _p = profile("crate_def_map_query").detail(|| {
181 .detail(|| db.crate_graph()[krate].display_name.clone().unwrap_or_default()); 181 db.crate_graph()[krate]
182 .display_name
183 .as_ref()
184 .map(ToString::to_string)
185 .unwrap_or_default()
186 });
182 let def_map = { 187 let def_map = {
183 let edition = db.crate_graph()[krate].edition; 188 let edition = db.crate_graph()[krate].edition;
184 let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default(); 189 let mut modules: Arena<LocalModuleId, ModuleData> = Arena::default();
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index 3bdd61a2e..5b3760c18 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -94,7 +94,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
94 94
95fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> { 95fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
96 let mod_path = def.module(db).map(|module| { 96 let mod_path = def.module(db).map(|module| {
97 once(db.crate_graph()[module.krate().into()].display_name.clone()) 97 once(db.crate_graph()[module.krate().into()].display_name.as_ref().map(ToString::to_string))
98 .chain( 98 .chain(
99 module 99 module
100 .path_to_root(db) 100 .path_to_root(db)
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs
index 25816cf6f..2cf77a31f 100644
--- a/crates/ra_ide/src/mock_analysis.rs
+++ b/crates/ra_ide/src/mock_analysis.rs
@@ -109,7 +109,7 @@ impl MockAnalysis {
109 let other_crate = crate_graph.add_crate_root( 109 let other_crate = crate_graph.add_crate_root(
110 file_id, 110 file_id,
111 Edition2018, 111 Edition2018,
112 Some(crate_name.to_owned()), 112 Some(CrateName::new(crate_name).unwrap()),
113 cfg_options, 113 cfg_options,
114 Env::default(), 114 Env::default(),
115 Default::default(), 115 Default::default(),
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index a6274709d..897874813 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -245,7 +245,10 @@ impl ProjectWorkspace {
245 let crate_id = crate_graph.add_crate_root( 245 let crate_id = crate_graph.add_crate_root(
246 file_id, 246 file_id,
247 Edition::Edition2018, 247 Edition::Edition2018,
248 Some(krate.name(&sysroot).to_string()), 248 Some(
249 CrateName::new(krate.name(&sysroot))
250 .expect("Sysroot crate names should not contain dashes"),
251 ),
249 cfg_options, 252 cfg_options,
250 env, 253 env,
251 extern_source, 254 extern_source,
@@ -296,7 +299,7 @@ impl ProjectWorkspace {
296 let crate_id = crate_graph.add_crate_root( 299 let crate_id = crate_graph.add_crate_root(
297 file_id, 300 file_id,
298 edition, 301 edition,
299 Some(pkg.name(&cargo).to_string()), 302 Some(CrateName::normalize_dashes(pkg.name(&cargo))),
300 cfg_options, 303 cfg_options,
301 env, 304 env,
302 extern_source, 305 extern_source,