aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/lib.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-10 12:51:58 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-10 12:51:58 +0000
commitaef93c918e2b6e0b8826e970b00c46f8a5c3aaa9 (patch)
tree0c264c806bb6fabbc31bb785f7ba2b8f16a3b7aa /crates/ra_ide_api/src/lib.rs
parent9225033cdf16fd9f3f38b3d3482efb0c36698085 (diff)
parent495a7ea9f78209435579453b83726e50f339e50e (diff)
Merge #478
478: WIP: implement cancelation via unwinding r=matklad a=matklad This uses https://github.com/salsa-rs/salsa/pull/107 to implement cancellation. Now we can get rid of `Cancelable` wrapper from everywhere except the top-level analyzer library. Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/lib.rs')
-rw-r--r--crates/ra_ide_api/src/lib.rs51
1 files changed, 33 insertions, 18 deletions
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index fbe1421a4..f505959ce 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -35,7 +35,7 @@ use std::{fmt, sync::Arc};
35 35
36use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit}; 36use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit};
37use ra_text_edit::TextEdit; 37use ra_text_edit::TextEdit;
38use ra_db::{SyntaxDatabase, FilesDatabase, LocalSyntaxPtr}; 38use ra_db::{SyntaxDatabase, FilesDatabase, LocalSyntaxPtr, BaseDatabase};
39use rayon::prelude::*; 39use rayon::prelude::*;
40use relative_path::RelativePathBuf; 40use relative_path::RelativePathBuf;
41use rustc_hash::FxHashMap; 41use rustc_hash::FxHashMap;
@@ -420,43 +420,47 @@ impl Analysis {
420 420
421 /// Fuzzy searches for a symbol. 421 /// Fuzzy searches for a symbol.
422 pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> { 422 pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> {
423 let res = symbol_index::world_symbols(&*self.db, query)? 423 self.with_db(|db| {
424 .into_iter() 424 let res = symbol_index::world_symbols(db, query)?
425 .map(NavigationTarget::from_symbol) 425 .into_iter()
426 .collect(); 426 .map(NavigationTarget::from_symbol)
427 Ok(res) 427 .collect::<Vec<_>>();
428 Ok(res)
429 })?
428 } 430 }
429 431
430 pub fn goto_definition( 432 pub fn goto_definition(
431 &self, 433 &self,
432 position: FilePosition, 434 position: FilePosition,
433 ) -> Cancelable<Option<Vec<NavigationTarget>>> { 435 ) -> Cancelable<Option<Vec<NavigationTarget>>> {
434 goto_definition::goto_definition(&*self.db, position) 436 self.db
437 .catch_canceled(|db| goto_definition::goto_definition(db, position))?
435 } 438 }
436 439
437 /// Finds all usages of the reference at point. 440 /// Finds all usages of the reference at point.
438 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { 441 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> {
439 self.db.find_all_refs(position) 442 self.with_db(|db| db.find_all_refs(position))?
440 } 443 }
441 444
442 /// Returns a short text descrbing element at position. 445 /// Returns a short text descrbing element at position.
443 pub fn hover(&self, position: FilePosition) -> Cancelable<Option<RangeInfo<String>>> { 446 pub fn hover(&self, position: FilePosition) -> Cancelable<Option<RangeInfo<String>>> {
444 hover::hover(&*self.db, position) 447 self.with_db(|db| hover::hover(db, position))?
445 } 448 }
446 449
447 /// Computes parameter information for the given call expression. 450 /// Computes parameter information for the given call expression.
448 pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> { 451 pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> {
449 call_info::call_info(&*self.db, position) 452 self.db
453 .catch_canceled(|db| call_info::call_info(db, position))?
450 } 454 }
451 455
452 /// Returns a `mod name;` declaration which created the current module. 456 /// Returns a `mod name;` declaration which created the current module.
453 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { 457 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> {
454 self.db.parent_module(position) 458 self.with_db(|db| db.parent_module(position))?
455 } 459 }
456 460
457 /// Returns crates this file belongs too. 461 /// Returns crates this file belongs too.
458 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { 462 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
459 self.db.crate_for(file_id) 463 self.with_db(|db| db.crate_for(file_id))?
460 } 464 }
461 465
462 /// Returns the root file of the given crate. 466 /// Returns the root file of the given crate.
@@ -466,17 +470,21 @@ impl Analysis {
466 470
467 /// Returns the set of possible targets to run for the current file. 471 /// Returns the set of possible targets to run for the current file.
468 pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> { 472 pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> {
469 runnables::runnables(&*self.db, file_id) 473 self.db
474 .catch_canceled(|db| runnables::runnables(db, file_id))?
470 } 475 }
471 476
472 /// Computes syntax highlighting for the given file. 477 /// Computes syntax highlighting for the given file.
473 pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { 478 pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> {
474 syntax_highlighting::highlight(&*self.db, file_id) 479 self.db
480 .catch_canceled(|db| syntax_highlighting::highlight(db, file_id))?
475 } 481 }
476 482
477 /// Computes completions at the given position. 483 /// Computes completions at the given position.
478 pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { 484 pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> {
479 let completions = completion::completions(&self.db, position)?; 485 let completions = self
486 .db
487 .catch_canceled(|db| completion::completions(db, position))??;
480 Ok(completions.map(|it| it.into())) 488 Ok(completions.map(|it| it.into()))
481 } 489 }
482 490
@@ -488,12 +496,12 @@ impl Analysis {
488 496
489 /// Computes the set of diagnostics for the given file. 497 /// Computes the set of diagnostics for the given file.
490 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { 498 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
491 self.db.diagnostics(file_id) 499 self.with_db(|db| db.diagnostics(file_id))?
492 } 500 }
493 501
494 /// Computes the type of the expression at the given position. 502 /// Computes the type of the expression at the given position.
495 pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { 503 pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> {
496 hover::type_of(&*self.db, frange) 504 self.with_db(|db| hover::type_of(db, frange))?
497 } 505 }
498 506
499 /// Returns the edit required to rename reference at the position to the new 507 /// Returns the edit required to rename reference at the position to the new
@@ -503,7 +511,14 @@ impl Analysis {
503 position: FilePosition, 511 position: FilePosition,
504 new_name: &str, 512 new_name: &str,
505 ) -> Cancelable<Vec<SourceFileEdit>> { 513 ) -> Cancelable<Vec<SourceFileEdit>> {
506 self.db.rename(position, new_name) 514 self.with_db(|db| db.rename(position, new_name))?
515 }
516
517 fn with_db<F: FnOnce(&db::RootDatabase) -> T + std::panic::UnwindSafe, T>(
518 &self,
519 f: F,
520 ) -> Cancelable<T> {
521 self.db.catch_canceled(f)
507 } 522 }
508} 523}
509 524