diff options
-rw-r--r-- | crates/ra_db/src/cancellation.rs | 2 | ||||
-rw-r--r-- | crates/ra_db/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/call_info.rs | 16 | ||||
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 33 | ||||
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 48 | ||||
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 16 | ||||
-rw-r--r-- | crates/ra_ide_api/src/parent_module.rs | 11 | ||||
-rw-r--r-- | crates/ra_ide_api/src/runnables.rs | 9 |
8 files changed, 61 insertions, 76 deletions
diff --git a/crates/ra_db/src/cancellation.rs b/crates/ra_db/src/cancellation.rs index 32a268553..439080075 100644 --- a/crates/ra_db/src/cancellation.rs +++ b/crates/ra_db/src/cancellation.rs | |||
@@ -21,8 +21,6 @@ pub struct Canceled { | |||
21 | _private: (), | 21 | _private: (), |
22 | } | 22 | } |
23 | 23 | ||
24 | pub type Cancelable<T> = Result<T, Canceled>; | ||
25 | |||
26 | impl Canceled { | 24 | impl Canceled { |
27 | pub(crate) fn new() -> Canceled { | 25 | pub(crate) fn new() -> Canceled { |
28 | Canceled { _private: () } | 26 | Canceled { _private: () } |
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 8473fc050..89113e7a6 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs | |||
@@ -10,7 +10,7 @@ use std::panic; | |||
10 | use ra_syntax::{TextUnit, TextRange, SourceFile, TreeArc}; | 10 | use ra_syntax::{TextUnit, TextRange, SourceFile, TreeArc}; |
11 | 11 | ||
12 | pub use crate::{ | 12 | pub use crate::{ |
13 | cancellation::{Canceled, Cancelable}, | 13 | cancellation::Canceled, |
14 | syntax_ptr::LocalSyntaxPtr, | 14 | syntax_ptr::LocalSyntaxPtr, |
15 | input::{ | 15 | input::{ |
16 | FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency, | 16 | FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency, |
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index efa320d83..18b9508ef 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::cmp::{max, min}; | 1 | use std::cmp::{max, min}; |
2 | 2 | ||
3 | use ra_db::{SyntaxDatabase, Cancelable}; | 3 | use ra_db::SyntaxDatabase; |
4 | use ra_syntax::{ | 4 | use ra_syntax::{ |
5 | AstNode, SyntaxNode, TextUnit, TextRange, | 5 | AstNode, SyntaxNode, TextUnit, TextRange, |
6 | SyntaxKind::FN_DEF, | 6 | SyntaxKind::FN_DEF, |
@@ -11,21 +11,23 @@ use ra_syntax::{ | |||
11 | use crate::{FilePosition, CallInfo, db::RootDatabase}; | 11 | use crate::{FilePosition, CallInfo, db::RootDatabase}; |
12 | 12 | ||
13 | /// Computes parameter information for the given call expression. | 13 | /// Computes parameter information for the given call expression. |
14 | pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Cancelable<Option<CallInfo>> { | 14 | pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo> { |
15 | let file = db.source_file(position.file_id); | 15 | let file = db.source_file(position.file_id); |
16 | let syntax = file.syntax(); | 16 | let syntax = file.syntax(); |
17 | 17 | ||
18 | // Find the calling expression and it's NameRef | 18 | // Find the calling expression and it's NameRef |
19 | let calling_node = ctry!(FnCallNode::with_node(syntax, position.offset)); | 19 | let calling_node = FnCallNode::with_node(syntax, position.offset)?; |
20 | let name_ref = ctry!(calling_node.name_ref()); | 20 | let name_ref = calling_node.name_ref()?; |
21 | 21 | ||
22 | // Resolve the function's NameRef (NOTE: this isn't entirely accurate). | 22 | // Resolve the function's NameRef (NOTE: this isn't entirely accurate). |
23 | let file_symbols = db.index_resolve(name_ref); | 23 | let file_symbols = db.index_resolve(name_ref); |
24 | let symbol = ctry!(file_symbols.into_iter().find(|it| it.ptr.kind() == FN_DEF)); | 24 | let symbol = file_symbols |
25 | .into_iter() | ||
26 | .find(|it| it.ptr.kind() == FN_DEF)?; | ||
25 | let fn_file = db.source_file(symbol.file_id); | 27 | let fn_file = db.source_file(symbol.file_id); |
26 | let fn_def = symbol.ptr.resolve(&fn_file); | 28 | let fn_def = symbol.ptr.resolve(&fn_file); |
27 | let fn_def = ast::FnDef::cast(&fn_def).unwrap(); | 29 | let fn_def = ast::FnDef::cast(&fn_def).unwrap(); |
28 | let mut call_info = ctry!(CallInfo::new(fn_def)); | 30 | let mut call_info = CallInfo::new(fn_def)?; |
29 | // If we have a calling expression let's find which argument we are on | 31 | // If we have a calling expression let's find which argument we are on |
30 | let num_params = call_info.parameters.len(); | 32 | let num_params = call_info.parameters.len(); |
31 | let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some(); | 33 | let has_self = fn_def.param_list().and_then(|l| l.self_param()).is_some(); |
@@ -61,7 +63,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Cancelable | |||
61 | } | 63 | } |
62 | } | 64 | } |
63 | 65 | ||
64 | Ok(Some(call_info)) | 66 | Some(call_info) |
65 | } | 67 | } |
66 | 68 | ||
67 | enum FnCallNode<'a> { | 69 | enum FnCallNode<'a> { |
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index e0f3deb0b..b1becca03 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use ra_db::{FileId, Cancelable, SyntaxDatabase}; | 1 | use ra_db::{FileId, SyntaxDatabase}; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | AstNode, ast, | 3 | AstNode, ast, |
4 | algo::find_node_at_offset, | 4 | algo::find_node_at_offset, |
@@ -9,21 +9,18 @@ use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo}; | |||
9 | pub(crate) fn goto_definition( | 9 | pub(crate) fn goto_definition( |
10 | db: &RootDatabase, | 10 | db: &RootDatabase, |
11 | position: FilePosition, | 11 | position: FilePosition, |
12 | ) -> Cancelable<Option<RangeInfo<Vec<NavigationTarget>>>> { | 12 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { |
13 | let file = db.source_file(position.file_id); | 13 | let file = db.source_file(position.file_id); |
14 | let syntax = file.syntax(); | 14 | let syntax = file.syntax(); |
15 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { | 15 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { |
16 | let navs = reference_definition(db, position.file_id, name_ref)?.to_vec(); | 16 | let navs = reference_definition(db, position.file_id, name_ref).to_vec(); |
17 | return Ok(Some(RangeInfo::new( | 17 | return Some(RangeInfo::new(name_ref.syntax().range(), navs.to_vec())); |
18 | name_ref.syntax().range(), | ||
19 | navs.to_vec(), | ||
20 | ))); | ||
21 | } | 18 | } |
22 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) { | 19 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) { |
23 | let navs = ctry!(name_definition(db, position.file_id, name)?); | 20 | let navs = name_definition(db, position.file_id, name)?; |
24 | return Ok(Some(RangeInfo::new(name.syntax().range(), navs))); | 21 | return Some(RangeInfo::new(name.syntax().range(), navs)); |
25 | } | 22 | } |
26 | Ok(None) | 23 | None |
27 | } | 24 | } |
28 | 25 | ||
29 | pub(crate) enum ReferenceResult { | 26 | pub(crate) enum ReferenceResult { |
@@ -45,7 +42,7 @@ pub(crate) fn reference_definition( | |||
45 | db: &RootDatabase, | 42 | db: &RootDatabase, |
46 | file_id: FileId, | 43 | file_id: FileId, |
47 | name_ref: &ast::NameRef, | 44 | name_ref: &ast::NameRef, |
48 | ) -> Cancelable<ReferenceResult> { | 45 | ) -> ReferenceResult { |
49 | use self::ReferenceResult::*; | 46 | use self::ReferenceResult::*; |
50 | if let Some(function) = | 47 | if let Some(function) = |
51 | hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax()) | 48 | hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax()) |
@@ -54,7 +51,7 @@ pub(crate) fn reference_definition( | |||
54 | // First try to resolve the symbol locally | 51 | // First try to resolve the symbol locally |
55 | if let Some(entry) = scope.resolve_local_name(name_ref) { | 52 | if let Some(entry) = scope.resolve_local_name(name_ref) { |
56 | let nav = NavigationTarget::from_scope_entry(file_id, &entry); | 53 | let nav = NavigationTarget::from_scope_entry(file_id, &entry); |
57 | return Ok(Exact(nav)); | 54 | return Exact(nav); |
58 | }; | 55 | }; |
59 | 56 | ||
60 | // Next check if it is a method | 57 | // Next check if it is a method |
@@ -71,7 +68,7 @@ pub(crate) fn reference_definition( | |||
71 | .and_then(|it| infer_result.method_resolution(it)) | 68 | .and_then(|it| infer_result.method_resolution(it)) |
72 | { | 69 | { |
73 | if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)) { | 70 | if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)) { |
74 | return Ok(Exact(target)); | 71 | return Exact(target); |
75 | } | 72 | } |
76 | }; | 73 | }; |
77 | } | 74 | } |
@@ -88,7 +85,7 @@ pub(crate) fn reference_definition( | |||
88 | let resolved = module.resolve_path(db, &path); | 85 | let resolved = module.resolve_path(db, &path); |
89 | if let Some(def_id) = resolved.take_types().or(resolved.take_values()) { | 86 | if let Some(def_id) = resolved.take_types().or(resolved.take_values()) { |
90 | if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)) { | 87 | if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)) { |
91 | return Ok(Exact(target)); | 88 | return Exact(target); |
92 | } | 89 | } |
93 | } | 90 | } |
94 | } | 91 | } |
@@ -99,25 +96,25 @@ pub(crate) fn reference_definition( | |||
99 | .into_iter() | 96 | .into_iter() |
100 | .map(NavigationTarget::from_symbol) | 97 | .map(NavigationTarget::from_symbol) |
101 | .collect(); | 98 | .collect(); |
102 | Ok(Approximate(navs)) | 99 | Approximate(navs) |
103 | } | 100 | } |
104 | 101 | ||
105 | fn name_definition( | 102 | fn name_definition( |
106 | db: &RootDatabase, | 103 | db: &RootDatabase, |
107 | file_id: FileId, | 104 | file_id: FileId, |
108 | name: &ast::Name, | 105 | name: &ast::Name, |
109 | ) -> Cancelable<Option<Vec<NavigationTarget>>> { | 106 | ) -> Option<Vec<NavigationTarget>> { |
110 | if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { | 107 | if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { |
111 | if module.has_semi() { | 108 | if module.has_semi() { |
112 | if let Some(child_module) = | 109 | if let Some(child_module) = |
113 | hir::source_binder::module_from_declaration(db, file_id, module) | 110 | hir::source_binder::module_from_declaration(db, file_id, module) |
114 | { | 111 | { |
115 | let nav = NavigationTarget::from_module(db, child_module); | 112 | let nav = NavigationTarget::from_module(db, child_module); |
116 | return Ok(Some(vec![nav])); | 113 | return Some(vec![nav]); |
117 | } | 114 | } |
118 | } | 115 | } |
119 | } | 116 | } |
120 | Ok(None) | 117 | None |
121 | } | 118 | } |
122 | 119 | ||
123 | #[cfg(test)] | 120 | #[cfg(test)] |
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 6b5887bda..d91151c15 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use ra_db::{Cancelable, SyntaxDatabase}; | 1 | use ra_db::{SyntaxDatabase}; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | AstNode, SyntaxNode, TreeArc, | 3 | AstNode, SyntaxNode, TreeArc, |
4 | ast::self, | 4 | ast::self, |
@@ -7,19 +7,16 @@ use ra_syntax::{ | |||
7 | 7 | ||
8 | use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget}; | 8 | use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget}; |
9 | 9 | ||
10 | pub(crate) fn hover( | 10 | pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeInfo<String>> { |
11 | db: &RootDatabase, | ||
12 | position: FilePosition, | ||
13 | ) -> Cancelable<Option<RangeInfo<String>>> { | ||
14 | let file = db.source_file(position.file_id); | 11 | let file = db.source_file(position.file_id); |
15 | let mut res = Vec::new(); | 12 | let mut res = Vec::new(); |
16 | 13 | ||
17 | let mut range = None; | 14 | let mut range = None; |
18 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) { | 15 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset) { |
19 | use crate::goto_definition::{ReferenceResult::*, reference_definition}; | 16 | use crate::goto_definition::{ReferenceResult::*, reference_definition}; |
20 | let ref_result = reference_definition(db, position.file_id, name_ref)?; | 17 | let ref_result = reference_definition(db, position.file_id, name_ref); |
21 | match ref_result { | 18 | match ref_result { |
22 | Exact(nav) => res.extend(doc_text_for(db, nav)?), | 19 | Exact(nav) => res.extend(doc_text_for(db, nav)), |
23 | Approximate(navs) => { | 20 | Approximate(navs) => { |
24 | let mut msg = String::from("Failed to exactly resolve the symbol. This is probably because rust_analyzer does not yet support glob imports or traits."); | 21 | let mut msg = String::from("Failed to exactly resolve the symbol. This is probably because rust_analyzer does not yet support glob imports or traits."); |
25 | if !navs.is_empty() { | 22 | if !navs.is_empty() { |
@@ -27,7 +24,7 @@ pub(crate) fn hover( | |||
27 | } | 24 | } |
28 | res.push(msg); | 25 | res.push(msg); |
29 | for nav in navs { | 26 | for nav in navs { |
30 | res.extend(doc_text_for(db, nav)?) | 27 | res.extend(doc_text_for(db, nav)) |
31 | } | 28 | } |
32 | } | 29 | } |
33 | } | 30 | } |
@@ -39,25 +36,24 @@ pub(crate) fn hover( | |||
39 | let node = find_leaf_at_offset(file.syntax(), position.offset).find_map(|leaf| { | 36 | let node = find_leaf_at_offset(file.syntax(), position.offset).find_map(|leaf| { |
40 | leaf.ancestors() | 37 | leaf.ancestors() |
41 | .find(|n| ast::Expr::cast(*n).is_some() || ast::Pat::cast(*n).is_some()) | 38 | .find(|n| ast::Expr::cast(*n).is_some() || ast::Pat::cast(*n).is_some()) |
42 | }); | 39 | })?; |
43 | let node = ctry!(node); | ||
44 | let frange = FileRange { | 40 | let frange = FileRange { |
45 | file_id: position.file_id, | 41 | file_id: position.file_id, |
46 | range: node.range(), | 42 | range: node.range(), |
47 | }; | 43 | }; |
48 | res.extend(type_of(db, frange)?.map(Into::into)); | 44 | res.extend(type_of(db, frange).map(Into::into)); |
49 | range = Some(node.range()); | 45 | range = Some(node.range()); |
50 | }; | 46 | }; |
51 | 47 | ||
52 | let range = ctry!(range); | 48 | let range = range?; |
53 | if res.is_empty() { | 49 | if res.is_empty() { |
54 | return Ok(None); | 50 | return None; |
55 | } | 51 | } |
56 | let res = RangeInfo::new(range, res.join("\n\n---\n")); | 52 | let res = RangeInfo::new(range, res.join("\n\n---\n")); |
57 | Ok(Some(res)) | 53 | Some(res) |
58 | } | 54 | } |
59 | 55 | ||
60 | pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Cancelable<Option<String>> { | 56 | pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> { |
61 | let file = db.source_file(frange.file_id); | 57 | let file = db.source_file(frange.file_id); |
62 | let syntax = file.syntax(); | 58 | let syntax = file.syntax(); |
63 | let leaf_node = find_covering_node(syntax, frange.range); | 59 | let leaf_node = find_covering_node(syntax, frange.range); |
@@ -67,34 +63,28 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Cancelable<Option | |||
67 | .take_while(|it| it.range() == leaf_node.range()) | 63 | .take_while(|it| it.range() == leaf_node.range()) |
68 | .find(|&it| ast::Expr::cast(it).is_some() || ast::Pat::cast(it).is_some()) | 64 | .find(|&it| ast::Expr::cast(it).is_some() || ast::Pat::cast(it).is_some()) |
69 | .unwrap_or(leaf_node); | 65 | .unwrap_or(leaf_node); |
70 | let parent_fn = ctry!(node.ancestors().find_map(ast::FnDef::cast)); | 66 | let parent_fn = node.ancestors().find_map(ast::FnDef::cast)?; |
71 | let function = ctry!(hir::source_binder::function_from_source( | 67 | let function = hir::source_binder::function_from_source(db, frange.file_id, parent_fn)?; |
72 | db, | ||
73 | frange.file_id, | ||
74 | parent_fn | ||
75 | )); | ||
76 | let infer = function.infer(db); | 68 | let infer = function.infer(db); |
77 | let syntax_mapping = function.body_syntax_mapping(db); | 69 | let syntax_mapping = function.body_syntax_mapping(db); |
78 | if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) { | 70 | if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) { |
79 | Ok(Some(infer[expr].to_string())) | 71 | Some(infer[expr].to_string()) |
80 | } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) { | 72 | } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) { |
81 | Ok(Some(infer[pat].to_string())) | 73 | Some(infer[pat].to_string()) |
82 | } else { | 74 | } else { |
83 | Ok(None) | 75 | None |
84 | } | 76 | } |
85 | } | 77 | } |
86 | 78 | ||
87 | // FIXME: this should not really use navigation target. Rather, approximatelly | 79 | // FIXME: this should not really use navigation target. Rather, approximatelly |
88 | // resovled symbol should return a `DefId`. | 80 | // resovled symbol should return a `DefId`. |
89 | fn doc_text_for(db: &RootDatabase, nav: NavigationTarget) -> Cancelable<Option<String>> { | 81 | fn doc_text_for(db: &RootDatabase, nav: NavigationTarget) -> Option<String> { |
90 | let result = match (nav.description(db), nav.docs(db)) { | 82 | match (nav.description(db), nav.docs(db)) { |
91 | (Some(desc), Some(docs)) => Some("```rust\n".to_string() + &*desc + "\n```\n\n" + &*docs), | 83 | (Some(desc), Some(docs)) => Some("```rust\n".to_string() + &*desc + "\n```\n\n" + &*docs), |
92 | (Some(desc), None) => Some("```rust\n".to_string() + &*desc + "\n```"), | 84 | (Some(desc), None) => Some("```rust\n".to_string() + &*desc + "\n```"), |
93 | (None, Some(docs)) => Some(docs), | 85 | (None, Some(docs)) => Some(docs), |
94 | _ => None, | 86 | _ => None, |
95 | }; | 87 | } |
96 | |||
97 | Ok(result) | ||
98 | } | 88 | } |
99 | 89 | ||
100 | impl NavigationTarget { | 90 | impl NavigationTarget { |
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 0f690fc84..f18eb09ae 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs | |||
@@ -58,9 +58,11 @@ pub use ra_ide_api_light::{ | |||
58 | LineIndex, LineCol, translate_offset_with_edit, | 58 | LineIndex, LineCol, translate_offset_with_edit, |
59 | }; | 59 | }; |
60 | pub use ra_db::{ | 60 | pub use ra_db::{ |
61 | Cancelable, Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId | 61 | Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId |
62 | }; | 62 | }; |
63 | 63 | ||
64 | pub type Cancelable<T> = Result<T, Canceled>; | ||
65 | |||
64 | #[derive(Default)] | 66 | #[derive(Default)] |
65 | pub struct AnalysisChange { | 67 | pub struct AnalysisChange { |
66 | new_roots: Vec<(SourceRootId, bool)>, | 68 | new_roots: Vec<(SourceRootId, bool)>, |
@@ -393,7 +395,7 @@ impl Analysis { | |||
393 | position: FilePosition, | 395 | position: FilePosition, |
394 | ) -> Cancelable<Option<RangeInfo<Vec<NavigationTarget>>>> { | 396 | ) -> Cancelable<Option<RangeInfo<Vec<NavigationTarget>>>> { |
395 | self.db | 397 | self.db |
396 | .catch_canceled(|db| goto_definition::goto_definition(db, position))? | 398 | .catch_canceled(|db| goto_definition::goto_definition(db, position)) |
397 | } | 399 | } |
398 | 400 | ||
399 | /// Finds all usages of the reference at point. | 401 | /// Finds all usages of the reference at point. |
@@ -403,18 +405,18 @@ impl Analysis { | |||
403 | 405 | ||
404 | /// Returns a short text descrbing element at position. | 406 | /// Returns a short text descrbing element at position. |
405 | pub fn hover(&self, position: FilePosition) -> Cancelable<Option<RangeInfo<String>>> { | 407 | pub fn hover(&self, position: FilePosition) -> Cancelable<Option<RangeInfo<String>>> { |
406 | self.with_db(|db| hover::hover(db, position))? | 408 | self.with_db(|db| hover::hover(db, position)) |
407 | } | 409 | } |
408 | 410 | ||
409 | /// Computes parameter information for the given call expression. | 411 | /// Computes parameter information for the given call expression. |
410 | pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> { | 412 | pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> { |
411 | self.db | 413 | self.db |
412 | .catch_canceled(|db| call_info::call_info(db, position))? | 414 | .catch_canceled(|db| call_info::call_info(db, position)) |
413 | } | 415 | } |
414 | 416 | ||
415 | /// Returns a `mod name;` declaration which created the current module. | 417 | /// Returns a `mod name;` declaration which created the current module. |
416 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { | 418 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { |
417 | self.with_db(|db| parent_module::parent_module(db, position))? | 419 | self.with_db(|db| parent_module::parent_module(db, position)) |
418 | } | 420 | } |
419 | 421 | ||
420 | /// Returns crates this file belongs too. | 422 | /// Returns crates this file belongs too. |
@@ -430,7 +432,7 @@ impl Analysis { | |||
430 | /// Returns the set of possible targets to run for the current file. | 432 | /// Returns the set of possible targets to run for the current file. |
431 | pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> { | 433 | pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> { |
432 | self.db | 434 | self.db |
433 | .catch_canceled(|db| runnables::runnables(db, file_id))? | 435 | .catch_canceled(|db| runnables::runnables(db, file_id)) |
434 | } | 436 | } |
435 | 437 | ||
436 | /// Computes syntax highlighting for the given file. | 438 | /// Computes syntax highlighting for the given file. |
@@ -460,7 +462,7 @@ impl Analysis { | |||
460 | 462 | ||
461 | /// Computes the type of the expression at the given position. | 463 | /// Computes the type of the expression at the given position. |
462 | pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { | 464 | pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { |
463 | self.with_db(|db| hover::type_of(db, frange))? | 465 | self.with_db(|db| hover::type_of(db, frange)) |
464 | } | 466 | } |
465 | 467 | ||
466 | /// Returns the edit required to rename reference at the position to the new | 468 | /// Returns the edit required to rename reference at the position to the new |
diff --git a/crates/ra_ide_api/src/parent_module.rs b/crates/ra_ide_api/src/parent_module.rs index 379b3f3a4..e94297fe3 100644 --- a/crates/ra_ide_api/src/parent_module.rs +++ b/crates/ra_ide_api/src/parent_module.rs | |||
@@ -1,19 +1,16 @@ | |||
1 | use ra_db::{Cancelable, FilePosition}; | 1 | use ra_db::FilePosition; |
2 | 2 | ||
3 | use crate::{NavigationTarget, db::RootDatabase}; | 3 | use crate::{NavigationTarget, db::RootDatabase}; |
4 | 4 | ||
5 | /// This returns `Vec` because a module may be included from several places. We | 5 | /// This returns `Vec` because a module may be included from several places. We |
6 | /// don't handle this case yet though, so the Vec has length at most one. | 6 | /// don't handle this case yet though, so the Vec has length at most one. |
7 | pub(crate) fn parent_module( | 7 | pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<NavigationTarget> { |
8 | db: &RootDatabase, | ||
9 | position: FilePosition, | ||
10 | ) -> Cancelable<Vec<NavigationTarget>> { | ||
11 | let module = match hir::source_binder::module_from_position(db, position) { | 8 | let module = match hir::source_binder::module_from_position(db, position) { |
12 | None => return Ok(Vec::new()), | 9 | None => return Vec::new(), |
13 | Some(it) => it, | 10 | Some(it) => it, |
14 | }; | 11 | }; |
15 | let nav = NavigationTarget::from_module_to_decl(db, module); | 12 | let nav = NavigationTarget::from_module_to_decl(db, module); |
16 | Ok(vec![nav]) | 13 | vec![nav] |
17 | } | 14 | } |
18 | 15 | ||
19 | #[cfg(test)] | 16 | #[cfg(test)] |
diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs index a3207fdd2..0f9f8deb3 100644 --- a/crates/ra_ide_api/src/runnables.rs +++ b/crates/ra_ide_api/src/runnables.rs | |||
@@ -3,7 +3,7 @@ use ra_syntax::{ | |||
3 | TextRange, SyntaxNode, | 3 | TextRange, SyntaxNode, |
4 | ast::{self, AstNode, NameOwner, ModuleItemOwner}, | 4 | ast::{self, AstNode, NameOwner, ModuleItemOwner}, |
5 | }; | 5 | }; |
6 | use ra_db::{Cancelable, SyntaxDatabase}; | 6 | use ra_db::SyntaxDatabase; |
7 | 7 | ||
8 | use crate::{db::RootDatabase, FileId}; | 8 | use crate::{db::RootDatabase, FileId}; |
9 | 9 | ||
@@ -21,14 +21,13 @@ pub enum RunnableKind { | |||
21 | Bin, | 21 | Bin, |
22 | } | 22 | } |
23 | 23 | ||
24 | pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Cancelable<Vec<Runnable>> { | 24 | pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> { |
25 | let source_file = db.source_file(file_id); | 25 | let source_file = db.source_file(file_id); |
26 | let res = source_file | 26 | source_file |
27 | .syntax() | 27 | .syntax() |
28 | .descendants() | 28 | .descendants() |
29 | .filter_map(|i| runnable(db, file_id, i)) | 29 | .filter_map(|i| runnable(db, file_id, i)) |
30 | .collect(); | 30 | .collect() |
31 | Ok(res) | ||
32 | } | 31 | } |
33 | 32 | ||
34 | fn runnable(db: &RootDatabase, file_id: FileId, item: &SyntaxNode) -> Option<Runnable> { | 33 | fn runnable(db: &RootDatabase, file_id: FileId, item: &SyntaxNode) -> Option<Runnable> { |