mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Classify name works for TypeParams
This commit is contained in:
parent
d1a01aa2f8
commit
7d2080a031
6 changed files with 68 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
|||
//! FIXME: write short doc here
|
||||
use hir_def::{
|
||||
child_by_source::ChildBySource, dyn_map::DynMap, keys, nameres::ModuleSource, AstItemDef,
|
||||
EnumVariantId, LocationCtx, ModuleId, VariantId,
|
||||
EnumVariantId, GenericDefId, LocationCtx, ModuleId, VariantId,
|
||||
};
|
||||
use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind};
|
||||
use ra_syntax::{
|
||||
|
@ -11,8 +11,8 @@ use ra_syntax::{
|
|||
|
||||
use crate::{
|
||||
db::{AstDatabase, DefDatabase, HirDatabase},
|
||||
Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, ImplBlock, InFile, Local,
|
||||
MacroDef, Module, Static, Struct, StructField, Trait, TypeAlias, Union,
|
||||
Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, GenericParam, ImplBlock, InFile,
|
||||
Local, MacroDef, Module, Static, Struct, StructField, Trait, TypeAlias, Union,
|
||||
};
|
||||
|
||||
pub trait FromSource: Sized {
|
||||
|
@ -177,6 +177,23 @@ impl Local {
|
|||
}
|
||||
}
|
||||
|
||||
impl GenericParam {
|
||||
pub fn from_source(db: &impl HirDatabase, src: InFile<ast::TypeParam>) -> Option<Self> {
|
||||
let file_id = src.file_id;
|
||||
let parent: GenericDefId = src.value.syntax().ancestors().find_map(|it| {
|
||||
let res = match_ast! {
|
||||
match it {
|
||||
ast::FnDef(value) => { Function::from_source(db, InFile { value, file_id})?.id.into() },
|
||||
_ => return None,
|
||||
}
|
||||
};
|
||||
Some(res)
|
||||
})?;
|
||||
let &id = parent.child_by_source(db)[keys::TYPE_PARAM].get(&src)?;
|
||||
Some(GenericParam { id })
|
||||
}
|
||||
}
|
||||
|
||||
impl Module {
|
||||
pub fn from_declaration(db: &impl DefDatabase, src: InFile<ast::Module>) -> Option<Self> {
|
||||
let parent_declaration = src.value.syntax().ancestors().skip(1).find_map(ast::Module::cast);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue