diff options
author | Aleksey Kladov <[email protected]> | 2018-08-13 15:19:27 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-13 15:19:27 +0100 |
commit | 5a56ac4b72e7f57fb20d49bcf531611f144cc0e0 (patch) | |
tree | 895b810cdebc1afa199133b17441339fdf4e1ff0 /crates/libanalysis/src/lib.rs | |
parent | 8ae56fa6d0e8a03d6ad75919d6be953f5fc27083 (diff) |
Better limiting
Diffstat (limited to 'crates/libanalysis/src/lib.rs')
-rw-r--r-- | crates/libanalysis/src/lib.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs index 97b6dfca6..562fab290 100644 --- a/crates/libanalysis/src/lib.rs +++ b/crates/libanalysis/src/lib.rs | |||
@@ -94,12 +94,12 @@ impl World { | |||
94 | Ok(index.clone()) | 94 | Ok(index.clone()) |
95 | } | 95 | } |
96 | 96 | ||
97 | pub fn world_symbols<'a>(&'a self, query: Query) -> impl Iterator<Item=(&'a Path, &'a FileSymbol)> + 'a { | 97 | pub fn world_symbols<'a>(&'a self, mut query: Query) -> impl Iterator<Item=(&'a Path, &'a FileSymbol)> + 'a { |
98 | self.data.file_map.iter() | 98 | self.data.file_map.iter() |
99 | .flat_map(move |(path, data)| { | 99 | .flat_map(move |(path, data)| { |
100 | let path: &'a Path = path.as_path(); | 100 | let path: &'a Path = path.as_path(); |
101 | let symbols = data.symbols(path); | 101 | let symbols = data.symbols(); |
102 | query.process(symbols).map(move |s| (path, s)) | 102 | query.process(symbols).into_iter().map(move |s| (path, s)) |
103 | }) | 103 | }) |
104 | } | 104 | } |
105 | 105 | ||
@@ -125,7 +125,8 @@ impl World { | |||
125 | 125 | ||
126 | let mut query = Query::new(name.to_string()); | 126 | let mut query = Query::new(name.to_string()); |
127 | query.exact(); | 127 | query.exact(); |
128 | Ok(self.world_symbols(query).take(4).collect()) | 128 | query.limit(4); |
129 | Ok(self.world_symbols(query).collect()) | ||
129 | } | 130 | } |
130 | 131 | ||
131 | fn file_data(&self, path: &Path) -> Result<Arc<FileData>> { | 132 | fn file_data(&self, path: &Path) -> Result<Arc<FileData>> { |
@@ -178,9 +179,14 @@ impl FileData { | |||
178 | }) | 179 | }) |
179 | } | 180 | } |
180 | 181 | ||
181 | fn symbols(&self, path: &Path) -> &FileSymbols { | 182 | fn syntax_transient(&self) -> ast::File { |
182 | let syntax = self.syntax(path); | 183 | self.syntax.get().map(|s| s.clone()) |
184 | .unwrap_or_else(|| ast::File::parse(&self.text)) | ||
185 | } | ||
186 | |||
187 | fn symbols(&self) -> &FileSymbols { | ||
188 | let syntax = self.syntax_transient(); | ||
183 | self.symbols | 189 | self.symbols |
184 | .get_or_init(|| FileSymbols::new(syntax)) | 190 | .get_or_init(|| FileSymbols::new(&syntax)) |
185 | } | 191 | } |
186 | } | 192 | } |