diff options
Diffstat (limited to 'crates/libanalysis/src')
-rw-r--r-- | crates/libanalysis/src/imp.rs | 11 | ||||
-rw-r--r-- | crates/libanalysis/src/job.rs | 4 | ||||
-rw-r--r-- | crates/libanalysis/src/lib.rs | 8 |
3 files changed, 13 insertions, 10 deletions
diff --git a/crates/libanalysis/src/imp.rs b/crates/libanalysis/src/imp.rs index 97802bd50..6a6e1e933 100644 --- a/crates/libanalysis/src/imp.rs +++ b/crates/libanalysis/src/imp.rs | |||
@@ -23,6 +23,7 @@ use { | |||
23 | module_map::Problem, | 23 | module_map::Problem, |
24 | symbol_index::FileSymbols, | 24 | symbol_index::FileSymbols, |
25 | module_map::{ModuleMap, ChangeKind}, | 25 | module_map::{ModuleMap, ChangeKind}, |
26 | JobToken, | ||
26 | }; | 27 | }; |
27 | 28 | ||
28 | #[derive(Debug)] | 29 | #[derive(Debug)] |
@@ -111,9 +112,10 @@ impl AnalysisImpl { | |||
111 | .clone() | 112 | .clone() |
112 | } | 113 | } |
113 | 114 | ||
114 | pub fn world_symbols(&self, mut query: Query) -> Vec<(FileId, FileSymbol)> { | 115 | pub fn world_symbols(&self, mut query: Query, token: &JobToken) -> Vec<(FileId, FileSymbol)> { |
115 | self.reindex(); | 116 | self.reindex(); |
116 | self.data.file_map.iter() | 117 | self.data.file_map.iter() |
118 | .take_while(move |_| !token.is_canceled()) | ||
117 | .flat_map(move |(id, data)| { | 119 | .flat_map(move |(id, data)| { |
118 | let symbols = data.symbols(); | 120 | let symbols = data.symbols(); |
119 | query.process(symbols).into_iter().map(move |s| (*id, s)) | 121 | query.process(symbols).into_iter().map(move |s| (*id, s)) |
@@ -147,11 +149,12 @@ impl AnalysisImpl { | |||
147 | &self, | 149 | &self, |
148 | id: FileId, | 150 | id: FileId, |
149 | offset: TextUnit, | 151 | offset: TextUnit, |
152 | token: &JobToken, | ||
150 | ) -> Vec<(FileId, FileSymbol)> { | 153 | ) -> Vec<(FileId, FileSymbol)> { |
151 | let file = self.file_syntax(id); | 154 | let file = self.file_syntax(id); |
152 | let syntax = file.syntax(); | 155 | let syntax = file.syntax(); |
153 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) { | 156 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, offset) { |
154 | return self.index_resolve(name_ref); | 157 | return self.index_resolve(name_ref, token); |
155 | } | 158 | } |
156 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) { | 159 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) { |
157 | if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { | 160 | if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { |
@@ -245,12 +248,12 @@ impl AnalysisImpl { | |||
245 | .collect() | 248 | .collect() |
246 | } | 249 | } |
247 | 250 | ||
248 | fn index_resolve(&self, name_ref: ast::NameRef) -> Vec<(FileId, FileSymbol)> { | 251 | fn index_resolve(&self, name_ref: ast::NameRef, token: &JobToken) -> Vec<(FileId, FileSymbol)> { |
249 | let name = name_ref.text(); | 252 | let name = name_ref.text(); |
250 | let mut query = Query::new(name.to_string()); | 253 | let mut query = Query::new(name.to_string()); |
251 | query.exact(); | 254 | query.exact(); |
252 | query.limit(4); | 255 | query.limit(4); |
253 | self.world_symbols(query) | 256 | self.world_symbols(query, token) |
254 | } | 257 | } |
255 | 258 | ||
256 | fn resolve_module(&self, id: FileId, module: ast::Module) -> Vec<FileId> { | 259 | fn resolve_module(&self, id: FileId, module: ast::Module) -> Vec<FileId> { |
diff --git a/crates/libanalysis/src/job.rs b/crates/libanalysis/src/job.rs index 4d393b915..ea1652a26 100644 --- a/crates/libanalysis/src/job.rs +++ b/crates/libanalysis/src/job.rs | |||
@@ -18,8 +18,8 @@ impl JobHandle { | |||
18 | let handle = JobHandle { job_alive: receiver_alive, _job_canceled: sender_canceled }; | 18 | let handle = JobHandle { job_alive: receiver_alive, _job_canceled: sender_canceled }; |
19 | (handle, token) | 19 | (handle, token) |
20 | } | 20 | } |
21 | pub fn is_alive(&self) -> bool { | 21 | pub fn has_completed(&self) -> bool { |
22 | !is_closed(&self.job_alive) | 22 | is_closed(&self.job_alive) |
23 | } | 23 | } |
24 | pub fn cancel(self) { | 24 | pub fn cancel(self) { |
25 | } | 25 | } |
diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs index 20ddb69d6..a59fd1c09 100644 --- a/crates/libanalysis/src/lib.rs +++ b/crates/libanalysis/src/lib.rs | |||
@@ -159,11 +159,11 @@ impl Analysis { | |||
159 | let file = self.file_syntax(file_id); | 159 | let file = self.file_syntax(file_id); |
160 | libeditor::file_structure(&file) | 160 | libeditor::file_structure(&file) |
161 | } | 161 | } |
162 | pub fn symbol_search(&self, query: Query) -> Vec<(FileId, FileSymbol)> { | 162 | pub fn symbol_search(&self, query: Query, token: &JobToken) -> Vec<(FileId, FileSymbol)> { |
163 | self.imp.world_symbols(query) | 163 | self.imp.world_symbols(query, token) |
164 | } | 164 | } |
165 | pub fn approximately_resolve_symbol(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, FileSymbol)> { | 165 | pub fn approximately_resolve_symbol(&self, file_id: FileId, offset: TextUnit, token: &JobToken) -> Vec<(FileId, FileSymbol)> { |
166 | self.imp.approximately_resolve_symbol(file_id, offset) | 166 | self.imp.approximately_resolve_symbol(file_id, offset, token) |
167 | } | 167 | } |
168 | pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> { | 168 | pub fn parent_module(&self, file_id: FileId) -> Vec<(FileId, FileSymbol)> { |
169 | self.imp.parent_module(file_id) | 169 | self.imp.parent_module(file_id) |