aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-16 10:33:13 +0000
committerGitHub <[email protected]>2020-03-16 10:33:13 +0000
commit2eb1677b12f15a377111e877f6a09e1a1550c8be (patch)
tree65212bd2a271776683682c76c7f033abe83a907d /crates/ra_db
parent200c275c2e9955371e61f6ad7684084655df46fc (diff)
parent92fd430dab8cd0c7a476ccc5db87607f3f0f00a2 (diff)
Merge #3603
3603: Fix crate display name dashes r=matklad a=SomeoneToIgnore A follow-up of https://github.com/rust-analyzer/rust-analyzer/pull/3602#discussion_r392733525 Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ra_db')
-rw-r--r--crates/ra_db/src/fixture.rs6
-rw-r--r--crates/ra_db/src/input.rs12
2 files changed, 14 insertions, 4 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,