aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-10-20 20:02:41 +0100
committerAleksey Kladov <[email protected]>2018-10-20 20:02:41 +0100
commit998f2ae7627053a9363a05a1ab79359882dce39f (patch)
tree6be2e60ebae8c03d117edec200aa942d810b3e31 /crates/ra_analysis
parentc4b0d3cd56ab68f4fa23f7c1f6c76f7f6148153e (diff)
remove job tokens
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r--crates/ra_analysis/src/imp.rs16
-rw-r--r--crates/ra_analysis/src/lib.rs44
-rw-r--r--crates/ra_analysis/src/symbol_index.rs5
3 files changed, 30 insertions, 35 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 3a135ef13..4cfb681d8 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -148,14 +148,14 @@ impl AnalysisImpl {
148 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { 148 pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
149 self.root(file_id).lines(file_id) 149 self.root(file_id).lines(file_id)
150 } 150 }
151 pub fn world_symbols(&self, query: Query, token: &JobToken) -> Vec<(FileId, FileSymbol)> { 151 pub fn world_symbols(&self, query: Query) -> Vec<(FileId, FileSymbol)> {
152 let mut buf = Vec::new(); 152 let mut buf = Vec::new();
153 if query.libs { 153 if query.libs {
154 self.data.libs.iter().for_each(|it| it.symbols(&mut buf)); 154 self.data.libs.iter().for_each(|it| it.symbols(&mut buf));
155 } else { 155 } else {
156 self.data.root.symbols(&mut buf); 156 self.data.root.symbols(&mut buf);
157 } 157 }
158 query.search(&buf, token) 158 query.search(&buf)
159 } 159 }
160 pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> { 160 pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> {
161 let root = self.root(file_id); 161 let root = self.root(file_id);
@@ -205,7 +205,6 @@ impl AnalysisImpl {
205 &self, 205 &self,
206 file_id: FileId, 206 file_id: FileId,
207 offset: TextUnit, 207 offset: TextUnit,
208 token: &JobToken,
209 ) -> Vec<(FileId, FileSymbol)> { 208 ) -> Vec<(FileId, FileSymbol)> {
210 let root = self.root(file_id); 209 let root = self.root(file_id);
211 let module_tree = root.module_tree(); 210 let module_tree = root.module_tree();
@@ -227,7 +226,7 @@ impl AnalysisImpl {
227 return vec; 226 return vec;
228 } else { 227 } else {
229 // If that fails try the index based approach. 228 // If that fails try the index based approach.
230 return self.index_resolve(name_ref, token); 229 return self.index_resolve(name_ref);
231 } 230 }
232 } 231 }
233 if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) { 232 if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) {
@@ -258,7 +257,7 @@ impl AnalysisImpl {
258 vec![] 257 vec![]
259 } 258 }
260 259
261 pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, _token: &JobToken) -> Vec<(FileId, TextRange)> { 260 pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, TextRange)> {
262 let root = self.root(file_id); 261 let root = self.root(file_id);
263 let file = root.syntax(file_id); 262 let file = root.syntax(file_id);
264 let syntax = file.syntax(); 263 let syntax = file.syntax();
@@ -380,7 +379,6 @@ impl AnalysisImpl {
380 &self, 379 &self,
381 file_id: FileId, 380 file_id: FileId,
382 offset: TextUnit, 381 offset: TextUnit,
383 token: &JobToken,
384 ) -> Option<(FnDescriptor, Option<usize>)> { 382 ) -> Option<(FnDescriptor, Option<usize>)> {
385 let root = self.root(file_id); 383 let root = self.root(file_id);
386 let file = root.syntax(file_id); 384 let file = root.syntax(file_id);
@@ -391,7 +389,7 @@ impl AnalysisImpl {
391 let name_ref = calling_node.name_ref()?; 389 let name_ref = calling_node.name_ref()?;
392 390
393 // Resolve the function's NameRef (NOTE: this isn't entirely accurate). 391 // Resolve the function's NameRef (NOTE: this isn't entirely accurate).
394 let file_symbols = self.index_resolve(name_ref, token); 392 let file_symbols = self.index_resolve(name_ref);
395 for (_, fs) in file_symbols { 393 for (_, fs) in file_symbols {
396 if fs.kind == FN_DEF { 394 if fs.kind == FN_DEF {
397 if let Some(fn_def) = find_node_at_offset(syntax, fs.node_range.start()) { 395 if let Some(fn_def) = find_node_at_offset(syntax, fs.node_range.start()) {
@@ -442,12 +440,12 @@ impl AnalysisImpl {
442 None 440 None
443 } 441 }
444 442
445 fn index_resolve(&self, name_ref: ast::NameRef, token: &JobToken) -> Vec<(FileId, FileSymbol)> { 443 fn index_resolve(&self, name_ref: ast::NameRef) -> Vec<(FileId, FileSymbol)> {
446 let name = name_ref.text(); 444 let name = name_ref.text();
447 let mut query = Query::new(name.to_string()); 445 let mut query = Query::new(name.to_string());
448 query.exact(); 446 query.exact();
449 query.limit(4); 447 query.limit(4);
450 self.world_symbols(query, token) 448 self.world_symbols(query)
451 } 449 }
452 450
453 fn resolve_module( 451 fn resolve_module(
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 988a45b46..7e9798c29 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -219,47 +219,46 @@ impl Analysis {
219 let file = self.imp.file_syntax(file_id); 219 let file = self.imp.file_syntax(file_id);
220 ra_editor::file_structure(&file) 220 ra_editor::file_structure(&file)
221 } 221 }
222 pub fn symbol_search(&self, query: Query, token: &JobToken) -> Vec<(FileId, FileSymbol)> { 222 pub fn symbol_search(&self, query: Query) -> Vec<(FileId, FileSymbol)> {
223 self.imp.world_symbols(query, token) 223 self.imp.world_symbols(query)
224 } 224 }
225 pub fn approximately_resolve_symbol( 225 pub fn approximately_resolve_symbol(
226 &self, 226 &self,
227 file_id: FileId, 227 file_id: FileId,
228 offset: TextUnit, 228 offset: TextUnit
229 token: &JobToken,
230 ) -> Vec<(FileId, FileSymbol)> { 229 ) -> Vec<(FileId, FileSymbol)> {
231 self.imp 230 self.imp
232 .approximately_resolve_symbol(file_id, offset, token) 231 .approximately_resolve_symbol(file_id, offset)
233 } 232 }
234 pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, token: &JobToken) -> Vec<(FileId, TextRange)> { 233 pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, ) -> Vec<(FileId, TextRange)> {
235 self.imp.find_all_refs(file_id, offset, token) 234 self.imp.find_all_refs(file_id, offset)
236 } 235 }
237 pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> { 236 pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> {
238 self.imp.parent_module(file_id) 237 self.imp.parent_module(file_id)
239 } 238 }
240 pub fn crate_for(&self, file_id: FileId) -> Vec<CrateId> { 239 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
241 self.imp.crate_for(file_id) 240 Ok(self.imp.crate_for(file_id))
242 } 241 }
243 pub fn crate_root(&self, crate_id: CrateId) -> FileId { 242 pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> {
244 self.imp.crate_root(crate_id) 243 Ok(self.imp.crate_root(crate_id))
245 } 244 }
246 pub fn runnables(&self, file_id: FileId) -> Vec<Runnable> { 245 pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> {
247 let file = self.imp.file_syntax(file_id); 246 let file = self.imp.file_syntax(file_id);
248 ra_editor::runnables(&file) 247 Ok(ra_editor::runnables(&file))
249 } 248 }
250 pub fn highlight(&self, file_id: FileId) -> Vec<HighlightedRange> { 249 pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> {
251 let file = self.imp.file_syntax(file_id); 250 let file = self.imp.file_syntax(file_id);
252 ra_editor::highlight(&file) 251 Ok(ra_editor::highlight(&file))
253 } 252 }
254 pub fn completions(&self, file_id: FileId, offset: TextUnit) -> Option<Vec<CompletionItem>> { 253 pub fn completions(&self, file_id: FileId, offset: TextUnit) -> Cancelable<Option<Vec<CompletionItem>>> {
255 let file = self.imp.file_syntax(file_id); 254 let file = self.imp.file_syntax(file_id);
256 ra_editor::scope_completion(&file, offset) 255 Ok(ra_editor::scope_completion(&file, offset))
257 } 256 }
258 pub fn assists(&self, file_id: FileId, range: TextRange) -> Vec<SourceChange> { 257 pub fn assists(&self, file_id: FileId, range: TextRange) -> Cancelable<Vec<SourceChange>> {
259 self.imp.assists(file_id, range) 258 Ok(self.imp.assists(file_id, range))
260 } 259 }
261 pub fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> { 260 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
262 self.imp.diagnostics(file_id) 261 Ok(self.imp.diagnostics(file_id))
263 } 262 }
264 pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> { 263 pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> {
265 let file = self.imp.file_syntax(file_id); 264 let file = self.imp.file_syntax(file_id);
@@ -270,9 +269,8 @@ impl Analysis {
270 &self, 269 &self,
271 file_id: FileId, 270 file_id: FileId,
272 offset: TextUnit, 271 offset: TextUnit,
273 token: &JobToken,
274 ) -> Option<(FnDescriptor, Option<usize>)> { 272 ) -> Option<(FnDescriptor, Option<usize>)> {
275 self.imp.resolve_callable(file_id, offset, token) 273 self.imp.resolve_callable(file_id, offset)
276 } 274 }
277} 275}
278 276
diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs
index 51eef8170..19f9ea47d 100644
--- a/crates/ra_analysis/src/symbol_index.rs
+++ b/crates/ra_analysis/src/symbol_index.rs
@@ -1,4 +1,4 @@
1use crate::{FileId, JobToken, Query}; 1use crate::{FileId, Query};
2use fst::{self, Streamer}; 2use fst::{self, Streamer};
3use ra_editor::{file_symbols, FileSymbol}; 3use ra_editor::{file_symbols, FileSymbol};
4use ra_syntax::{ 4use ra_syntax::{
@@ -59,7 +59,6 @@ impl Query {
59 pub(crate) fn search( 59 pub(crate) fn search(
60 self, 60 self,
61 indices: &[Arc<SymbolIndex>], 61 indices: &[Arc<SymbolIndex>],
62 token: &JobToken,
63 ) -> Vec<(FileId, FileSymbol)> { 62 ) -> Vec<(FileId, FileSymbol)> {
64 let mut op = fst::map::OpBuilder::new(); 63 let mut op = fst::map::OpBuilder::new();
65 for file_symbols in indices.iter() { 64 for file_symbols in indices.iter() {
@@ -69,7 +68,7 @@ impl Query {
69 let mut stream = op.union(); 68 let mut stream = op.union();
70 let mut res = Vec::new(); 69 let mut res = Vec::new();
71 while let Some((_, indexed_values)) = stream.next() { 70 while let Some((_, indexed_values)) = stream.next() {
72 if res.len() >= self.limit || token.is_canceled() { 71 if res.len() >= self.limit {
73 break; 72 break;
74 } 73 }
75 for indexed_value in indexed_values { 74 for indexed_value in indexed_values {