Fix ConstParam HasSource impl and implement TryToNav not Nav

This commit is contained in:
Nick Spain 2021-01-02 22:11:25 +11:00
parent 887028fcf5
commit 40cd6cdf67
2 changed files with 8 additions and 8 deletions

View File

@ -142,8 +142,8 @@ impl HasSource for LifetimeParam {
impl HasSource for ConstParam {
type Ast = ast::ConstParam;
fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast> {
fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> {
let child_source = self.id.parent.child_source(db.upcast());
child_source.map(|it| it[self.id.local_id].clone())
Some(child_source.map(|it| it[self.id.local_id].clone()))
}
}

View File

@ -218,7 +218,7 @@ impl TryToNav for Definition {
Definition::TypeParam(it) => it.try_to_nav(db),
Definition::LifetimeParam(it) => it.try_to_nav(db),
Definition::Label(it) => Some(it.to_nav(db)),
Definition::ConstParam(it) => Some(it.to_nav(db)),
Definition::ConstParam(it) => it.try_to_nav(db),
}
}
}
@ -479,11 +479,11 @@ impl TryToNav for hir::LifetimeParam {
}
}
impl ToNav for hir::ConstParam {
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
let src = self.source(db);
impl TryToNav for hir::ConstParam {
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
let src = self.source(db)?;
let full_range = src.value.syntax().text_range();
NavigationTarget {
Some(NavigationTarget {
file_id: src.file_id.original_file(db),
name: self.name(db).to_string().into(),
kind: Some(SymbolKind::ConstParam),
@ -492,7 +492,7 @@ impl ToNav for hir::ConstParam {
container_name: None,
description: None,
docs: None,
}
})
}
}