diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-09-15 22:11:25 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-09-15 22:11:25 +0100 |
commit | 3993bb4de95af407e5edc1fe551bec0f001a3f0f (patch) | |
tree | 31893552cd739187080048df24a629d416174305 /crates/libanalysis/tests/tests.rs | |
parent | 2a56b5c4f096736d6795eecb835cc2dc14b00107 (diff) | |
parent | fcdf3a52b4b61a39474950486ea0edf5ebf33bea (diff) |
Merge #67
67: Salsa r=matklad a=matklad
The aim of this PR is to transition from rather ad-hock FileData and ModuleMap caching strategy to something resembling a general-purpose red-green engine.
Ideally, we shouldn't recompute ModuleMap at all, unless the set of mod decls or files changes.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/libanalysis/tests/tests.rs')
-rw-r--r-- | crates/libanalysis/tests/tests.rs | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/crates/libanalysis/tests/tests.rs b/crates/libanalysis/tests/tests.rs index 00efe059c..547f85958 100644 --- a/crates/libanalysis/tests/tests.rs +++ b/crates/libanalysis/tests/tests.rs | |||
@@ -14,24 +14,6 @@ use test_utils::assert_eq_dbg; | |||
14 | #[derive(Debug)] | 14 | #[derive(Debug)] |
15 | struct FileMap(Vec<(FileId, RelativePathBuf)>); | 15 | struct FileMap(Vec<(FileId, RelativePathBuf)>); |
16 | 16 | ||
17 | fn analysis_host(files: &'static [(&'static str, &'static str)]) -> AnalysisHost { | ||
18 | let mut host = AnalysisHost::new(); | ||
19 | let mut file_map = Vec::new(); | ||
20 | for (id, &(path, contents)) in files.iter().enumerate() { | ||
21 | let file_id = FileId((id + 1) as u32); | ||
22 | assert!(path.starts_with('/')); | ||
23 | let path = RelativePathBuf::from_path(&path[1..]).unwrap(); | ||
24 | host.change_file(file_id, Some(contents.to_string())); | ||
25 | file_map.push((file_id, path)); | ||
26 | } | ||
27 | host.set_file_resolver(Arc::new(FileMap(file_map))); | ||
28 | host | ||
29 | } | ||
30 | |||
31 | fn analysis(files: &'static [(&'static str, &'static str)]) -> Analysis { | ||
32 | analysis_host(files).analysis() | ||
33 | } | ||
34 | |||
35 | impl FileMap { | 17 | impl FileMap { |
36 | fn iter<'a>(&'a self) -> impl Iterator<Item=(FileId, &'a RelativePath)> + 'a { | 18 | fn iter<'a>(&'a self) -> impl Iterator<Item=(FileId, &'a RelativePath)> + 'a { |
37 | self.0.iter().map(|(id, path)| (*id, path.as_relative_path())) | 19 | self.0.iter().map(|(id, path)| (*id, path.as_relative_path())) |
@@ -56,6 +38,23 @@ impl FileResolver for FileMap { | |||
56 | } | 38 | } |
57 | } | 39 | } |
58 | 40 | ||
41 | fn analysis_host(files: &'static [(&'static str, &'static str)]) -> AnalysisHost { | ||
42 | let mut host = AnalysisHost::new(); | ||
43 | let mut file_map = Vec::new(); | ||
44 | for (id, &(path, contents)) in files.iter().enumerate() { | ||
45 | let file_id = FileId((id + 1) as u32); | ||
46 | assert!(path.starts_with('/')); | ||
47 | let path = RelativePathBuf::from_path(&path[1..]).unwrap(); | ||
48 | host.change_file(file_id, Some(contents.to_string())); | ||
49 | file_map.push((file_id, path)); | ||
50 | } | ||
51 | host.set_file_resolver(Arc::new(FileMap(file_map))); | ||
52 | host | ||
53 | } | ||
54 | |||
55 | fn analysis(files: &'static [(&'static str, &'static str)]) -> Analysis { | ||
56 | analysis_host(files).analysis() | ||
57 | } | ||
59 | 58 | ||
60 | #[test] | 59 | #[test] |
61 | fn test_resolve_module() { | 60 | fn test_resolve_module() { |