diff options
Diffstat (limited to 'crates/ide/src/display/navigation_target.rs')
-rw-r--r-- | crates/ide/src/display/navigation_target.rs | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index 198243466..c086de163 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs | |||
@@ -3,9 +3,12 @@ | |||
3 | use std::fmt; | 3 | use std::fmt; |
4 | 4 | ||
5 | use either::Either; | 5 | use either::Either; |
6 | use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, ModuleSource}; | 6 | use hir::{ |
7 | AssocItem, Documentation, FieldSource, HasAttrs, HasSource, HirDisplay, InFile, ModuleSource, | ||
8 | Semantics, | ||
9 | }; | ||
7 | use ide_db::{ | 10 | use ide_db::{ |
8 | base_db::{FileId, FileRange, SourceDatabase}, | 11 | base_db::{FileId, FileRange}, |
9 | symbol_index::FileSymbolKind, | 12 | symbol_index::FileSymbolKind, |
10 | SymbolKind, | 13 | SymbolKind, |
11 | }; | 14 | }; |
@@ -17,8 +20,6 @@ use syntax::{ | |||
17 | 20 | ||
18 | use crate::FileSymbol; | 21 | use crate::FileSymbol; |
19 | 22 | ||
20 | use super::short_label::ShortLabel; | ||
21 | |||
22 | /// `NavigationTarget` represents and element in the editor's UI which you can | 23 | /// `NavigationTarget` represents and element in the editor's UI which you can |
23 | /// click on to navigate to a particular piece of code. | 24 | /// click on to navigate to a particular piece of code. |
24 | /// | 25 | /// |
@@ -98,7 +99,7 @@ impl NavigationTarget { | |||
98 | SymbolKind::Module, | 99 | SymbolKind::Module, |
99 | ); | 100 | ); |
100 | res.docs = module.attrs(db).docs(); | 101 | res.docs = module.attrs(db).docs(); |
101 | res.description = src.value.short_label(); | 102 | res.description = Some(module.display(db).to_string()); |
102 | return res; | 103 | return res; |
103 | } | 104 | } |
104 | module.to_nav(db) | 105 | module.to_nav(db) |
@@ -251,8 +252,8 @@ impl ToNavFromAst for hir::Trait { | |||
251 | 252 | ||
252 | impl<D> TryToNav for D | 253 | impl<D> TryToNav for D |
253 | where | 254 | where |
254 | D: HasSource + ToNavFromAst + Copy + HasAttrs, | 255 | D: HasSource + ToNavFromAst + Copy + HasAttrs + HirDisplay, |
255 | D::Ast: ast::NameOwner + ShortLabel, | 256 | D::Ast: ast::NameOwner, |
256 | { | 257 | { |
257 | fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> { | 258 | fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> { |
258 | let src = self.source(db)?; | 259 | let src = self.source(db)?; |
@@ -262,7 +263,7 @@ where | |||
262 | D::KIND, | 263 | D::KIND, |
263 | ); | 264 | ); |
264 | res.docs = self.docs(db); | 265 | res.docs = self.docs(db); |
265 | res.description = src.value.short_label(); | 266 | res.description = Some(self.display(db).to_string()); |
266 | Some(res) | 267 | Some(res) |
267 | } | 268 | } |
268 | } | 269 | } |
@@ -317,7 +318,7 @@ impl TryToNav for hir::Field { | |||
317 | let mut res = | 318 | let mut res = |
318 | NavigationTarget::from_named(db, src.with_value(it), SymbolKind::Field); | 319 | NavigationTarget::from_named(db, src.with_value(it), SymbolKind::Field); |
319 | res.docs = self.docs(db); | 320 | res.docs = self.docs(db); |
320 | res.description = it.short_label(); | 321 | res.description = Some(self.display(db).to_string()); |
321 | res | 322 | res |
322 | } | 323 | } |
323 | FieldSource::Pos(it) => { | 324 | FieldSource::Pos(it) => { |
@@ -500,21 +501,22 @@ impl TryToNav for hir::ConstParam { | |||
500 | /// | 501 | /// |
501 | /// e.g. `struct Name`, `enum Name`, `fn Name` | 502 | /// e.g. `struct Name`, `enum Name`, `fn Name` |
502 | pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> { | 503 | pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> { |
503 | let parse = db.parse(symbol.file_id); | 504 | let sema = Semantics::new(db); |
504 | let node = symbol.ptr.to_node(parse.tree().syntax()); | 505 | let parse = sema.parse(symbol.file_id); |
506 | let node = symbol.ptr.to_node(parse.syntax()); | ||
505 | 507 | ||
506 | match_ast! { | 508 | match_ast! { |
507 | match node { | 509 | match node { |
508 | ast::Fn(it) => it.short_label(), | 510 | ast::Fn(it) => sema.to_def(&it).map(|it| it.display(db).to_string()), |
509 | ast::Struct(it) => it.short_label(), | 511 | ast::Struct(it) => sema.to_def(&it).map(|it| it.display(db).to_string()), |
510 | ast::Enum(it) => it.short_label(), | 512 | ast::Enum(it) => sema.to_def(&it).map(|it| it.display(db).to_string()), |
511 | ast::Trait(it) => it.short_label(), | 513 | ast::Trait(it) => sema.to_def(&it).map(|it| it.display(db).to_string()), |
512 | ast::Module(it) => it.short_label(), | 514 | ast::Module(it) => sema.to_def(&it).map(|it| it.display(db).to_string()), |
513 | ast::TypeAlias(it) => it.short_label(), | 515 | ast::TypeAlias(it) => sema.to_def(&it).map(|it| it.display(db).to_string()), |
514 | ast::Const(it) => it.short_label(), | 516 | ast::Const(it) => sema.to_def(&it).map(|it| it.display(db).to_string()), |
515 | ast::Static(it) => it.short_label(), | 517 | ast::Static(it) => sema.to_def(&it).map(|it| it.display(db).to_string()), |
516 | ast::RecordField(it) => it.short_label(), | 518 | ast::RecordField(it) => sema.to_def(&it).map(|it| it.display(db).to_string()), |
517 | ast::Variant(it) => it.short_label(), | 519 | ast::Variant(it) => sema.to_def(&it).map(|it| it.display(db).to_string()), |
518 | _ => None, | 520 | _ => None, |
519 | } | 521 | } |
520 | } | 522 | } |