aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/mock_analysis.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/mock_analysis.rs')
-rw-r--r--crates/ra_ide/src/mock_analysis.rs20
1 files changed, 7 insertions, 13 deletions
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs
index 120d29aa0..db6d50694 100644
--- a/crates/ra_ide/src/mock_analysis.rs
+++ b/crates/ra_ide/src/mock_analysis.rs
@@ -10,8 +10,6 @@ use test_utils::{
10use crate::{ 10use crate::{
11 Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition, FileId, FilePosition, FileRange, 11 Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition, FileId, FilePosition, FileRange,
12}; 12};
13use ra_syntax::TextRange;
14use rustc_hash::FxHashMap;
15 13
16/// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis 14/// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis
17/// from a set of in-memory files. 15/// from a set of in-memory files.
@@ -81,27 +79,23 @@ impl MockAnalysis {
81 .expect("no file in this mock"); 79 .expect("no file in this mock");
82 FileId(idx as u32 + 1) 80 FileId(idx as u32 + 1)
83 } 81 }
84 pub fn annotations(&self) -> FxHashMap<FileId, Vec<(TextRange, String)>> { 82 pub fn annotations(&self) -> Vec<(FileRange, String)> {
85 self.files 83 self.files
86 .iter() 84 .iter()
87 .enumerate() 85 .enumerate()
88 .filter_map(|(idx, fixture)| { 86 .flat_map(|(idx, fixture)| {
89 let file_id = FileId(idx as u32 + 1); 87 let file_id = FileId(idx as u32 + 1);
90 let annotations = extract_annotations(&fixture.text); 88 let annotations = extract_annotations(&fixture.text);
91 if annotations.is_empty() { 89 annotations
92 return None; 90 .into_iter()
93 } 91 .map(move |(range, data)| (FileRange { file_id, range }, data))
94 Some((file_id, annotations))
95 }) 92 })
96 .collect() 93 .collect()
97 } 94 }
98 pub fn annotation(&self) -> (FileRange, String) { 95 pub fn annotation(&self) -> (FileRange, String) {
99 let all = self.annotations(); 96 let mut all = self.annotations();
100 assert_eq!(all.len(), 1); 97 assert_eq!(all.len(), 1);
101 let (file_id, mut for_file) = all.into_iter().next().unwrap(); 98 all.pop().unwrap()
102 assert_eq!(for_file.len(), 1);
103 let (range, data) = for_file.pop().unwrap();
104 (FileRange { file_id, range}, data)
105 } 99 }
106 pub fn analysis_host(self) -> AnalysisHost { 100 pub fn analysis_host(self) -> AnalysisHost {
107 let mut host = AnalysisHost::default(); 101 let mut host = AnalysisHost::default();