Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/base-db/src/input.rs')
-rw-r--r--crates/base-db/src/input.rs55
1 files changed, 42 insertions, 13 deletions
diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs
index 27eb05cd4d..240af7925c 100644
--- a/crates/base-db/src/input.rs
+++ b/crates/base-db/src/input.rs
@@ -19,6 +19,10 @@ use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath};
// Map from crate id to the name of the crate and path of the proc-macro. If the value is `None`,
// then the crate for the proc-macro hasn't been build yet as the build data is missing.
pub type ProcMacroPaths = FxHashMap<CrateId, Result<(Option<String>, AbsPathBuf), String>>;
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
+pub struct SourceRootId(pub u32);
+
/// Files are grouped into source roots. A source root is a directory on the
/// file systems which is watched for changes. Typically it corresponds to a
/// Rust crate. Source roots *might* be nested: in this case, a file belongs to
@@ -26,9 +30,6 @@ pub type ProcMacroPaths = FxHashMap<CrateId, Result<(Option<String>, AbsPathBuf)
/// source root, and the analyzer does not know the root path of the source root at
/// all. So, a file from one source root can't refer to a file in another source
/// root by path.
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
-pub struct SourceRootId(pub u32);
-
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SourceRoot {
/// Sysroot or crates.io library.
@@ -285,20 +286,39 @@ pub struct CrateData {
/// For purposes of analysis, crates are anonymous (only names in
/// `Dependency` matters), this name should only be used for UI.
pub display_name: Option<CrateDisplayName>,
- pub cfg_options: CfgOptions,
+ pub cfg_options: Arc<CfgOptions>,
/// The cfg options that could be used by the crate
- pub potential_cfg_options: Option<CfgOptions>,
+ pub potential_cfg_options: Option<Arc<CfgOptions>>,
pub env: Env,
pub dependencies: Vec<Dependency>,
pub origin: CrateOrigin,
pub is_proc_macro: bool,
}
-#[derive(Default, Debug, Clone, PartialEq, Eq)]
+#[derive(Default, Clone, PartialEq, Eq)]
pub struct Env {
entries: FxHashMap<String, String>,
}
+impl fmt::Debug for Env {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ struct EnvDebug<'s>(Vec<(&'s String, &'s String)>);
+
+ impl fmt::Debug for EnvDebug<'_> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_map().entries(self.0.iter().copied()).finish()
+ }
+ }
+ f.debug_struct("Env")
+ .field("entries", &{
+ let mut entries: Vec<_> = self.entries.iter().collect();
+ entries.sort();
+ EnvDebug(entries)
+ })
+ .finish()
+ }
+}
+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Dependency {
pub crate_id: CrateId,
@@ -328,12 +348,13 @@ impl CrateGraph {
edition: Edition,
display_name: Option<CrateDisplayName>,
version: Option<String>,
- cfg_options: CfgOptions,
- potential_cfg_options: Option<CfgOptions>,
- env: Env,
+ cfg_options: Arc<CfgOptions>,
+ potential_cfg_options: Option<Arc<CfgOptions>>,
+ mut env: Env,
is_proc_macro: bool,
origin: CrateOrigin,
) -> CrateId {
+ env.entries.shrink_to_fit();
let data = CrateData {
root_file_id,
edition,
@@ -650,16 +671,24 @@ impl FromIterator<(String, String)> for Env {
}
impl Env {
- pub fn set(&mut self, env: &str, value: String) {
- self.entries.insert(env.to_owned(), value);
+ pub fn set(&mut self, env: &str, value: impl Into<String>) {
+ self.entries.insert(env.to_owned(), value.into());
}
pub fn get(&self, env: &str) -> Option<String> {
self.entries.get(env).cloned()
}
- pub fn iter(&self) -> impl Iterator<Item = (&str, &str)> {
- self.entries.iter().map(|(k, v)| (k.as_str(), v.as_str()))
+ pub fn extend_from_other(&mut self, other: &Env) {
+ self.entries.extend(other.entries.iter().map(|(x, y)| (x.to_owned(), y.to_owned())));
+ }
+}
+
+impl From<Env> for Vec<(String, String)> {
+ fn from(env: Env) -> Vec<(String, String)> {
+ let mut entries: Vec<_> = env.entries.into_iter().collect();
+ entries.sort();
+ entries
}
}