diff options
author | Kirill Bulatov <[email protected]> | 2020-03-16 09:47:52 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2020-03-16 09:47:52 +0000 |
commit | 059ed25a3eea97f370c190803318d5cb7885e1a9 (patch) | |
tree | 7c4b36fc3623683380caf5bd6487e3f8aa57774a /crates/ra_db | |
parent | 6bc226fa1918b8025b19cdf9d1f972f029e6a899 (diff) |
Fix crate display name dashes
Diffstat (limited to 'crates/ra_db')
-rw-r--r-- | crates/ra_db/src/fixture.rs | 6 | ||||
-rw-r--r-- | crates/ra_db/src/input.rs | 9 |
2 files changed, 11 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..a6a831afa 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -83,6 +83,7 @@ pub struct CrateGraph { | |||
83 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 83 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
84 | pub struct CrateId(pub u32); | 84 | pub struct CrateId(pub u32); |
85 | 85 | ||
86 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
86 | pub struct CrateName(SmolStr); | 87 | pub struct CrateName(SmolStr); |
87 | 88 | ||
88 | impl CrateName { | 89 | impl CrateName { |
@@ -101,6 +102,10 @@ impl CrateName { | |||
101 | pub fn normalize_dashes(name: &str) -> CrateName { | 102 | pub fn normalize_dashes(name: &str) -> CrateName { |
102 | Self(SmolStr::new(name.replace('-', "_"))) | 103 | Self(SmolStr::new(name.replace('-', "_"))) |
103 | } | 104 | } |
105 | |||
106 | pub fn get_name(&self) -> String { | ||
107 | self.0.to_string() | ||
108 | } | ||
104 | } | 109 | } |
105 | 110 | ||
106 | #[derive(Debug, Clone, PartialEq, Eq)] | 111 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -110,7 +115,7 @@ pub struct CrateData { | |||
110 | /// The name to display to the end user. | 115 | /// The name to display to the end user. |
111 | /// This actual crate name can be different in a particular dependent crate | 116 | /// 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. | 117 | /// or may even be missing for some cases, such as a dummy crate for the code snippet. |
113 | pub display_name: Option<String>, | 118 | pub display_name: Option<CrateName>, |
114 | pub cfg_options: CfgOptions, | 119 | pub cfg_options: CfgOptions, |
115 | pub env: Env, | 120 | pub env: Env, |
116 | pub extern_source: ExternSource, | 121 | pub extern_source: ExternSource, |
@@ -150,7 +155,7 @@ impl CrateGraph { | |||
150 | &mut self, | 155 | &mut self, |
151 | file_id: FileId, | 156 | file_id: FileId, |
152 | edition: Edition, | 157 | edition: Edition, |
153 | display_name: Option<String>, | 158 | display_name: Option<CrateName>, |
154 | cfg_options: CfgOptions, | 159 | cfg_options: CfgOptions, |
155 | env: Env, | 160 | env: Env, |
156 | extern_source: ExternSource, | 161 | extern_source: ExternSource, |