aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-11 09:20:20 +0000
committerGitHub <[email protected]>2019-11-11 09:20:20 +0000
commit3dff405443e23a551429d224b6a676361cc6574d (patch)
tree07010e39e6d56903fc72c94c1fa8ddb5dd6b9c25 /crates/ra_ide_api/src
parent2ccc45979cd2057bb88e209474698090fb32bb40 (diff)
parent4deba88c33c470f084c531fa979fe5684d37f757 (diff)
Merge #2210
2210: Introduce ToNav trait r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/display.rs2
-rw-r--r--crates/ra_ide_api/src/display/navigation_target.rs328
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs16
-rw-r--r--crates/ra_ide_api/src/goto_type_definition.rs4
-rw-r--r--crates/ra_ide_api/src/impls.rs11
-rw-r--r--crates/ra_ide_api/src/lib.rs4
-rw-r--r--crates/ra_ide_api/src/references.rs12
7 files changed, 200 insertions, 177 deletions
diff --git a/crates/ra_ide_api/src/display.rs b/crates/ra_ide_api/src/display.rs
index a980c56bc..30617412a 100644
--- a/crates/ra_ide_api/src/display.rs
+++ b/crates/ra_ide_api/src/display.rs
@@ -15,7 +15,7 @@ pub use function_signature::FunctionSignature;
15pub use navigation_target::NavigationTarget; 15pub use navigation_target::NavigationTarget;
16pub use structure::{file_structure, StructureNode}; 16pub use structure::{file_structure, StructureNode};
17 17
18pub(crate) use navigation_target::{description_from_symbol, docs_from_symbol}; 18pub(crate) use navigation_target::{description_from_symbol, docs_from_symbol, ToNav};
19pub(crate) use short_label::ShortLabel; 19pub(crate) use short_label::ShortLabel;
20 20
21pub(crate) fn function_label(node: &ast::FnDef) -> String { 21pub(crate) fn function_label(node: &ast::FnDef) -> String {
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs
index 1bf81e7d5..41d467564 100644
--- a/crates/ra_ide_api/src/display/navigation_target.rs
+++ b/crates/ra_ide_api/src/display/navigation_target.rs
@@ -29,19 +29,8 @@ pub struct NavigationTarget {
29 docs: Option<String>, 29 docs: Option<String>,
30} 30}
31 31
32fn find_range_from_node( 32pub(crate) trait ToNav {
33 db: &RootDatabase, 33 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget;
34 src: hir::HirFileId,
35 node: &SyntaxNode,
36) -> (FileId, TextRange) {
37 let text_range = node.text_range();
38 let (file_id, text_range) = src
39 .expansion_info(db)
40 .and_then(|expansion_info| expansion_info.find_range(text_range))
41 .unwrap_or((src, text_range));
42
43 // FIXME: handle recursive macro generated macro
44 (file_id.original_file(db), text_range)
45} 34}
46 35
47impl NavigationTarget { 36impl NavigationTarget {
@@ -95,19 +84,6 @@ impl NavigationTarget {
95 NavigationTarget::from_named(db, file_id.into(), pat, None, None) 84 NavigationTarget::from_named(db, file_id.into(), pat, None, None)
96 } 85 }
97 86
98 pub(crate) fn from_symbol(db: &RootDatabase, symbol: FileSymbol) -> NavigationTarget {
99 NavigationTarget {
100 file_id: symbol.file_id,
101 name: symbol.name.clone(),
102 kind: symbol.ptr.kind(),
103 full_range: symbol.ptr.range(),
104 focus_range: symbol.name_range,
105 container_name: symbol.container_name.clone(),
106 description: description_from_symbol(db, &symbol),
107 docs: docs_from_symbol(db, &symbol),
108 }
109 }
110
111 pub(crate) fn from_pat( 87 pub(crate) fn from_pat(
112 db: &RootDatabase, 88 db: &RootDatabase,
113 file_id: FileId, 89 file_id: FileId,
@@ -136,39 +112,6 @@ impl NavigationTarget {
136 } 112 }
137 } 113 }
138 114
139 pub(crate) fn from_module(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
140 let src = module.definition_source(db);
141 let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default();
142 match src.ast {
143 ModuleSource::SourceFile(node) => {
144 let (file_id, text_range) = find_range_from_node(db, src.file_id, node.syntax());
145
146 NavigationTarget::from_syntax(
147 file_id,
148 name,
149 None,
150 text_range,
151 node.syntax(),
152 None,
153 None,
154 )
155 }
156 ModuleSource::Module(node) => {
157 let (file_id, text_range) = find_range_from_node(db, src.file_id, node.syntax());
158
159 NavigationTarget::from_syntax(
160 file_id,
161 name,
162 None,
163 text_range,
164 node.syntax(),
165 node.doc_comment_text(),
166 node.short_label(),
167 )
168 }
169 }
170 }
171
172 pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget { 115 pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
173 let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default(); 116 let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default();
174 if let Some(src) = module.declaration_source(db) { 117 if let Some(src) = module.declaration_source(db) {
@@ -183,55 +126,7 @@ impl NavigationTarget {
183 src.ast.short_label(), 126 src.ast.short_label(),
184 ); 127 );
185 } 128 }
186 NavigationTarget::from_module(db, module) 129 module.to_nav(db)
187 }
188
189 pub(crate) fn from_field(db: &RootDatabase, field: hir::StructField) -> NavigationTarget {
190 let src = field.source(db);
191 match src.ast {
192 FieldSource::Named(it) => NavigationTarget::from_named(
193 db,
194 src.file_id,
195 &it,
196 it.doc_comment_text(),
197 it.short_label(),
198 ),
199 FieldSource::Pos(it) => {
200 let (file_id, text_range) = find_range_from_node(db, src.file_id, it.syntax());
201 NavigationTarget::from_syntax(
202 file_id,
203 "".into(),
204 None,
205 text_range,
206 it.syntax(),
207 None,
208 None,
209 )
210 }
211 }
212 }
213
214 pub(crate) fn from_def_source<A, D>(db: &RootDatabase, def: D) -> NavigationTarget
215 where
216 D: HasSource<Ast = A>,
217 A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel,
218 {
219 let src = def.source(db);
220 NavigationTarget::from_named(
221 db,
222 src.file_id,
223 &src.ast,
224 src.ast.doc_comment_text(),
225 src.ast.short_label(),
226 )
227 }
228
229 pub(crate) fn from_adt_def(db: &RootDatabase, adt_def: hir::Adt) -> NavigationTarget {
230 match adt_def {
231 hir::Adt::Struct(it) => NavigationTarget::from_def_source(db, it),
232 hir::Adt::Union(it) => NavigationTarget::from_def_source(db, it),
233 hir::Adt::Enum(it) => NavigationTarget::from_def_source(db, it),
234 }
235 } 130 }
236 131
237 pub(crate) fn from_def( 132 pub(crate) fn from_def(
@@ -239,14 +134,14 @@ impl NavigationTarget {
239 module_def: hir::ModuleDef, 134 module_def: hir::ModuleDef,
240 ) -> Option<NavigationTarget> { 135 ) -> Option<NavigationTarget> {
241 let nav = match module_def { 136 let nav = match module_def {
242 hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module), 137 hir::ModuleDef::Module(module) => module.to_nav(db),
243 hir::ModuleDef::Function(func) => NavigationTarget::from_def_source(db, func), 138 hir::ModuleDef::Function(it) => it.to_nav(db),
244 hir::ModuleDef::Adt(it) => NavigationTarget::from_adt_def(db, it), 139 hir::ModuleDef::Adt(it) => it.to_nav(db),
245 hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it), 140 hir::ModuleDef::Const(it) => it.to_nav(db),
246 hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it), 141 hir::ModuleDef::Static(it) => it.to_nav(db),
247 hir::ModuleDef::EnumVariant(it) => NavigationTarget::from_def_source(db, it), 142 hir::ModuleDef::EnumVariant(it) => it.to_nav(db),
248 hir::ModuleDef::Trait(it) => NavigationTarget::from_def_source(db, it), 143 hir::ModuleDef::Trait(it) => it.to_nav(db),
249 hir::ModuleDef::TypeAlias(it) => NavigationTarget::from_def_source(db, it), 144 hir::ModuleDef::TypeAlias(it) => it.to_nav(db),
250 hir::ModuleDef::BuiltinType(..) => { 145 hir::ModuleDef::BuiltinType(..) => {
251 return None; 146 return None;
252 } 147 }
@@ -254,41 +149,6 @@ impl NavigationTarget {
254 Some(nav) 149 Some(nav)
255 } 150 }
256 151
257 pub(crate) fn from_impl_block(
258 db: &RootDatabase,
259 impl_block: hir::ImplBlock,
260 ) -> NavigationTarget {
261 let src = impl_block.source(db);
262 let (file_id, text_range) = find_range_from_node(db, src.file_id, src.ast.syntax());
263
264 NavigationTarget::from_syntax(
265 file_id,
266 "impl".into(),
267 None,
268 text_range,
269 src.ast.syntax(),
270 None,
271 None,
272 )
273 }
274
275 pub(crate) fn from_assoc_item(
276 db: &RootDatabase,
277 assoc_item: hir::AssocItem,
278 ) -> NavigationTarget {
279 match assoc_item {
280 AssocItem::Function(it) => NavigationTarget::from_def_source(db, it),
281 AssocItem::Const(it) => NavigationTarget::from_def_source(db, it),
282 AssocItem::TypeAlias(it) => NavigationTarget::from_def_source(db, it),
283 }
284 }
285
286 pub(crate) fn from_macro_def(db: &RootDatabase, macro_call: hir::MacroDef) -> NavigationTarget {
287 let src = macro_call.source(db);
288 log::debug!("nav target {:#?}", src.ast.syntax());
289 NavigationTarget::from_named(db, src.file_id, &src.ast, src.ast.doc_comment_text(), None)
290 }
291
292 #[cfg(test)] 152 #[cfg(test)]
293 pub(crate) fn assert_match(&self, expected: &str) { 153 pub(crate) fn assert_match(&self, expected: &str) {
294 let actual = self.debug_render(); 154 let actual = self.debug_render();
@@ -359,6 +219,172 @@ impl NavigationTarget {
359 } 219 }
360} 220}
361 221
222impl ToNav for FileSymbol {
223 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
224 NavigationTarget {
225 file_id: self.file_id,
226 name: self.name.clone(),
227 kind: self.ptr.kind(),
228 full_range: self.ptr.range(),
229 focus_range: self.name_range,
230 container_name: self.container_name.clone(),
231 description: description_from_symbol(db, self),
232 docs: docs_from_symbol(db, self),
233 }
234 }
235}
236
237pub(crate) trait ToNavFromAst {}
238impl ToNavFromAst for hir::Function {}
239impl ToNavFromAst for hir::Const {}
240impl ToNavFromAst for hir::Static {}
241impl ToNavFromAst for hir::Struct {}
242impl ToNavFromAst for hir::Enum {}
243impl ToNavFromAst for hir::EnumVariant {}
244impl ToNavFromAst for hir::Union {}
245impl ToNavFromAst for hir::TypeAlias {}
246impl ToNavFromAst for hir::Trait {}
247
248impl<D> ToNav for D
249where
250 D: HasSource + ToNavFromAst + Copy,
251 D::Ast: ast::DocCommentsOwner + ast::NameOwner + ShortLabel,
252{
253 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
254 let src = self.source(db);
255 NavigationTarget::from_named(
256 db,
257 src.file_id,
258 &src.ast,
259 src.ast.doc_comment_text(),
260 src.ast.short_label(),
261 )
262 }
263}
264
265impl ToNav for hir::Module {
266 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
267 let src = self.definition_source(db);
268 let name = self.name(db).map(|it| it.to_string().into()).unwrap_or_default();
269 match src.ast {
270 ModuleSource::SourceFile(node) => {
271 let (file_id, text_range) = find_range_from_node(db, src.file_id, node.syntax());
272
273 NavigationTarget::from_syntax(
274 file_id,
275 name,
276 None,
277 text_range,
278 node.syntax(),
279 None,
280 None,
281 )
282 }
283 ModuleSource::Module(node) => {
284 let (file_id, text_range) = find_range_from_node(db, src.file_id, node.syntax());
285
286 NavigationTarget::from_syntax(
287 file_id,
288 name,
289 None,
290 text_range,
291 node.syntax(),
292 node.doc_comment_text(),
293 node.short_label(),
294 )
295 }
296 }
297 }
298}
299
300impl ToNav for hir::ImplBlock {
301 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
302 let src = self.source(db);
303 let (file_id, text_range) = find_range_from_node(db, src.file_id, src.ast.syntax());
304
305 NavigationTarget::from_syntax(
306 file_id,
307 "impl".into(),
308 None,
309 text_range,
310 src.ast.syntax(),
311 None,
312 None,
313 )
314 }
315}
316
317impl ToNav for hir::StructField {
318 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
319 let src = self.source(db);
320
321 match src.ast {
322 FieldSource::Named(it) => NavigationTarget::from_named(
323 db,
324 src.file_id,
325 &it,
326 it.doc_comment_text(),
327 it.short_label(),
328 ),
329 FieldSource::Pos(it) => {
330 let (file_id, text_range) = find_range_from_node(db, src.file_id, it.syntax());
331 NavigationTarget::from_syntax(
332 file_id,
333 "".into(),
334 None,
335 text_range,
336 it.syntax(),
337 None,
338 None,
339 )
340 }
341 }
342 }
343}
344
345impl ToNav for hir::MacroDef {
346 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
347 let src = self.source(db);
348 log::debug!("nav target {:#?}", src.ast.syntax());
349 NavigationTarget::from_named(db, src.file_id, &src.ast, src.ast.doc_comment_text(), None)
350 }
351}
352
353impl ToNav for hir::Adt {
354 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
355 match self {
356 hir::Adt::Struct(it) => it.to_nav(db),
357 hir::Adt::Union(it) => it.to_nav(db),
358 hir::Adt::Enum(it) => it.to_nav(db),
359 }
360 }
361}
362
363impl ToNav for hir::AssocItem {
364 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
365 match self {
366 AssocItem::Function(it) => it.to_nav(db),
367 AssocItem::Const(it) => it.to_nav(db),
368 AssocItem::TypeAlias(it) => it.to_nav(db),
369 }
370 }
371}
372
373fn find_range_from_node(
374 db: &RootDatabase,
375 src: hir::HirFileId,
376 node: &SyntaxNode,
377) -> (FileId, TextRange) {
378 let text_range = node.text_range();
379 let (file_id, text_range) = src
380 .expansion_info(db)
381 .and_then(|expansion_info| expansion_info.find_range(text_range))
382 .unwrap_or((src, text_range));
383
384 // FIXME: handle recursive macro generated macro
385 (file_id.original_file(db), text_range)
386}
387
362pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> { 388pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> {
363 let parse = db.parse(symbol.file_id); 389 let parse = db.parse(symbol.file_id);
364 let node = symbol.ptr.to_node(parse.tree().syntax()); 390 let node = symbol.ptr.to_node(parse.tree().syntax());
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index afa59cbe3..713b61d5e 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -9,7 +9,7 @@ use ra_syntax::{
9 9
10use crate::{ 10use crate::{
11 db::RootDatabase, 11 db::RootDatabase,
12 display::ShortLabel, 12 display::{ShortLabel, ToNav},
13 references::{classify_name_ref, NameKind::*}, 13 references::{classify_name_ref, NameKind::*},
14 FilePosition, NavigationTarget, RangeInfo, 14 FilePosition, NavigationTarget, RangeInfo,
15}; 15};
@@ -56,16 +56,16 @@ pub(crate) fn reference_definition(
56 56
57 let name_kind = classify_name_ref(db, file_id, &name_ref).map(|d| d.kind); 57 let name_kind = classify_name_ref(db, file_id, &name_ref).map(|d| d.kind);
58 match name_kind { 58 match name_kind {
59 Some(Macro(mac)) => return Exact(NavigationTarget::from_macro_def(db, mac)), 59 Some(Macro(mac)) => return Exact(mac.to_nav(db)),
60 Some(Field(field)) => return Exact(NavigationTarget::from_field(db, field)), 60 Some(Field(field)) => return Exact(field.to_nav(db)),
61 Some(AssocItem(assoc)) => return Exact(NavigationTarget::from_assoc_item(db, assoc)), 61 Some(AssocItem(assoc)) => return Exact(assoc.to_nav(db)),
62 Some(Def(def)) => match NavigationTarget::from_def(db, def) { 62 Some(Def(def)) => match NavigationTarget::from_def(db, def) {
63 Some(nav) => return Exact(nav), 63 Some(nav) => return Exact(nav),
64 None => return Approximate(vec![]), 64 None => return Approximate(vec![]),
65 }, 65 },
66 Some(SelfType(ty)) => { 66 Some(SelfType(ty)) => {
67 if let Some((def_id, _)) = ty.as_adt() { 67 if let Some((adt, _)) = ty.as_adt() {
68 return Exact(NavigationTarget::from_adt_def(db, def_id)); 68 return Exact(adt.to_nav(db));
69 } 69 }
70 } 70 }
71 Some(Pat((_, pat))) => return Exact(NavigationTarget::from_pat(db, file_id, pat)), 71 Some(Pat((_, pat))) => return Exact(NavigationTarget::from_pat(db, file_id, pat)),
@@ -79,7 +79,7 @@ pub(crate) fn reference_definition(
79 // Fallback index based approach: 79 // Fallback index based approach:
80 let navs = crate::symbol_index::index_resolve(db, name_ref) 80 let navs = crate::symbol_index::index_resolve(db, name_ref)
81 .into_iter() 81 .into_iter()
82 .map(|s| NavigationTarget::from_symbol(db, s)) 82 .map(|s| s.to_nav(db))
83 .collect(); 83 .collect();
84 Approximate(navs) 84 Approximate(navs)
85} 85}
@@ -95,7 +95,7 @@ pub(crate) fn name_definition(
95 if module.has_semi() { 95 if module.has_semi() {
96 let src = hir::Source { file_id: file_id.into(), ast: module }; 96 let src = hir::Source { file_id: file_id.into(), ast: module };
97 if let Some(child_module) = hir::Module::from_declaration(db, src) { 97 if let Some(child_module) = hir::Module::from_declaration(db, src) {
98 let nav = NavigationTarget::from_module(db, child_module); 98 let nav = child_module.to_nav(db);
99 return Some(vec![nav]); 99 return Some(vec![nav]);
100 } 100 }
101 } 101 }
diff --git a/crates/ra_ide_api/src/goto_type_definition.rs b/crates/ra_ide_api/src/goto_type_definition.rs
index 059d80524..71146591d 100644
--- a/crates/ra_ide_api/src/goto_type_definition.rs
+++ b/crates/ra_ide_api/src/goto_type_definition.rs
@@ -3,7 +3,7 @@
3use ra_db::SourceDatabase; 3use ra_db::SourceDatabase;
4use ra_syntax::{ast, AstNode}; 4use ra_syntax::{ast, AstNode};
5 5
6use crate::{db::RootDatabase, FilePosition, NavigationTarget, RangeInfo}; 6use crate::{db::RootDatabase, display::ToNav, FilePosition, NavigationTarget, RangeInfo};
7 7
8pub(crate) fn goto_type_definition( 8pub(crate) fn goto_type_definition(
9 db: &RootDatabase, 9 db: &RootDatabase,
@@ -33,7 +33,7 @@ pub(crate) fn goto_type_definition(
33 33
34 let adt_def = analyzer.autoderef(db, ty).find_map(|ty| ty.as_adt().map(|adt| adt.0))?; 34 let adt_def = analyzer.autoderef(db, ty).find_map(|ty| ty.as_adt().map(|adt| adt.0))?;
35 35
36 let nav = NavigationTarget::from_adt_def(db, adt_def); 36 let nav = adt_def.to_nav(db);
37 Some(RangeInfo::new(node.text_range(), vec![nav])) 37 Some(RangeInfo::new(node.text_range(), vec![nav]))
38} 38}
39 39
diff --git a/crates/ra_ide_api/src/impls.rs b/crates/ra_ide_api/src/impls.rs
index b899ed3a5..bc9b66550 100644
--- a/crates/ra_ide_api/src/impls.rs
+++ b/crates/ra_ide_api/src/impls.rs
@@ -4,7 +4,7 @@ use hir::{db::HirDatabase, ApplicationTy, FromSource, Ty, TypeCtor};
4use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
5use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; 5use ra_syntax::{algo::find_node_at_offset, ast, AstNode};
6 6
7use crate::{db::RootDatabase, FilePosition, NavigationTarget, RangeInfo}; 7use crate::{db::RootDatabase, display::ToNav, FilePosition, NavigationTarget, RangeInfo};
8 8
9pub(crate) fn goto_implementation( 9pub(crate) fn goto_implementation(
10 db: &RootDatabase, 10 db: &RootDatabase,
@@ -58,7 +58,7 @@ fn impls_for_def(
58 impls 58 impls
59 .all_impls() 59 .all_impls()
60 .filter(|impl_block| is_equal_for_find_impls(&ty, &impl_block.target_ty(db))) 60 .filter(|impl_block| is_equal_for_find_impls(&ty, &impl_block.target_ty(db)))
61 .map(|imp| NavigationTarget::from_impl_block(db, imp)) 61 .map(|imp| imp.to_nav(db))
62 .collect(), 62 .collect(),
63 ) 63 )
64} 64}
@@ -75,12 +75,7 @@ fn impls_for_trait(
75 let krate = module.krate(); 75 let krate = module.krate();
76 let impls = db.impls_in_crate(krate); 76 let impls = db.impls_in_crate(krate);
77 77
78 Some( 78 Some(impls.lookup_impl_blocks_for_trait(tr).map(|imp| imp.to_nav(db)).collect())
79 impls
80 .lookup_impl_blocks_for_trait(tr)
81 .map(|imp| NavigationTarget::from_impl_block(db, imp))
82 .collect(),
83 )
84} 79}
85 80
86fn is_equal_for_find_impls(original_ty: &Ty, impl_ty: &Ty) -> bool { 81fn is_equal_for_find_impls(original_ty: &Ty, impl_ty: &Ty) -> bool {
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index d0188da44..484fbcc82 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -56,7 +56,7 @@ use ra_db::{
56}; 56};
57use ra_syntax::{SourceFile, TextRange, TextUnit}; 57use ra_syntax::{SourceFile, TextRange, TextUnit};
58 58
59use crate::{db::LineIndexDatabase, symbol_index::FileSymbol}; 59use crate::{db::LineIndexDatabase, display::ToNav, symbol_index::FileSymbol};
60 60
61pub use crate::{ 61pub use crate::{
62 assists::{Assist, AssistId}, 62 assists::{Assist, AssistId},
@@ -351,7 +351,7 @@ impl Analysis {
351 self.with_db(|db| { 351 self.with_db(|db| {
352 symbol_index::world_symbols(db, query) 352 symbol_index::world_symbols(db, query)
353 .into_iter() 353 .into_iter()
354 .map(|s| NavigationTarget::from_symbol(db, s)) 354 .map(|s| s.to_nav(db))
355 .collect::<Vec<_>>() 355 .collect::<Vec<_>>()
356 }) 356 })
357 } 357 }
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs
index b5b1c9a16..0a76bf484 100644
--- a/crates/ra_ide_api/src/references.rs
+++ b/crates/ra_ide_api/src/references.rs
@@ -19,7 +19,9 @@ use ra_db::{SourceDatabase, SourceDatabaseExt};
19use ra_prof::profile; 19use ra_prof::profile;
20use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SourceFile, SyntaxNode, TextUnit}; 20use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SourceFile, SyntaxNode, TextUnit};
21 21
22use crate::{db::RootDatabase, FilePosition, FileRange, NavigationTarget, RangeInfo}; 22use crate::{
23 db::RootDatabase, display::ToNav, FilePosition, FileRange, NavigationTarget, RangeInfo,
24};
23 25
24pub(crate) use self::{ 26pub(crate) use self::{
25 classify::{classify_name, classify_name_ref}, 27 classify::{classify_name, classify_name_ref},
@@ -76,12 +78,12 @@ pub(crate) fn find_all_refs(
76 let RangeInfo { range, info: (name, def) } = find_name(db, &syntax, position)?; 78 let RangeInfo { range, info: (name, def) } = find_name(db, &syntax, position)?;
77 79
78 let declaration = match def.kind { 80 let declaration = match def.kind {
79 NameKind::Macro(mac) => NavigationTarget::from_macro_def(db, mac), 81 NameKind::Macro(mac) => mac.to_nav(db),
80 NameKind::Field(field) => NavigationTarget::from_field(db, field), 82 NameKind::Field(field) => field.to_nav(db),
81 NameKind::AssocItem(assoc) => NavigationTarget::from_assoc_item(db, assoc), 83 NameKind::AssocItem(assoc) => assoc.to_nav(db),
82 NameKind::Def(def) => NavigationTarget::from_def(db, def)?, 84 NameKind::Def(def) => NavigationTarget::from_def(db, def)?,
83 NameKind::SelfType(ref ty) => match ty.as_adt() { 85 NameKind::SelfType(ref ty) => match ty.as_adt() {
84 Some((def_id, _)) => NavigationTarget::from_adt_def(db, def_id), 86 Some((adt, _)) => adt.to_nav(db),
85 None => return None, 87 None => return None,
86 }, 88 },
87 NameKind::Pat((_, pat)) => NavigationTarget::from_pat(db, position.file_id, pat), 89 NameKind::Pat((_, pat)) => NavigationTarget::from_pat(db, position.file_id, pat),