From 059ed25a3eea97f370c190803318d5cb7885e1a9 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 16 Mar 2020 11:47:52 +0200 Subject: Fix crate display name dashes --- crates/ra_db/src/fixture.rs | 6 ++++-- crates/ra_db/src/input.rs | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'crates/ra_db/src') 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 crate_graph.add_crate_root( file_id, meta.edition, - meta.krate, + meta.krate.map(|name| { + CrateName::new(&name).expect("Fixture crate name should not contain dashes") + }), meta.cfg, meta.env, Default::default(), @@ -124,7 +126,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option CrateName { Self(SmolStr::new(name.replace('-', "_"))) } + + pub fn get_name(&self) -> String { + self.0.to_string() + } } #[derive(Debug, Clone, PartialEq, Eq)] @@ -110,7 +115,7 @@ pub struct CrateData { /// The name to display to the end user. /// 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. - pub display_name: Option, + pub display_name: Option, pub cfg_options: CfgOptions, pub env: Env, pub extern_source: ExternSource, @@ -150,7 +155,7 @@ impl CrateGraph { &mut self, file_id: FileId, edition: Edition, - display_name: Option, + display_name: Option, cfg_options: CfgOptions, env: Env, extern_source: ExternSource, -- cgit v1.2.3 From 92fd430dab8cd0c7a476ccc5db87607f3f0f00a2 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 16 Mar 2020 12:03:43 +0200 Subject: Use Display instead of a custom method --- crates/ra_db/src/input.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'crates/ra_db/src') diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index a6a831afa..bde843001 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -14,6 +14,7 @@ use rustc_hash::FxHashMap; use rustc_hash::FxHashSet; use crate::{RelativePath, RelativePathBuf}; +use fmt::Display; /// `FileId` is an integer which uniquely identifies a file. File paths are /// messy and system-dependent, so most of the code should work directly with @@ -102,9 +103,11 @@ impl CrateName { pub fn normalize_dashes(name: &str) -> CrateName { Self(SmolStr::new(name.replace('-', "_"))) } +} - pub fn get_name(&self) -> String { - self.0.to_string() +impl Display for CrateName { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.0) } } -- cgit v1.2.3