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