aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/lib.rs')
-rw-r--r--crates/ra_ide_api/src/lib.rs31
1 files changed, 12 insertions, 19 deletions
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index 0f690fc84..ea5267ad9 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -9,15 +9,6 @@
9//! 9//!
10//! The sibling `ra_ide_api_light` handles thouse bits of IDE functionality 10//! The sibling `ra_ide_api_light` handles thouse bits of IDE functionality
11//! which are restricted to a single file and need only syntax. 11//! which are restricted to a single file and need only syntax.
12macro_rules! ctry {
13 ($expr:expr) => {
14 match $expr {
15 None => return Ok(None),
16 Some(it) => it,
17 }
18 };
19}
20
21mod db; 12mod db;
22mod imp; 13mod imp;
23pub mod mock_analysis; 14pub mod mock_analysis;
@@ -58,9 +49,11 @@ pub use ra_ide_api_light::{
58 LineIndex, LineCol, translate_offset_with_edit, 49 LineIndex, LineCol, translate_offset_with_edit,
59}; 50};
60pub use ra_db::{ 51pub use ra_db::{
61 Cancelable, Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId 52 Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId
62}; 53};
63 54
55pub type Cancelable<T> = Result<T, Canceled>;
56
64#[derive(Default)] 57#[derive(Default)]
65pub struct AnalysisChange { 58pub struct AnalysisChange {
66 new_roots: Vec<(SourceRootId, bool)>, 59 new_roots: Vec<(SourceRootId, bool)>,
@@ -393,28 +386,28 @@ impl Analysis {
393 position: FilePosition, 386 position: FilePosition,
394 ) -> Cancelable<Option<RangeInfo<Vec<NavigationTarget>>>> { 387 ) -> Cancelable<Option<RangeInfo<Vec<NavigationTarget>>>> {
395 self.db 388 self.db
396 .catch_canceled(|db| goto_definition::goto_definition(db, position))? 389 .catch_canceled(|db| goto_definition::goto_definition(db, position))
397 } 390 }
398 391
399 /// Finds all usages of the reference at point. 392 /// Finds all usages of the reference at point.
400 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { 393 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> {
401 self.with_db(|db| db.find_all_refs(position))? 394 self.with_db(|db| db.find_all_refs(position))
402 } 395 }
403 396
404 /// Returns a short text descrbing element at position. 397 /// Returns a short text descrbing element at position.
405 pub fn hover(&self, position: FilePosition) -> Cancelable<Option<RangeInfo<String>>> { 398 pub fn hover(&self, position: FilePosition) -> Cancelable<Option<RangeInfo<String>>> {
406 self.with_db(|db| hover::hover(db, position))? 399 self.with_db(|db| hover::hover(db, position))
407 } 400 }
408 401
409 /// Computes parameter information for the given call expression. 402 /// Computes parameter information for the given call expression.
410 pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> { 403 pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> {
411 self.db 404 self.db
412 .catch_canceled(|db| call_info::call_info(db, position))? 405 .catch_canceled(|db| call_info::call_info(db, position))
413 } 406 }
414 407
415 /// Returns a `mod name;` declaration which created the current module. 408 /// Returns a `mod name;` declaration which created the current module.
416 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { 409 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> {
417 self.with_db(|db| parent_module::parent_module(db, position))? 410 self.with_db(|db| parent_module::parent_module(db, position))
418 } 411 }
419 412
420 /// Returns crates this file belongs too. 413 /// Returns crates this file belongs too.
@@ -430,7 +423,7 @@ impl Analysis {
430 /// Returns the set of possible targets to run for the current file. 423 /// Returns the set of possible targets to run for the current file.
431 pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> { 424 pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> {
432 self.db 425 self.db
433 .catch_canceled(|db| runnables::runnables(db, file_id))? 426 .catch_canceled(|db| runnables::runnables(db, file_id))
434 } 427 }
435 428
436 /// Computes syntax highlighting for the given file. 429 /// Computes syntax highlighting for the given file.
@@ -443,7 +436,7 @@ impl Analysis {
443 pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { 436 pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> {
444 let completions = self 437 let completions = self
445 .db 438 .db
446 .catch_canceled(|db| completion::completions(db, position))??; 439 .catch_canceled(|db| completion::completions(db, position))?;
447 Ok(completions.map(|it| it.into())) 440 Ok(completions.map(|it| it.into()))
448 } 441 }
449 442
@@ -460,7 +453,7 @@ impl Analysis {
460 453
461 /// Computes the type of the expression at the given position. 454 /// Computes the type of the expression at the given position.
462 pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { 455 pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> {
463 self.with_db(|db| hover::type_of(db, frange))? 456 self.with_db(|db| hover::type_of(db, frange))
464 } 457 }
465 458
466 /// Returns the edit required to rename reference at the position to the new 459 /// Returns the edit required to rename reference at the position to the new
@@ -470,7 +463,7 @@ impl Analysis {
470 position: FilePosition, 463 position: FilePosition,
471 new_name: &str, 464 new_name: &str,
472 ) -> Cancelable<Vec<SourceFileEdit>> { 465 ) -> Cancelable<Vec<SourceFileEdit>> {
473 self.with_db(|db| db.rename(position, new_name))? 466 self.with_db(|db| db.rename(position, new_name))
474 } 467 }
475 468
476 fn with_db<F: FnOnce(&db::RootDatabase) -> T + std::panic::UnwindSafe, T>( 469 fn with_db<F: FnOnce(&db::RootDatabase) -> T + std::panic::UnwindSafe, T>(