Clean usage of ShortLabel

This commit is contained in:
oxalica 2021-03-16 00:58:42 +08:00
parent 7101bada0f
commit 7c855c940a
No known key found for this signature in database
GPG key ID: CED392DE0C483D00
2 changed files with 8 additions and 7 deletions

View file

@ -5,6 +5,5 @@ pub(crate) mod navigation_target;
mod short_label; mod short_label;
pub(crate) use navigation_target::{ToNav, TryToNav}; pub(crate) use navigation_target::{ToNav, TryToNav};
pub(crate) use short_label::ShortLabel;
pub(crate) use syntax::display::{function_declaration, macro_label}; pub(crate) use syntax::display::{function_declaration, macro_label};

View file

@ -3,7 +3,9 @@
use std::fmt; use std::fmt;
use either::Either; use either::Either;
use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, ModuleSource}; use hir::{
AssocItem, Documentation, FieldSource, HasAttrs, HasSource, HirDisplay, InFile, ModuleSource,
};
use ide_db::{ use ide_db::{
base_db::{FileId, FileRange, SourceDatabase}, base_db::{FileId, FileRange, SourceDatabase},
symbol_index::FileSymbolKind, symbol_index::FileSymbolKind,
@ -98,7 +100,7 @@ impl NavigationTarget {
SymbolKind::Module, SymbolKind::Module,
); );
res.docs = module.attrs(db).docs(); res.docs = module.attrs(db).docs();
res.description = src.value.short_label(); res.description = Some(module.display(db).to_string());
return res; return res;
} }
module.to_nav(db) module.to_nav(db)
@ -251,8 +253,8 @@ impl ToNavFromAst for hir::Trait {
impl<D> TryToNav for D impl<D> TryToNav for D
where where
D: HasSource + ToNavFromAst + Copy + HasAttrs, D: HasSource + ToNavFromAst + Copy + HasAttrs + HirDisplay,
D::Ast: ast::NameOwner + ShortLabel, D::Ast: ast::NameOwner,
{ {
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> { fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
let src = self.source(db)?; let src = self.source(db)?;
@ -262,7 +264,7 @@ where
D::KIND, D::KIND,
); );
res.docs = self.docs(db); res.docs = self.docs(db);
res.description = src.value.short_label(); res.description = Some(self.display(db).to_string());
Some(res) Some(res)
} }
} }
@ -317,7 +319,7 @@ impl TryToNav for hir::Field {
let mut res = let mut res =
NavigationTarget::from_named(db, src.with_value(it), SymbolKind::Field); NavigationTarget::from_named(db, src.with_value(it), SymbolKind::Field);
res.docs = self.docs(db); res.docs = self.docs(db);
res.description = it.short_label(); res.description = Some(self.display(db).to_string());
res res
} }
FieldSource::Pos(it) => { FieldSource::Pos(it) => {