Add generic params to impl blocks
This commit is contained in:
parent
ccfc6b11c1
commit
da7056245d
4 changed files with 16 additions and 9 deletions
|
|
@ -7,7 +7,7 @@ use std::sync::Arc;
|
|||
|
||||
use ra_syntax::ast::{self, NameOwner, TypeParamsOwner};
|
||||
|
||||
use crate::{db::PersistentHirDatabase, Name, AsName, Function, Struct, Enum, Trait, Type};
|
||||
use crate::{db::PersistentHirDatabase, Name, AsName, Function, Struct, Enum, Trait, Type, ImplBlock};
|
||||
|
||||
/// Data about a generic parameter (to a function, struct, impl, ...).
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
|
|
@ -30,8 +30,9 @@ pub enum GenericDef {
|
|||
Enum(Enum),
|
||||
Trait(Trait),
|
||||
Type(Type),
|
||||
ImplBlock(ImplBlock),
|
||||
}
|
||||
impl_froms!(GenericDef: Function, Struct, Enum, Trait, Type);
|
||||
impl_froms!(GenericDef: Function, Struct, Enum, Trait, Type, ImplBlock);
|
||||
|
||||
impl GenericParams {
|
||||
pub(crate) fn generic_params_query(
|
||||
|
|
@ -45,6 +46,7 @@ impl GenericParams {
|
|||
GenericDef::Enum(it) => generics.fill(&*it.source(db).1),
|
||||
GenericDef::Trait(it) => generics.fill(&*it.source(db).1),
|
||||
GenericDef::Type(it) => generics.fill(&*it.source(db).1),
|
||||
GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).1),
|
||||
}
|
||||
|
||||
Arc::new(generics)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use crate::{
|
|||
type_ref::TypeRef,
|
||||
ids::LocationCtx,
|
||||
resolve::Resolver,
|
||||
ty::Ty,
|
||||
ty::Ty, generics::GenericParams
|
||||
};
|
||||
|
||||
use crate::code_model_api::{Module, ModuleSource};
|
||||
|
|
@ -38,7 +38,7 @@ impl ImplSourceMap {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct ImplBlock {
|
||||
module: Module,
|
||||
impl_id: ImplId,
|
||||
|
|
@ -58,7 +58,7 @@ impl ImplBlock {
|
|||
}
|
||||
|
||||
/// Returns the syntax of the impl block
|
||||
pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::ImplBlock>) {
|
||||
pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ImplBlock>) {
|
||||
let source_map = db.impls_in_module_source_map(self.module);
|
||||
let (file_id, source) = self.module.definition_source(db);
|
||||
(file_id, source_map.get(&source, self.impl_id))
|
||||
|
|
@ -72,11 +72,11 @@ impl ImplBlock {
|
|||
self.module
|
||||
}
|
||||
|
||||
pub fn target_trait_ref(&self, db: &impl HirDatabase) -> Option<TypeRef> {
|
||||
pub fn target_trait_ref(&self, db: &impl PersistentHirDatabase) -> Option<TypeRef> {
|
||||
db.impls_in_module(self.module).impls[self.impl_id].target_trait().cloned()
|
||||
}
|
||||
|
||||
pub fn target_type(&self, db: &impl HirDatabase) -> TypeRef {
|
||||
pub fn target_type(&self, db: &impl PersistentHirDatabase) -> TypeRef {
|
||||
db.impls_in_module(self.module).impls[self.impl_id].target_type().clone()
|
||||
}
|
||||
|
||||
|
|
@ -96,10 +96,14 @@ impl ImplBlock {
|
|||
None
|
||||
}
|
||||
|
||||
pub fn items(&self, db: &impl HirDatabase) -> Vec<ImplItem> {
|
||||
pub fn items(&self, db: &impl PersistentHirDatabase) -> Vec<ImplItem> {
|
||||
db.impls_in_module(self.module).impls[self.impl_id].items().to_vec()
|
||||
}
|
||||
|
||||
pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
|
||||
db.generic_params((*self).into())
|
||||
}
|
||||
|
||||
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
||||
let r = self.module().resolver(db);
|
||||
// TODO: add generics
|
||||
|
|
|
|||
|
|
@ -1352,6 +1352,7 @@ impl ToOwned for ImplBlock {
|
|||
}
|
||||
|
||||
|
||||
impl ast::TypeParamsOwner for ImplBlock {}
|
||||
impl ImplBlock {
|
||||
pub fn item_list(&self) -> Option<&ItemList> {
|
||||
super::child_opt(self)
|
||||
|
|
|
|||
|
|
@ -322,7 +322,7 @@ Grammar(
|
|||
],
|
||||
options: ["TypeRef"]
|
||||
),
|
||||
"ImplBlock": (options: ["ItemList"]),
|
||||
"ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner"]),
|
||||
|
||||
"ParenType": (options: ["TypeRef"]),
|
||||
"TupleType": ( collections: [["fields", "TypeRef"]] ),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue