diff options
-rw-r--r-- | crates/assert_eq_text/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/assert_eq_text/src/lib.rs | 11 | ||||
-rw-r--r-- | crates/libanalysis/Cargo.toml | 3 | ||||
-rw-r--r-- | crates/libanalysis/src/lib.rs | 24 | ||||
-rw-r--r-- | crates/libanalysis/tests/tests.rs | 45 | ||||
-rw-r--r-- | crates/libeditor/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/libeditor/tests/test.rs | 13 | ||||
-rw-r--r-- | crates/libsyntax2/Cargo.toml | 2 |
8 files changed, 82 insertions, 19 deletions
diff --git a/crates/assert_eq_text/Cargo.toml b/crates/assert_eq_text/Cargo.toml index 21858dfd3..e122bbbeb 100644 --- a/crates/assert_eq_text/Cargo.toml +++ b/crates/assert_eq_text/Cargo.toml | |||
@@ -5,3 +5,4 @@ authors = ["Aleksey Kladov <[email protected]>"] | |||
5 | 5 | ||
6 | [dependencies] | 6 | [dependencies] |
7 | difference = "2.0.0" | 7 | difference = "2.0.0" |
8 | itertools = "0.7.8" | ||
diff --git a/crates/assert_eq_text/src/lib.rs b/crates/assert_eq_text/src/lib.rs index ed942d81a..26b9bfb38 100644 --- a/crates/assert_eq_text/src/lib.rs +++ b/crates/assert_eq_text/src/lib.rs | |||
@@ -1,4 +1,9 @@ | |||
1 | extern crate difference; | 1 | extern crate difference; |
2 | extern crate itertools; | ||
3 | |||
4 | use std::fmt; | ||
5 | use itertools::Itertools; | ||
6 | |||
2 | pub use self::difference::Changeset as __Changeset; | 7 | pub use self::difference::Changeset as __Changeset; |
3 | 8 | ||
4 | #[macro_export] | 9 | #[macro_export] |
@@ -23,3 +28,9 @@ macro_rules! assert_eq_text { | |||
23 | } | 28 | } |
24 | }}; | 29 | }}; |
25 | } | 30 | } |
31 | |||
32 | pub fn assert_eq_dbg(expected: &str, actual: &impl fmt::Debug) { | ||
33 | let actual = format!("{:?}", actual); | ||
34 | let expected = expected.lines().map(|l| l.trim()).join(" "); | ||
35 | assert_eq!(expected, actual); | ||
36 | } | ||
diff --git a/crates/libanalysis/Cargo.toml b/crates/libanalysis/Cargo.toml index 42a5aca14..fa859ff94 100644 --- a/crates/libanalysis/Cargo.toml +++ b/crates/libanalysis/Cargo.toml | |||
@@ -12,3 +12,6 @@ rayon = "1.0.2" | |||
12 | fst = { git = "https://github.com/matklad/fst", branch = "subsequence"} | 12 | fst = { git = "https://github.com/matklad/fst", branch = "subsequence"} |
13 | libsyntax2 = { path = "../libsyntax2" } | 13 | libsyntax2 = { path = "../libsyntax2" } |
14 | libeditor = { path = "../libeditor" } | 14 | libeditor = { path = "../libeditor" } |
15 | |||
16 | [dev-dependencies] | ||
17 | assert_eq_text = { path = "../assert_eq_text" } | ||
diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs index 19b64fece..a50a0f32f 100644 --- a/crates/libanalysis/src/lib.rs +++ b/crates/libanalysis/src/lib.rs | |||
@@ -163,15 +163,21 @@ impl World { | |||
163 | Some(name) => name.text(), | 163 | Some(name) => name.text(), |
164 | None => return Vec::new(), | 164 | None => return Vec::new(), |
165 | }; | 165 | }; |
166 | let id = match self.resolve_relative_path(id, &PathBuf::from(format!("../{}.rs", name))) { | 166 | let paths = &[ |
167 | Some(id) => id, | 167 | PathBuf::from(format!("../{}.rs", name)), |
168 | None => return Vec::new(), | 168 | PathBuf::from(format!("../{}/mod.rs", name)), |
169 | }; | 169 | ]; |
170 | vec![(id, FileSymbol { | 170 | paths.iter() |
171 | name: name.clone(), | 171 | .filter_map(|path| self.resolve_relative_path(id, path)) |
172 | node_range: TextRange::offset_len(0.into(), 0.into()), | 172 | .map(|id| { |
173 | kind: MODULE, | 173 | let symbol = FileSymbol { |
174 | })] | 174 | name: name.clone(), |
175 | node_range: TextRange::offset_len(0.into(), 0.into()), | ||
176 | kind: MODULE, | ||
177 | }; | ||
178 | (id, symbol) | ||
179 | }) | ||
180 | .collect() | ||
175 | } | 181 | } |
176 | 182 | ||
177 | fn resolve_relative_path(&self, id: FileId, path: &Path) -> Option<FileId> { | 183 | fn resolve_relative_path(&self, id: FileId, path: &Path) -> Option<FileId> { |
diff --git a/crates/libanalysis/tests/tests.rs b/crates/libanalysis/tests/tests.rs new file mode 100644 index 000000000..9ef5200af --- /dev/null +++ b/crates/libanalysis/tests/tests.rs | |||
@@ -0,0 +1,45 @@ | |||
1 | extern crate libanalysis; | ||
2 | extern crate assert_eq_text; | ||
3 | |||
4 | use std::path::PathBuf; | ||
5 | |||
6 | use libanalysis::{WorldState, FileId}; | ||
7 | use assert_eq_text::assert_eq_dbg; | ||
8 | |||
9 | |||
10 | #[test] | ||
11 | fn test_resolve_module() { | ||
12 | let mut world = WorldState::new(); | ||
13 | world.change_file(FileId(1), Some("mod foo;".to_string())); | ||
14 | world.change_file(FileId(2), Some("".to_string())); | ||
15 | |||
16 | let snap = world.snapshot(|id, path| { | ||
17 | assert_eq!(id, FileId(1)); | ||
18 | if path == PathBuf::from("../foo/mod.rs") { | ||
19 | return None; | ||
20 | } | ||
21 | assert_eq!(path, PathBuf::from("../foo.rs")); | ||
22 | Some(FileId(2)) | ||
23 | }); | ||
24 | let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into()) | ||
25 | .unwrap(); | ||
26 | assert_eq_dbg( | ||
27 | r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#, | ||
28 | &symbols, | ||
29 | ); | ||
30 | |||
31 | let snap = world.snapshot(|id, path| { | ||
32 | assert_eq!(id, FileId(1)); | ||
33 | if path == PathBuf::from("../foo.rs") { | ||
34 | return None; | ||
35 | } | ||
36 | assert_eq!(path, PathBuf::from("../foo/mod.rs")); | ||
37 | Some(FileId(2)) | ||
38 | }); | ||
39 | let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into()) | ||
40 | .unwrap(); | ||
41 | assert_eq_dbg( | ||
42 | r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#, | ||
43 | &symbols, | ||
44 | ); | ||
45 | } | ||
diff --git a/crates/libeditor/Cargo.toml b/crates/libeditor/Cargo.toml index 502f532a7..7b39870cd 100644 --- a/crates/libeditor/Cargo.toml +++ b/crates/libeditor/Cargo.toml | |||
@@ -10,4 +10,6 @@ superslice = "0.1.0" | |||
10 | 10 | ||
11 | libsyntax2 = { path = "../libsyntax2" } | 11 | libsyntax2 = { path = "../libsyntax2" } |
12 | smol_str = "0.1.0" | 12 | smol_str = "0.1.0" |
13 | |||
14 | [dev-dependencies] | ||
13 | assert_eq_text = { path = "../assert_eq_text" } | 15 | assert_eq_text = { path = "../assert_eq_text" } |
diff --git a/crates/libeditor/tests/test.rs b/crates/libeditor/tests/test.rs index 97919d347..df4cb65d1 100644 --- a/crates/libeditor/tests/test.rs +++ b/crates/libeditor/tests/test.rs | |||
@@ -6,6 +6,7 @@ extern crate assert_eq_text; | |||
6 | 6 | ||
7 | use std::fmt; | 7 | use std::fmt; |
8 | use itertools::Itertools; | 8 | use itertools::Itertools; |
9 | use assert_eq_text::{assert_eq_dbg}; | ||
9 | use libeditor::{ | 10 | use libeditor::{ |
10 | File, TextUnit, TextRange, ActionResult, CursorPosition, | 11 | File, TextUnit, TextRange, ActionResult, CursorPosition, |
11 | highlight, runnables, extend_selection, file_structure, | 12 | highlight, runnables, extend_selection, file_structure, |
@@ -33,7 +34,7 @@ fn main() {} | |||
33 | println!("Hello, {}!", 92); | 34 | println!("Hello, {}!", 92); |
34 | "#); | 35 | "#); |
35 | let hls = highlight(&file); | 36 | let hls = highlight(&file); |
36 | dbg_eq( | 37 | assert_eq_dbg( |
37 | r#"[HighlightedRange { range: [1; 11), tag: "comment" }, | 38 | r#"[HighlightedRange { range: [1; 11), tag: "comment" }, |
38 | HighlightedRange { range: [12; 14), tag: "keyword" }, | 39 | HighlightedRange { range: [12; 14), tag: "keyword" }, |
39 | HighlightedRange { range: [15; 19), tag: "function" }, | 40 | HighlightedRange { range: [15; 19), tag: "function" }, |
@@ -57,7 +58,7 @@ fn test_foo() {} | |||
57 | fn test_foo() {} | 58 | fn test_foo() {} |
58 | "#); | 59 | "#); |
59 | let runnables = runnables(&file); | 60 | let runnables = runnables(&file); |
60 | dbg_eq( | 61 | assert_eq_dbg( |
61 | r#"[Runnable { range: [1; 13), kind: Bin }, | 62 | r#"[Runnable { range: [1; 13), kind: Bin }, |
62 | Runnable { range: [15; 39), kind: Test { name: "test_foo" } }, | 63 | Runnable { range: [15; 39), kind: Test { name: "test_foo" } }, |
63 | Runnable { range: [41; 75), kind: Test { name: "test_foo" } }]"#, | 64 | Runnable { range: [41; 75), kind: Test { name: "test_foo" } }]"#, |
@@ -86,7 +87,7 @@ impl E {} | |||
86 | impl fmt::Debug for E {} | 87 | impl fmt::Debug for E {} |
87 | "#); | 88 | "#); |
88 | let symbols = file_structure(&file); | 89 | let symbols = file_structure(&file); |
89 | dbg_eq( | 90 | assert_eq_dbg( |
90 | r#"[StructureNode { parent: None, label: "Foo", navigation_range: [8; 11), node_range: [1; 26), kind: STRUCT_DEF }, | 91 | r#"[StructureNode { parent: None, label: "Foo", navigation_range: [8; 11), node_range: [1; 26), kind: STRUCT_DEF }, |
91 | StructureNode { parent: Some(0), label: "x", navigation_range: [18; 19), node_range: [18; 24), kind: NAMED_FIELD }, | 92 | StructureNode { parent: Some(0), label: "x", navigation_range: [18; 19), node_range: [18; 24), kind: NAMED_FIELD }, |
92 | StructureNode { parent: None, label: "m", navigation_range: [32; 33), node_range: [28; 53), kind: MODULE }, | 93 | StructureNode { parent: None, label: "m", navigation_range: [32; 33), node_range: [28; 53), kind: MODULE }, |
@@ -147,12 +148,6 @@ fn file(text: &str) -> File { | |||
147 | File::parse(text) | 148 | File::parse(text) |
148 | } | 149 | } |
149 | 150 | ||
150 | fn dbg_eq(expected: &str, actual: &impl fmt::Debug) { | ||
151 | let actual = format!("{:?}", actual); | ||
152 | let expected = expected.lines().map(|l| l.trim()).join(" "); | ||
153 | assert_eq!(expected, actual); | ||
154 | } | ||
155 | |||
156 | fn check_action<F: Fn(&File, TextUnit) -> Option<ActionResult>>( | 151 | fn check_action<F: Fn(&File, TextUnit) -> Option<ActionResult>>( |
157 | before: &str, | 152 | before: &str, |
158 | after: &str, | 153 | after: &str, |
diff --git a/crates/libsyntax2/Cargo.toml b/crates/libsyntax2/Cargo.toml index 78e9e18a2..b55cdf481 100644 --- a/crates/libsyntax2/Cargo.toml +++ b/crates/libsyntax2/Cargo.toml | |||
@@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0" | |||
7 | [dependencies] | 7 | [dependencies] |
8 | unicode-xid = "0.1.0" | 8 | unicode-xid = "0.1.0" |
9 | text_unit = "0.1.2" | 9 | text_unit = "0.1.2" |
10 | itertools = "0.7.5" | 10 | itertools = "0.7.8" |
11 | drop_bomb = "0.1.4" | 11 | drop_bomb = "0.1.4" |
12 | parking_lot = "0.6.0" | 12 | parking_lot = "0.6.0" |
13 | smol_str = "0.1.0" | 13 | smol_str = "0.1.0" |