diff options
Diffstat (limited to 'crates/ra_ide_api/src/goto_definition.rs')
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 106 |
1 files changed, 78 insertions, 28 deletions
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 1066bf155..82b5e3b5e 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -20,13 +20,13 @@ pub(crate) fn goto_definition( | |||
20 | position: FilePosition, | 20 | position: FilePosition, |
21 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { | 21 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { |
22 | let parse = db.parse(position.file_id); | 22 | let parse = db.parse(position.file_id); |
23 | let syntax = parse.tree().syntax(); | 23 | let syntax = parse.tree().syntax().clone(); |
24 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { | 24 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(&syntax, position.offset) { |
25 | let navs = reference_definition(db, position.file_id, name_ref).to_vec(); | 25 | let navs = reference_definition(db, position.file_id, &name_ref).to_vec(); |
26 | return Some(RangeInfo::new(name_ref.syntax().range(), navs.to_vec())); | 26 | return Some(RangeInfo::new(name_ref.syntax().range(), navs.to_vec())); |
27 | } | 27 | } |
28 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) { | 28 | if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, position.offset) { |
29 | let navs = name_definition(db, position.file_id, name)?; | 29 | let navs = name_definition(db, position.file_id, &name)?; |
30 | return Some(RangeInfo::new(name.syntax().range(), navs)); | 30 | return Some(RangeInfo::new(name.syntax().range(), navs)); |
31 | } | 31 | } |
32 | None | 32 | None |
@@ -94,7 +94,7 @@ pub(crate) fn name_definition( | |||
94 | ) -> Option<Vec<NavigationTarget>> { | 94 | ) -> Option<Vec<NavigationTarget>> { |
95 | let parent = name.syntax().parent()?; | 95 | let parent = name.syntax().parent()?; |
96 | 96 | ||
97 | if let Some(module) = ast::Module::cast(&parent) { | 97 | if let Some(module) = ast::Module::cast(parent.clone()) { |
98 | if module.has_semi() { | 98 | if module.has_semi() { |
99 | if let Some(child_module) = | 99 | if let Some(child_module) = |
100 | hir::source_binder::module_from_declaration(db, file_id, module) | 100 | hir::source_binder::module_from_declaration(db, file_id, module) |
@@ -114,38 +114,88 @@ pub(crate) fn name_definition( | |||
114 | 114 | ||
115 | fn named_target(file_id: FileId, node: &SyntaxNode) -> Option<NavigationTarget> { | 115 | fn named_target(file_id: FileId, node: &SyntaxNode) -> Option<NavigationTarget> { |
116 | visitor() | 116 | visitor() |
117 | .visit(|node: &ast::StructDef| { | 117 | .visit(|node: ast::StructDef| { |
118 | NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) | 118 | NavigationTarget::from_named( |
119 | file_id, | ||
120 | &node, | ||
121 | node.doc_comment_text(), | ||
122 | node.short_label(), | ||
123 | ) | ||
119 | }) | 124 | }) |
120 | .visit(|node: &ast::EnumDef| { | 125 | .visit(|node: ast::EnumDef| { |
121 | NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) | 126 | NavigationTarget::from_named( |
127 | file_id, | ||
128 | &node, | ||
129 | node.doc_comment_text(), | ||
130 | node.short_label(), | ||
131 | ) | ||
122 | }) | 132 | }) |
123 | .visit(|node: &ast::EnumVariant| { | 133 | .visit(|node: ast::EnumVariant| { |
124 | NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) | 134 | NavigationTarget::from_named( |
135 | file_id, | ||
136 | &node, | ||
137 | node.doc_comment_text(), | ||
138 | node.short_label(), | ||
139 | ) | ||
125 | }) | 140 | }) |
126 | .visit(|node: &ast::FnDef| { | 141 | .visit(|node: ast::FnDef| { |
127 | NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) | 142 | NavigationTarget::from_named( |
143 | file_id, | ||
144 | &node, | ||
145 | node.doc_comment_text(), | ||
146 | node.short_label(), | ||
147 | ) | ||
128 | }) | 148 | }) |
129 | .visit(|node: &ast::TypeAliasDef| { | 149 | .visit(|node: ast::TypeAliasDef| { |
130 | NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) | 150 | NavigationTarget::from_named( |
151 | file_id, | ||
152 | &node, | ||
153 | node.doc_comment_text(), | ||
154 | node.short_label(), | ||
155 | ) | ||
131 | }) | 156 | }) |
132 | .visit(|node: &ast::ConstDef| { | 157 | .visit(|node: ast::ConstDef| { |
133 | NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) | 158 | NavigationTarget::from_named( |
159 | file_id, | ||
160 | &node, | ||
161 | node.doc_comment_text(), | ||
162 | node.short_label(), | ||
163 | ) | ||
134 | }) | 164 | }) |
135 | .visit(|node: &ast::StaticDef| { | 165 | .visit(|node: ast::StaticDef| { |
136 | NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) | 166 | NavigationTarget::from_named( |
167 | file_id, | ||
168 | &node, | ||
169 | node.doc_comment_text(), | ||
170 | node.short_label(), | ||
171 | ) | ||
137 | }) | 172 | }) |
138 | .visit(|node: &ast::TraitDef| { | 173 | .visit(|node: ast::TraitDef| { |
139 | NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) | 174 | NavigationTarget::from_named( |
175 | file_id, | ||
176 | &node, | ||
177 | node.doc_comment_text(), | ||
178 | node.short_label(), | ||
179 | ) | ||
140 | }) | 180 | }) |
141 | .visit(|node: &ast::NamedFieldDef| { | 181 | .visit(|node: ast::NamedFieldDef| { |
142 | NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) | 182 | NavigationTarget::from_named( |
183 | file_id, | ||
184 | &node, | ||
185 | node.doc_comment_text(), | ||
186 | node.short_label(), | ||
187 | ) | ||
143 | }) | 188 | }) |
144 | .visit(|node: &ast::Module| { | 189 | .visit(|node: ast::Module| { |
145 | NavigationTarget::from_named(file_id, node, node.doc_comment_text(), node.short_label()) | 190 | NavigationTarget::from_named( |
191 | file_id, | ||
192 | &node, | ||
193 | node.doc_comment_text(), | ||
194 | node.short_label(), | ||
195 | ) | ||
146 | }) | 196 | }) |
147 | .visit(|node: &ast::MacroCall| { | 197 | .visit(|node: ast::MacroCall| { |
148 | NavigationTarget::from_named(file_id, node, node.doc_comment_text(), None) | 198 | NavigationTarget::from_named(file_id, &node, node.doc_comment_text(), None) |
149 | }) | 199 | }) |
150 | .accept(node) | 200 | .accept(node) |
151 | } | 201 | } |