diff options
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_dot.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_item.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide_api/src/navigation_target.rs | 34 | ||||
-rw-r--r-- | crates/ra_ide_api/src/parent_module.rs | 2 |
6 files changed, 18 insertions, 30 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index bf6d91a09..886dc54d4 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -27,7 +27,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) | |||
27 | for receiver in receiver.autoderef(ctx.db) { | 27 | for receiver in receiver.autoderef(ctx.db) { |
28 | match receiver { | 28 | match receiver { |
29 | Ty::Adt { def_id, .. } => { | 29 | Ty::Adt { def_id, .. } => { |
30 | match def_id.resolve(ctx.db)? { | 30 | match def_id.resolve(ctx.db) { |
31 | Def::Struct(s) => { | 31 | Def::Struct(s) => { |
32 | for field in s.fields(ctx.db) { | 32 | for field in s.fields(ctx.db) { |
33 | CompletionItem::new( | 33 | CompletionItem::new( |
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 6388197be..207a509b3 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -12,7 +12,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C | |||
12 | Some(it) => it, | 12 | Some(it) => it, |
13 | None => return Ok(()), | 13 | None => return Ok(()), |
14 | }; | 14 | }; |
15 | match def_id.resolve(ctx.db)? { | 15 | match def_id.resolve(ctx.db) { |
16 | hir::Def::Module(module) => { | 16 | hir::Def::Module(module) => { |
17 | let module_scope = module.scope(ctx.db)?; | 17 | let module_scope = module.scope(ctx.db)?; |
18 | for (name, res) in module_scope.entries() { | 18 | for (name, res) in module_scope.entries() { |
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index b75d65de3..11d00f78c 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs | |||
@@ -144,7 +144,7 @@ impl Builder { | |||
144 | ctx: &CompletionContext, | 144 | ctx: &CompletionContext, |
145 | resolution: &hir::Resolution, | 145 | resolution: &hir::Resolution, |
146 | ) -> Builder { | 146 | ) -> Builder { |
147 | let resolved = resolution.def_id.and_then(|d| d.resolve(ctx.db).ok()); | 147 | let resolved = resolution.def_id.map(|d| d.resolve(ctx.db)); |
148 | let kind = match resolved { | 148 | let kind = match resolved { |
149 | PerNs { | 149 | PerNs { |
150 | types: Some(hir::Def::Module(..)), | 150 | types: Some(hir::Def::Module(..)), |
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 591f36cce..7229293a4 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -70,7 +70,7 @@ pub(crate) fn reference_definition( | |||
70 | .node_expr(expr) | 70 | .node_expr(expr) |
71 | .and_then(|it| infer_result.method_resolution(it)) | 71 | .and_then(|it| infer_result.method_resolution(it)) |
72 | { | 72 | { |
73 | if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)?)? { | 73 | if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)) { |
74 | return Ok(Exact(target)); | 74 | return Ok(Exact(target)); |
75 | } | 75 | } |
76 | }; | 76 | }; |
@@ -87,7 +87,7 @@ pub(crate) fn reference_definition( | |||
87 | { | 87 | { |
88 | let resolved = module.resolve_path(db, &path)?; | 88 | let resolved = module.resolve_path(db, &path)?; |
89 | if let Some(def_id) = resolved.take_types().or(resolved.take_values()) { | 89 | 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)?)? { | 90 | if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)) { |
91 | return Ok(Exact(target)); | 91 | return Ok(Exact(target)); |
92 | } | 92 | } |
93 | } | 93 | } |
@@ -112,7 +112,7 @@ fn name_definition( | |||
112 | if let Some(child_module) = | 112 | if let Some(child_module) = |
113 | hir::source_binder::module_from_declaration(db, file_id, module) | 113 | hir::source_binder::module_from_declaration(db, file_id, module) |
114 | { | 114 | { |
115 | let nav = NavigationTarget::from_module(db, child_module)?; | 115 | let nav = NavigationTarget::from_module(db, child_module); |
116 | return Ok(Some(vec![nav])); | 116 | return Ok(Some(vec![nav])); |
117 | } | 117 | } |
118 | } | 118 | } |
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs index 965dfc0ca..21c15c0c0 100644 --- a/crates/ra_ide_api/src/navigation_target.rs +++ b/crates/ra_ide_api/src/navigation_target.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use ra_db::{FileId, Cancelable}; | 1 | use ra_db::FileId; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | SyntaxNode, AstNode, SmolStr, TextRange, ast, | 3 | SyntaxNode, AstNode, SmolStr, TextRange, ast, |
4 | SyntaxKind::{self, NAME}, | 4 | SyntaxKind::{self, NAME}, |
@@ -69,47 +69,35 @@ impl NavigationTarget { | |||
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | pub(crate) fn from_module( | 72 | pub(crate) fn from_module(db: &RootDatabase, module: hir::Module) -> NavigationTarget { |
73 | db: &RootDatabase, | ||
74 | module: hir::Module, | ||
75 | ) -> Cancelable<NavigationTarget> { | ||
76 | let (file_id, source) = module.definition_source(db); | 73 | let (file_id, source) = module.definition_source(db); |
77 | let name = module | 74 | let name = module |
78 | .name(db) | 75 | .name(db) |
79 | .map(|it| it.to_string().into()) | 76 | .map(|it| it.to_string().into()) |
80 | .unwrap_or_default(); | 77 | .unwrap_or_default(); |
81 | let res = match source { | 78 | match source { |
82 | ModuleSource::SourceFile(node) => { | 79 | ModuleSource::SourceFile(node) => { |
83 | NavigationTarget::from_syntax(file_id, name, None, node.syntax()) | 80 | NavigationTarget::from_syntax(file_id, name, None, node.syntax()) |
84 | } | 81 | } |
85 | ModuleSource::Module(node) => { | 82 | ModuleSource::Module(node) => { |
86 | NavigationTarget::from_syntax(file_id, name, None, node.syntax()) | 83 | NavigationTarget::from_syntax(file_id, name, None, node.syntax()) |
87 | } | 84 | } |
88 | }; | 85 | } |
89 | Ok(res) | ||
90 | } | 86 | } |
91 | 87 | ||
92 | pub(crate) fn from_module_to_decl( | 88 | pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget { |
93 | db: &RootDatabase, | ||
94 | module: hir::Module, | ||
95 | ) -> Cancelable<NavigationTarget> { | ||
96 | let name = module | 89 | let name = module |
97 | .name(db) | 90 | .name(db) |
98 | .map(|it| it.to_string().into()) | 91 | .map(|it| it.to_string().into()) |
99 | .unwrap_or_default(); | 92 | .unwrap_or_default(); |
100 | if let Some((file_id, source)) = module.declaration_source(db) { | 93 | if let Some((file_id, source)) = module.declaration_source(db) { |
101 | return Ok(NavigationTarget::from_syntax( | 94 | return NavigationTarget::from_syntax(file_id, name, None, source.syntax()); |
102 | file_id, | ||
103 | name, | ||
104 | None, | ||
105 | source.syntax(), | ||
106 | )); | ||
107 | } | 95 | } |
108 | NavigationTarget::from_module(db, module) | 96 | NavigationTarget::from_module(db, module) |
109 | } | 97 | } |
110 | 98 | ||
111 | // TODO once Def::Item is gone, this should be able to always return a NavigationTarget | 99 | // TODO once Def::Item is gone, this should be able to always return a NavigationTarget |
112 | pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Cancelable<Option<NavigationTarget>> { | 100 | pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Option<NavigationTarget> { |
113 | let res = match def { | 101 | let res = match def { |
114 | Def::Struct(s) => { | 102 | Def::Struct(s) => { |
115 | let (file_id, node) = s.source(db); | 103 | let (file_id, node) = s.source(db); |
@@ -124,7 +112,7 @@ impl NavigationTarget { | |||
124 | NavigationTarget::from_named(file_id.original_file(db), &*node) | 112 | NavigationTarget::from_named(file_id.original_file(db), &*node) |
125 | } | 113 | } |
126 | Def::Function(f) => { | 114 | Def::Function(f) => { |
127 | let (file_id, node) = f.source(db)?; | 115 | let (file_id, node) = f.source(db); |
128 | NavigationTarget::from_named(file_id.original_file(db), &*node) | 116 | NavigationTarget::from_named(file_id.original_file(db), &*node) |
129 | } | 117 | } |
130 | Def::Trait(f) => { | 118 | Def::Trait(f) => { |
@@ -143,10 +131,10 @@ impl NavigationTarget { | |||
143 | let (file_id, node) = f.source(db); | 131 | let (file_id, node) = f.source(db); |
144 | NavigationTarget::from_named(file_id.original_file(db), &*node) | 132 | NavigationTarget::from_named(file_id.original_file(db), &*node) |
145 | } | 133 | } |
146 | Def::Module(m) => NavigationTarget::from_module(db, m)?, | 134 | Def::Module(m) => NavigationTarget::from_module(db, m), |
147 | Def::Item => return Ok(None), | 135 | Def::Item => return None, |
148 | }; | 136 | }; |
149 | Ok(Some(res)) | 137 | Some(res) |
150 | } | 138 | } |
151 | 139 | ||
152 | #[cfg(test)] | 140 | #[cfg(test)] |
diff --git a/crates/ra_ide_api/src/parent_module.rs b/crates/ra_ide_api/src/parent_module.rs index 451304739..379b3f3a4 100644 --- a/crates/ra_ide_api/src/parent_module.rs +++ b/crates/ra_ide_api/src/parent_module.rs | |||
@@ -12,7 +12,7 @@ pub(crate) fn parent_module( | |||
12 | None => return Ok(Vec::new()), | 12 | None => return Ok(Vec::new()), |
13 | Some(it) => it, | 13 | Some(it) => it, |
14 | }; | 14 | }; |
15 | let nav = NavigationTarget::from_module_to_decl(db, module)?; | 15 | let nav = NavigationTarget::from_module_to_decl(db, module); |
16 | Ok(vec![nav]) | 16 | Ok(vec![nav]) |
17 | } | 17 | } |
18 | 18 | ||