]> git.lizzy.rs Git - rust.git/commitdiff
Rename json_project -> project_json
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 24 Jun 2020 12:57:37 +0000 (14:57 +0200)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 24 Jun 2020 14:03:24 +0000 (16:03 +0200)
crates/ra_project_model/src/json_project.rs [deleted file]
crates/ra_project_model/src/lib.rs
crates/ra_project_model/src/project_json.rs [new file with mode: 0644]
crates/rust-analyzer/src/config.rs

diff --git a/crates/ra_project_model/src/json_project.rs b/crates/ra_project_model/src/json_project.rs
deleted file mode 100644 (file)
index ee2de4c..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-//! FIXME: write short doc here
-
-use std::path::PathBuf;
-
-use rustc_hash::FxHashSet;
-use serde::Deserialize;
-
-/// Roots and crates that compose this Rust project.
-#[derive(Clone, Debug, Deserialize)]
-pub struct JsonProject {
-    pub(crate) roots: Vec<Root>,
-    pub(crate) crates: Vec<Crate>,
-}
-
-/// A root points to the directory which contains Rust crates. rust-analyzer watches all files in
-/// all roots. Roots might be nested.
-#[derive(Clone, Debug, Deserialize)]
-#[serde(transparent)]
-pub struct Root {
-    pub(crate) path: PathBuf,
-}
-
-/// A crate points to the root module of a crate and lists the dependencies of the crate. This is
-/// useful in creating the crate graph.
-#[derive(Clone, Debug, Deserialize)]
-pub struct Crate {
-    pub(crate) root_module: PathBuf,
-    pub(crate) edition: Edition,
-    pub(crate) deps: Vec<Dep>,
-
-    #[serde(default)]
-    pub(crate) cfg: FxHashSet<String>,
-
-    pub(crate) out_dir: Option<PathBuf>,
-    pub(crate) proc_macro_dylib_path: Option<PathBuf>,
-}
-
-#[derive(Clone, Copy, Debug, Deserialize)]
-#[serde(rename = "edition")]
-pub enum Edition {
-    #[serde(rename = "2015")]
-    Edition2015,
-    #[serde(rename = "2018")]
-    Edition2018,
-}
-
-/// Identifies a crate by position in the crates array.
-#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd)]
-#[serde(transparent)]
-pub struct CrateId(pub usize);
-
-/// A dependency of a crate, identified by its id in the crates array and name.
-#[derive(Clone, Debug, Deserialize)]
-pub struct Dep {
-    #[serde(rename = "crate")]
-    pub(crate) krate: CrateId,
-    pub(crate) name: String,
-}
-
-#[cfg(test)]
-mod tests {
-    use super::*;
-    use serde_json::json;
-
-    #[test]
-    fn test_crate_deserialization() {
-        let raw_json = json!(    {
-            "crate_id": 2,
-            "root_module": "this/is/a/file/path.rs",
-            "deps": [
-              {
-                "crate": 1,
-                "name": "some_dep_crate"
-              },
-            ],
-            "edition": "2015",
-            "cfg": [
-              "atom_1",
-              "atom_2",
-              "feature=feature_1",
-              "feature=feature_2",
-              "other=value",
-            ],
-
-        });
-
-        let krate: Crate = serde_json::from_value(raw_json).unwrap();
-
-        assert!(krate.cfg.contains(&"atom_1".to_string()));
-        assert!(krate.cfg.contains(&"atom_2".to_string()));
-        assert!(krate.cfg.contains(&"feature=feature_1".to_string()));
-        assert!(krate.cfg.contains(&"feature=feature_2".to_string()));
-        assert!(krate.cfg.contains(&"other=value".to_string()));
-    }
-}
index ac88532f07c4febfcee95497ed0ffe24e1cc9c33..7e8e00df8b2c4da841ac5731bc8991ceb524ce60 100644 (file)
@@ -1,7 +1,7 @@
 //! FIXME: write short doc here
 
 mod cargo_workspace;
