aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libanalysis/src/lib.rs')
-rw-r--r--crates/libanalysis/src/lib.rs29
1 files changed, 17 insertions, 12 deletions
diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs
index f0d0cf0a4..acaadb8a2 100644
--- a/crates/libanalysis/src/lib.rs
+++ b/crates/libanalysis/src/lib.rs
@@ -89,14 +89,15 @@ impl World {
89 Ok(index.clone()) 89 Ok(index.clone())
90 } 90 }
91 91
92 pub fn world_symbols(&self, query: &str, f: &mut FnMut(&Path, &FileSymbol) -> Search) { 92 pub fn world_symbols<'a>(&'a self, query: &str) -> impl Iterator<Item=(&'a Path, &'a FileSymbol)> + 'a
93 {
93 let q = Query::new(query); 94 let q = Query::new(query);
94 for (path, data) in self.data.file_map.iter() { 95 self.data.file_map.iter()
95 let symbols = data.symbols(path.as_path()); 96 .flat_map(move |(path, data)| {
96 if q.process(symbols, &mut |symbol| f(path, symbol)) == Search::Break { 97 let path: &'a Path = path.as_path();
97 break; 98 let symbols = data.symbols(path);
98 } 99 q.process(symbols).map(move |s| (path, s))
99 } 100 })
100 } 101 }
101 102
102 fn file_data(&self, path: &Path) -> Result<Arc<FileData>> { 103 fn file_data(&self, path: &Path) -> Result<Arc<FileData>> {
@@ -107,11 +108,15 @@ impl World {
107 } 108 }
108} 109}
109 110
110#[derive(Debug, Clone, Copy, PartialEq, Eq)] 111
111pub enum Search { 112pub type SearchResult = ::std::result::Result<Continue, Break>;
112 Continue, 113
113 Break, 114pub struct Continue;
114} 115
116pub struct Break;
117
118pub const CONTINUE: SearchResult = Ok(Continue);
119pub const BREAK: SearchResult = Err(Break);
115 120
116 121
117#[derive(Default, Debug)] 122#[derive(Default, Debug)]