diff options
Diffstat (limited to 'crates/ra_ide_api/src/goto_definition.rs')
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 185 |
1 files changed, 95 insertions, 90 deletions
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 567d4a674..41a88314f 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -2,12 +2,9 @@ | |||
2 | 2 | ||
3 | use ra_db::{FileId, SourceDatabase}; | 3 | use ra_db::{FileId, SourceDatabase}; |
4 | use ra_syntax::{ | 4 | use ra_syntax::{ |
5 | algo::{ | 5 | algo::find_node_at_offset, |
6 | find_node_at_offset, | ||
7 | visit::{visitor, Visitor}, | ||
8 | }, | ||
9 | ast::{self, DocCommentsOwner}, | 6 | ast::{self, DocCommentsOwner}, |
10 | AstNode, SyntaxNode, | 7 | match_ast, AstNode, SyntaxNode, |
11 | }; | 8 | }; |
12 | 9 | ||
13 | use crate::{ | 10 | use crate::{ |
@@ -114,91 +111,99 @@ pub(crate) fn name_definition( | |||
114 | } | 111 | } |
115 | 112 | ||
116 | fn named_target(file_id: FileId, node: &SyntaxNode) -> Option<NavigationTarget> { | 113 | fn named_target(file_id: FileId, node: &SyntaxNode) -> Option<NavigationTarget> { |
117 | visitor() | 114 | match_ast! { |
118 | .visit(|node: ast::StructDef| { | 115 | match node { |
119 | NavigationTarget::from_named( | 116 | ast::StructDef(it) => { |
120 | file_id, | 117 | Some(NavigationTarget::from_named( |
121 | &node, | 118 | file_id, |
122 | node.doc_comment_text(), | 119 | &it, |
123 | node.short_label(), | 120 | it.doc_comment_text(), |
124 | ) | 121 | it.short_label(), |
125 | }) | 122 | )) |
126 | .visit(|node: ast::EnumDef| { | 123 | }, |
127 | NavigationTarget::from_named( | 124 | ast::EnumDef(it) => { |
128 | file_id, | 125 | Some(NavigationTarget::from_named( |
129 | &node, | 126 | file_id, |
130 | node.doc_comment_text(), | 127 | &it, |
131 | node.short_label(), | 128 | it.doc_comment_text(), |
132 | ) | 129 | it.short_label(), |
133 | }) | 130 | )) |
134 | .visit(|node: ast::EnumVariant| { | 131 | }, |
135 | NavigationTarget::from_named( | 132 | ast::EnumVariant(it) => { |
136 | file_id, | 133 | Some(NavigationTarget::from_named( |
137 | &node, | 134 | file_id, |
138 | node.doc_comment_text(), | 135 | &it, |
139 | node.short_label(), | 136 | it.doc_comment_text(), |
140 | ) | 137 | it.short_label(), |
141 | }) | 138 | )) |
142 | .visit(|node: ast::FnDef| { | 139 | }, |
143 | NavigationTarget::from_named( | 140 | ast::FnDef(it) => { |
144 | file_id, | 141 | Some(NavigationTarget::from_named( |
145 | &node, | 142 | file_id, |
146 | node.doc_comment_text(), | 143 | &it, |
147 | node.short_label(), | 144 | it.doc_comment_text(), |
148 | ) | 145 | it.short_label(), |
149 | }) | 146 | )) |
150 | .visit(|node: ast::TypeAliasDef| { | 147 | }, |
151 | NavigationTarget::from_named( | 148 | ast::TypeAliasDef(it) => { |
152 | file_id, | 149 | Some(NavigationTarget::from_named( |
153 | &node, | 150 | file_id, |
154 | node.doc_comment_text(), | 151 | &it, |
155 | node.short_label(), | 152 | it.doc_comment_text(), |
156 | ) | 153 | it.short_label(), |
157 | }) | 154 | )) |
158 | .visit(|node: ast::ConstDef| { | 155 | }, |
159 | NavigationTarget::from_named( | 156 | ast::ConstDef(it) => { |
160 | file_id, | 157 | Some(NavigationTarget::from_named( |
161 | &node, | 158 | file_id, |
162 | node.doc_comment_text(), | 159 | &it, |
163 | node.short_label(), | 160 | it.doc_comment_text(), |
164 | ) | 161 | it.short_label(), |
165 | }) | 162 | )) |
166 | .visit(|node: ast::StaticDef| { | 163 | }, |
167 | NavigationTarget::from_named( | 164 | ast::StaticDef(it) => { |
168 | file_id, | 165 | Some(NavigationTarget::from_named( |
169 | &node, | 166 | file_id, |
170 | node.doc_comment_text(), | 167 | &it, |
171 | node.short_label(), | 168 | it.doc_comment_text(), |
172 | ) | 169 | it.short_label(), |
173 | }) | 170 | )) |
174 | .visit(|node: ast::TraitDef| { | 171 | }, |
175 | NavigationTarget::from_named( | 172 | ast::TraitDef(it) => { |
176 | file_id, | 173 | Some(NavigationTarget::from_named( |
177 | &node, | 174 | file_id, |
178 | node.doc_comment_text(), | 175 | &it, |
179 | node.short_label(), | 176 | it.doc_comment_text(), |
180 | ) | 177 | it.short_label(), |
181 | }) | 178 | )) |
182 | .visit(|node: ast::RecordFieldDef| { | 179 | }, |
183 | NavigationTarget::from_named( | 180 | ast::RecordFieldDef(it) => { |
184 | file_id, | 181 | Some(NavigationTarget::from_named( |
185 | &node, | 182 | file_id, |
186 | node.doc_comment_text(), | 183 | &it, |
187 | node.short_label(), | 184 | it.doc_comment_text(), |
188 | ) | 185 | it.short_label(), |
189 | }) | 186 | )) |
190 | .visit(|node: ast::Module| { | 187 | }, |
191 | NavigationTarget::from_named( | 188 | ast::Module(it) => { |
192 | file_id, | 189 | Some(NavigationTarget::from_named( |
193 | &node, | 190 | file_id, |
194 | node.doc_comment_text(), | 191 | &it, |
195 | node.short_label(), | 192 | it.doc_comment_text(), |
196 | ) | 193 | it.short_label(), |
197 | }) | 194 | )) |
198 | .visit(|node: ast::MacroCall| { | 195 | }, |
199 | NavigationTarget::from_named(file_id, &node, node.doc_comment_text(), None) | 196 | ast::MacroCall(it) => { |
200 | }) | 197 | Some(NavigationTarget::from_named( |
201 | .accept(node) | 198 | file_id, |
199 | &it, | ||
200 | it.doc_comment_text(), | ||
201 | None, | ||
202 | )) | ||
203 | }, | ||
204 | _ => None, | ||
205 | } | ||
206 | } | ||
202 | } | 207 | } |
203 | 208 | ||
204 | #[cfg(test)] | 209 | #[cfg(test)] |