aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock9
-rw-r--r--crates/proc_macro_srv/Cargo.toml1
-rw-r--r--crates/project_model/src/cargo_workspace.rs22
-rw-r--r--crates/project_model/src/lib.rs7
-rw-r--r--crates/test_utils/Cargo.toml2
-rw-r--r--crates/test_utils/src/lib.rs19
6 files changed, 45 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock
index fe45f9dec..6b9020424 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -343,12 +343,6 @@ dependencies = [
343] 343]
344 344
345[[package]] 345[[package]]
346name = "difference"
347version = "2.0.0"
348source = "registry+https://github.com/rust-lang/crates.io-index"
349checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
350
351[[package]]
352name = "dissimilar" 346name = "dissimilar"
353version = "1.0.2" 347version = "1.0.2"
354source = "registry+https://github.com/rust-lang/crates.io-index" 348source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1170,7 +1164,6 @@ name = "proc_macro_srv"
1170version = "0.0.0" 1164version = "0.0.0"
1171dependencies = [ 1165dependencies = [
1172 "cargo_metadata", 1166 "cargo_metadata",
1173 "difference",
1174 "libloading", 1167 "libloading",
1175 "mbe", 1168 "mbe",
1176 "memmap", 1169 "memmap",
@@ -1621,7 +1614,7 @@ dependencies = [
1621name = "test_utils" 1614name = "test_utils"
1622version = "0.0.0" 1615version = "0.0.0"
1623dependencies = [ 1616dependencies = [
1624 "difference", 1617 "dissimilar",
1625 "rustc-hash", 1618 "rustc-hash",
1626 "serde_json", 1619 "serde_json",
1627 "stdx", 1620 "stdx",
diff --git a/crates/proc_macro_srv/Cargo.toml b/crates/proc_macro_srv/Cargo.toml
index df9a55c10..f78c17194 100644
--- a/crates/proc_macro_srv/Cargo.toml
+++ b/crates/proc_macro_srv/Cargo.toml
@@ -21,7 +21,6 @@ test_utils = { path = "../test_utils", version = "0.0.0" }
21 21
22[dev-dependencies] 22[dev-dependencies]
23cargo_metadata = "=0.12.0" 23cargo_metadata = "=0.12.0"
24difference = "2.0.0"
25 24
26# used as proc macro test targets 25# used as proc macro test targets
27serde_derive = "1.0.106" 26serde_derive = "1.0.106"
diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs
index 1700cb8a7..0e6679542 100644
--- a/crates/project_model/src/cargo_workspace.rs
+++ b/crates/project_model/src/cargo_workspace.rs
@@ -80,19 +80,35 @@ pub type Package = Idx<PackageData>;
80 80
81pub type Target = Idx<TargetData>; 81pub type Target = Idx<TargetData>;
82 82
83/// Information associated with a cargo crate
83#[derive(Debug, Clone, Eq, PartialEq)] 84#[derive(Debug, Clone, Eq, PartialEq)]
84pub struct PackageData { 85pub struct PackageData {
86 /// Version given in the `Cargo.toml`
85 pub version: String, 87 pub version: String,
88 /// Name as given in the `Cargo.toml`
86 pub name: String, 89 pub name: String,
90 /// Path containing the `Cargo.toml`
87 pub manifest: AbsPathBuf, 91 pub manifest: AbsPathBuf,
92 /// Targets provided by the crate (lib, bin, example, test, ...)
88 pub targets: Vec<Target>, 93 pub targets: Vec<Target>,
94 /// Is this package a member of the current workspace
89 pub is_member: bool, 95 pub is_member: bool,
96 /// List of packages this package depends on
90 pub dependencies: Vec<PackageDependency>, 97 pub dependencies: Vec<PackageDependency>,
98 /// Rust edition for this package
91 pub edition: Edition, 99 pub edition: Edition,
100 /// List of features to activate
92 pub features: Vec<String>, 101 pub features: Vec<String>,
102 /// List of config flags defined by this package's build script
93 pub cfgs: Vec<CfgFlag>, 103 pub cfgs: Vec<CfgFlag>,
104 /// List of cargo-related environment variables with their value
105 ///
106 /// If the package has a build script which defines environment variables,
107 /// they can also be found here.
94 pub envs: Vec<(String, String)>, 108 pub envs: Vec<(String, String)>,
109 /// Directory where a build script might place its output
95 pub out_dir: Option<AbsPathBuf>, 110 pub out_dir: Option<AbsPathBuf>,
111 /// Path to the proc-macro library file if this package exposes proc-macros
96 pub proc_macro_dylib_path: Option<AbsPathBuf>, 112 pub proc_macro_dylib_path: Option<AbsPathBuf>,
97} 113}
98 114
@@ -102,12 +118,18 @@ pub struct PackageDependency {
102 pub name: String, 118 pub name: String,
103} 119}
104 120
121/// Information associated with a package's target
105#[derive(Debug, Clone, Eq, PartialEq)] 122#[derive(Debug, Clone, Eq, PartialEq)]
106pub struct TargetData { 123pub struct TargetData {
124 /// Package that provided this target
107 pub package: Package, 125 pub package: Package,
126 /// Name as given in the `Cargo.toml` or generated from the file name
108 pub name: String, 127 pub name: String,
128 /// Path to the main source file of the target
109 pub root: AbsPathBuf, 129 pub root: AbsPathBuf,
130 /// Kind of target
110 pub kind: TargetKind, 131 pub kind: TargetKind,
132 /// Is this target a proc-macro
111 pub is_proc_macro: bool, 133 pub is_proc_macro: bool,
112} 134}
113 135
diff --git a/crates/project_model/src/lib.rs b/crates/project_model/src/lib.rs
index 24aa9b8fa..aabb7a47d 100644
--- a/crates/project_model/src/lib.rs
+++ b/crates/project_model/src/lib.rs
@@ -1,9 +1,9 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3mod cargo_workspace; 3mod cargo_workspace;
4mod cfg_flag;
4mod project_json; 5mod project_json;
5mod sysroot; 6mod sysroot;
6mod cfg_flag;
7mod workspace; 7mod workspace;
8 8
9use std::{ 9use std::{
@@ -17,7 +17,10 @@ use paths::{AbsPath, AbsPathBuf};
17use rustc_hash::FxHashSet; 17use rustc_hash::FxHashSet;
18 18
19pub use crate::{ 19pub use crate::{
20 cargo_workspace::{CargoConfig, CargoWorkspace, Package, Target, TargetKind}, 20 cargo_workspace::{
21 CargoConfig, CargoWorkspace, Package, PackageData, PackageDependency, Target, TargetData,
22 TargetKind,
23 },
21 project_json::{ProjectJson, ProjectJsonData}, 24 project_json::{ProjectJson, ProjectJsonData},
22 sysroot::Sysroot, 25 sysroot::Sysroot,
23 workspace::{PackageRoot, ProjectWorkspace}, 26 workspace::{PackageRoot, ProjectWorkspace},
diff --git a/crates/test_utils/Cargo.toml b/crates/test_utils/Cargo.toml
index 93eecc678..06341f003 100644
--- a/crates/test_utils/Cargo.toml
+++ b/crates/test_utils/Cargo.toml
@@ -11,7 +11,7 @@ doctest = false
11 11
12[dependencies] 12[dependencies]
13# Avoid adding deps here, this crate is widely used in tests it should compile fast! 13# Avoid adding deps here, this crate is widely used in tests it should compile fast!
14difference = "2.0.0" 14dissimilar = "1.0.2"
15text-size = "1.0.0" 15text-size = "1.0.0"
16serde_json = "1.0.48" 16serde_json = "1.0.48"
17rustc-hash = "1.1.0" 17rustc-hash = "1.1.0"
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index 05940a546..656dd2072 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -20,7 +20,7 @@ use serde_json::Value;
20use stdx::lines_with_ends; 20use stdx::lines_with_ends;
21use text_size::{TextRange, TextSize}; 21use text_size::{TextRange, TextSize};
22 22
23pub use difference::Changeset as __Changeset; 23pub use dissimilar::diff as __diff;
24pub use rustc_hash::FxHashMap; 24pub use rustc_hash::FxHashMap;
25 25
26pub use crate::fixture::Fixture; 26pub use crate::fixture::Fixture;
@@ -45,8 +45,8 @@ macro_rules! assert_eq_text {
45 if left.trim() == right.trim() { 45 if left.trim() == right.trim() {
46 std::eprintln!("Left:\n{:?}\n\nRight:\n{:?}\n\nWhitespace difference\n", left, right); 46 std::eprintln!("Left:\n{:?}\n\nRight:\n{:?}\n\nWhitespace difference\n", left, right);
47 } else { 47 } else {
48 let changeset = $crate::__Changeset::new(left, right, "\n"); 48 let diff = $crate::__diff(left, right);
49 std::eprintln!("Left:\n{}\n\nRight:\n{}\n\nDiff:\n{}\n", left, right, changeset); 49 std::eprintln!("Left:\n{}\n\nRight:\n{}\n\nDiff:\n{}\n", left, right, $crate::format_diff(diff));
50 } 50 }
51 std::eprintln!($($tt)*); 51 std::eprintln!($($tt)*);
52 panic!("text differs"); 52 panic!("text differs");
@@ -392,3 +392,16 @@ pub fn project_dir() -> PathBuf {
392 let dir = env!("CARGO_MANIFEST_DIR"); 392 let dir = env!("CARGO_MANIFEST_DIR");
393 PathBuf::from(dir).parent().unwrap().parent().unwrap().to_owned() 393 PathBuf::from(dir).parent().unwrap().parent().unwrap().to_owned()
394} 394}
395
396pub fn format_diff(chunks: Vec<dissimilar::Chunk>) -> String {
397 let mut buf = String::new();
398 for chunk in chunks {
399 let formatted = match chunk {
400 dissimilar::Chunk::Equal(text) => text.into(),
401 dissimilar::Chunk::Delete(text) => format!("\x1b[41m{}\x1b[0m", text),
402 dissimilar::Chunk::Insert(text) => format!("\x1b[42m{}\x1b[0m", text),
403 };
404 buf.push_str(&formatted);
405 }
406 buf
407}