-mod json_project;
+mod project_json;
 mod sysroot;
 
 use std::{
@@ -20,7 +20,7 @@
 
 pub use crate::{
     cargo_workspace::{CargoConfig, CargoWorkspace, Package, Target, TargetKind},
-    json_project::JsonProject,
+    project_json::ProjectJson,
     sysroot::Sysroot,
 };
 pub use ra_proc_macro::ProcMacroClient;
@@ -30,7 +30,7 @@ pub enum ProjectWorkspace {
     /// Project workspace was discovered by running `cargo metadata` and `rustc --print sysroot`.
     Cargo { cargo: CargoWorkspace, sysroot: Sysroot },
     /// Project workspace was manually specified using a `rust-project.json` file.
-    Json { project: JsonProject, project_location: AbsPathBuf },
+    Json { project: ProjectJson, project_location: AbsPathBuf },
 }
 
 /// `PackageRoot` describes a package root folder.
@@ -259,8 +259,8 @@ pub fn to_crate_graph(
                         let file_path = project_location.join(&krate.root_module);
                         let file_id = load(&file_path)?;
                         let edition = match krate.edition {
-                            json_project::Edition::Edition2015 => Edition::Edition2015,
-                            json_project::Edition::Edition2018 => Edition::Edition2018,
+                            project_json::Edition::Edition2015 => Edition::Edition2015,
+                            project_json::Edition::Edition2018 => Edition::Edition2018,
                         };
                         let cfg_options = {
                             let mut opts = CfgOptions::default();
@@ -290,7 +290,7 @@ pub fn to_crate_graph(
                             .map(|it| proc_macro_client.by_dylib_path(&it));
                         // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env
                         Some((
-                            json_project::CrateId(seq_index),
+                            project_json::CrateId(seq_index),
                             crate_graph.add_crate_root(
                                 file_id,
                                 edition,
@@ -306,7 +306,7 @@ pub fn to_crate_graph(
 
                 for (id, krate) in project.crates.iter().enumerate() {
                     for dep in &krate.deps {
-                        let from_crate_id = json_project::CrateId(id);
+                        let from_crate_id = project_json::CrateId(id);
                         let to_crate_id = dep.krate;
                         if let (Some(&from), Some(&to)) =
                             (crates.get(&from_crate_id), crates.get(&to_crate_id))
@@ -528,7 +528,7 @@ pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> {
             ProjectWorkspace::Cargo { cargo, .. } => {
                 Some(cargo.workspace_root()).filter(|root| path.starts_with(root))
             }
-            ProjectWorkspace::Json { project: JsonProject { roots, .. }, .. } => roots
+            ProjectWorkspace::Json { project: ProjectJson { roots, .. }, .. } => roots
                 .iter()
                 .find(|root| path.starts_with(&root.path))
                 .map(|root| root.path.as_ref()),
diff --git a/crates/ra_project_model/src/project_json.rs b/crates/ra_project_model/src/project_json.rs
new file mode 100644 (file)
index 0000000..e663bb4
--- /dev/null
@@ -0,0 +1,95 @@
+//! FIXME: write short doc here
+
+use std::path::PathBuf;
+
+use rustc_hash::FxHashSet;
+use serde::Deserialize;
+
+/// Roots and crates that compose this Rust project.
+#[derive(Clone, Debug, Deserialize)]
+pub struct ProjectJson {
+    pub(crate) roots: Vec<Root>,
+    pub(crate) crates: Vec<Crate>,
+}
+
+/// A root points to the directory which contains Rust crates. rust-analyzer watches all files in
+/// all roots. Roots might be nested.
+#[derive(Clone, Debug, Deserialize)]
+#[serde(transparent)]
+pub struct Root {
+    pub(crate) path: PathBuf,
+}
+
+/// A crate points to the root module of a crate and lists the dependencies of the crate. This is
+/// useful in creating the crate graph.
+#[derive(Clone, Debug, Deserialize)]
+pub struct Crate {
+    pub(crate) root_module: PathBuf,
+    pub(crate) edition: Edition,
+    pub(crate) deps: Vec<Dep>,
+
+    #[serde(default)]
+    pub(crate) cfg: FxHashSet<String>,
+
+    pub(crate) out_dir: Option<PathBuf>,
+    pub(crate) proc_macro_dylib_path: Option<PathBuf>,
+}
+
+#[derive(Clone, Copy, Debug, Deserialize)]
+#[serde(rename = "edition")]
+pub enum Edition {
+    #[serde(rename = "2015")]
+    Edition2015,
+    #[serde(rename = "2018")]
+    Edition2018,
+}
+
+/// Identifies a crate by position in the crates array.
+#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd)]
+#[serde(transparent)]
+pub struct CrateId(pub usize);
+
+/// A dependency of a crate, identified by its id in the crates array and name.
+#[derive(Clone, Debug, Deserialize)]
+pub struct Dep {
+    #[serde(rename = "crate")]
+    pub(crate) krate: CrateId,
+    pub(crate) name: String,
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use serde_json::json;
+
+    #[test]
+    fn test_crate_deserialization() {
+        let raw_json = json!(    {
+            "crate_id": 2,
+            "root_module": "this/is/a/file/path.rs",
+            "deps": [
+              {
+                "crate": 1,
+                "name": "some_dep_crate"
+              },
+            ],
+            "edition": "2015",
+            "cfg": [
+              "atom_1",
+              "atom_2",
+              "feature=feature_1",
+              "feature=feature_2",
+              "other=value",
+            ],
+
+        });
+
+        let krate: Crate = serde_json::from_value(raw_json).unwrap();
+
+        assert!(krate.cfg.contains(&"atom_1".to_string()));
+        assert!(krate.cfg.contains(&"atom_2".to_string()));
+        assert!(krate.cfg.contains(&"feature=feature_1".to_string()));
+        assert!(krate.cfg.contains(&"feature=feature_2".to_string()));
+        assert!(krate.cfg.contains(&"other=value".to_string()));
+    }
+}
index 0be34c43f063f93c215df36fe1d9000115ec5df8..7eded04c5a6e70dea377a5aa95cfa7fce92837a0 100644 (file)
@@ -14,7 +14,7 @@
 use ra_db::AbsPathBuf;
 use ra_flycheck::FlycheckConfig;
 use ra_ide::{AssistConfig, CompletionConfig, HoverConfig, InlayHintsConfig};
-use ra_project_model::{CargoConfig, JsonProject, ProjectManifest};
+use ra_project_model::{CargoConfig, ProjectJson, ProjectManifest};
 use serde::Deserialize;
 
 #[derive(Debug, Clone)]
@@ -47,7 +47,7 @@ pub struct Config {
 #[derive(Debug, Clone)]
 pub enum LinkedProject {
     ProjectManifest(ProjectManifest),
-    InlineJsonProject(JsonProject),
+    InlineJsonProject(ProjectJson),
 }
 
 impl From<ProjectManifest> for LinkedProject {
@@ -56,8 +56,8 @@ fn from(v: ProjectManifest) -> Self {
     }
 }
 
-impl From<JsonProject> for LinkedProject {
-    fn from(v: JsonProject) -> Self {
+impl From<ProjectJson> for LinkedProject {
+    fn from(v: ProjectJson) -> Self {
         LinkedProject::InlineJsonProject(v)
     }
 }
@@ -373,5 +373,5 @@ pub fn update_caps(&mut self, caps: &ClientCapabilities) {
 #[serde(untagged)]
 enum ManifestOrJsonProject {
     Manifest(PathBuf),
-    JsonProject(JsonProject),
+    JsonProject(ProjectJson),
 }