ToNav for GenericParam

This commit is contained in:
Aleksey Kladov 2019-12-07 18:48:35 +01:00
parent dda9587e75
commit 1692f07393
2 changed files with 28 additions and 1 deletions

View file

@ -860,6 +860,13 @@ pub struct GenericParam {
pub(crate) id: GenericParamId,
}
impl GenericParam {
pub fn name(self, db: &impl HirDatabase) -> Name {
let params = db.generic_params(self.id.parent);
params.params[self.id.local_id].name.clone()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ImplBlock {
pub(crate) id: ImplId,

View file

@ -6,7 +6,7 @@ use ra_db::{FileId, SourceDatabase};
use ra_syntax::{
ast::{self, DocCommentsOwner, NameOwner},
match_ast, AstNode, SmolStr,
SyntaxKind::{self, BIND_PAT},
SyntaxKind::{self, BIND_PAT, TYPE_PARAM},
TextRange,
};
@ -351,6 +351,26 @@ impl ToNav for hir::Local {
}
}
impl ToNav for hir::GenericParam {
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
let src = self.source(db);
let range = match src.value {
Either::Left(it) => it.syntax().text_range(),
Either::Right(it) => it.syntax().text_range(),
};
NavigationTarget {
file_id: src.file_id.original_file(db),
name: self.name(db).to_string().into(),
kind: TYPE_PARAM,
full_range: range,
focus_range: None,
container_name: None,
description: None,
docs: None,
}
}
}
pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> {
let parse = db.parse(symbol.file_id);
let node = symbol.ptr.to_node(parse.tree().syntax());