diff options
author | Aleksey Kladov <[email protected]> | 2019-01-10 09:20:32 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-10 09:20:32 +0000 |
commit | 64455ad701c8bce6e35793042f5e2ec177e12f7e (patch) | |
tree | 39bc814aaff25bc5aa6eba5ce02f430811f7285c /crates/ra_ide_api/src | |
parent | cf20ecae9f9572d598c3655f1c5dae35a9f4c548 (diff) |
use unwinding for cancelation
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/db.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 51 |
2 files changed, 37 insertions, 19 deletions
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index 9d46609ec..a2e06f5db 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use std::{fmt, sync::Arc}; | 1 | use std::{fmt, sync::Arc}; |
2 | 2 | ||
3 | use salsa::{self, Database}; | 3 | use salsa::{self, Database}; |
4 | use ra_db::{LocationIntener, BaseDatabase, FileId}; | 4 | use ra_db::{LocationIntener, BaseDatabase, FileId, Canceled}; |
5 | 5 | ||
6 | use crate::{symbol_index, LineIndex}; | 6 | use crate::{symbol_index, LineIndex}; |
7 | 7 | ||
@@ -29,6 +29,9 @@ impl salsa::Database for RootDatabase { | |||
29 | fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { | 29 | fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { |
30 | &self.runtime | 30 | &self.runtime |
31 | } | 31 | } |
32 | fn on_propagated_panic(&self) -> ! { | ||
33 | Canceled::throw() | ||
34 | } | ||
32 | } | 35 | } |
33 | 36 | ||
34 | impl Default for RootDatabase { | 37 | impl Default for RootDatabase { |
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 | ||
36 | use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit}; | 36 | use ra_syntax::{SmolStr, SourceFile, TreePtr, SyntaxKind, TextRange, TextUnit}; |
37 | use ra_text_edit::TextEdit; | 37 | use ra_text_edit::TextEdit; |
38 | use ra_db::{SyntaxDatabase, FilesDatabase, LocalSyntaxPtr}; | 38 | use ra_db::{SyntaxDatabase, FilesDatabase, LocalSyntaxPtr, BaseDatabase}; |
39 | use rayon::prelude::*; | 39 | use rayon::prelude::*; |
40 | use relative_path::RelativePathBuf; | 40 | use relative_path::RelativePathBuf; |
41 | use rustc_hash::FxHashMap; | 41 | use 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 | ||