use Source for Trait
This commit is contained in:
parent
5e6213b516
commit
f411c2988d
@ -110,7 +110,7 @@ fn resolve_target_trait_def(
|
||||
impl_block.target_trait().map(AstNode::syntax).and_then(ast::PathType::cast)?.path()?;
|
||||
|
||||
match analyzer.resolve_path(db, &ast_path) {
|
||||
Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def.source(db).1),
|
||||
Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def.source(db).ast),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -528,6 +528,13 @@ pub struct EnumVariant {
|
||||
pub(crate) id: EnumVariantId,
|
||||
}
|
||||
|
||||
impl HasSource for EnumVariant {
|
||||
type Ast = TreeArc<ast::EnumVariant>;
|
||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumVariant>> {
|
||||
self.source_impl(db)
|
||||
}
|
||||
}
|
||||
|
||||
impl EnumVariant {
|
||||
pub fn source(
|
||||
&self,
|
||||
@ -886,12 +893,16 @@ pub struct Trait {
|
||||
pub(crate) id: TraitId,
|
||||
}
|
||||
|
||||
impl HasSource for Trait {
|
||||
type Ast = TreeArc<ast::TraitDef>;
|
||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TraitDef>> {
|
||||
self.id.source(db).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Trait {
|
||||
pub fn source(
|
||||
self,
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
) -> (HirFileId, TreeArc<ast::TraitDef>) {
|
||||
self.id.source(db)
|
||||
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TraitDef>> {
|
||||
self.id.source(db).into()
|
||||
}
|
||||
|
||||
pub fn module(self, db: &impl DefDatabase) -> Module {
|
||||
|
@ -83,7 +83,7 @@ pub(crate) fn documentation_query(
|
||||
DocDef::Const(it) => docs_from_ast(&*it.source(db).ast),
|
||||
DocDef::Function(it) => docs_from_ast(&*it.source(db).ast),
|
||||
DocDef::Union(it) => docs_from_ast(&*it.source(db).1),
|
||||
DocDef::Trait(it) => docs_from_ast(&*it.source(db).1),
|
||||
DocDef::Trait(it) => docs_from_ast(&*it.source(db).ast),
|
||||
DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).ast),
|
||||
DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).1),
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ impl GenericParams {
|
||||
name: Name::self_type(),
|
||||
default: None,
|
||||
});
|
||||
generics.fill(&*it.source(db).1, start + 1);
|
||||
generics.fill(&*it.source(db).ast, start + 1);
|
||||
}
|
||||
GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).ast, start),
|
||||
GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).1, start),
|
||||
|
@ -22,12 +22,12 @@ impl TraitData {
|
||||
db: &(impl DefDatabase + AstDatabase),
|
||||
tr: Trait,
|
||||
) -> Arc<TraitData> {
|
||||
let (file_id, node) = tr.source(db);
|
||||
let name = node.name().map(|n| n.as_name());
|
||||
let src = tr.source(db);
|
||||
let name = src.ast.name().map(|n| n.as_name());
|
||||
let module = tr.module(db);
|
||||
let ctx = LocationCtx::new(db, module, file_id);
|
||||
let auto = node.is_auto();
|
||||
let items = if let Some(item_list) = node.item_list() {
|
||||
let ctx = LocationCtx::new(db, module, src.file_id);
|
||||
let auto = src.ast.is_auto();
|
||||
let items = if let Some(item_list) = src.ast.item_list() {
|
||||
item_list
|
||||
.impl_items()
|
||||
.map(|item_node| match item_node.kind() {
|
||||
|
@ -214,24 +214,8 @@ impl NavigationTarget {
|
||||
hir::ModuleDef::Union(it) => NavigationTarget::from_adt_def(db, it.into()),
|
||||
hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it),
|
||||
hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it),
|
||||
hir::ModuleDef::EnumVariant(var) => {
|
||||
let src = var.source(db);
|
||||
NavigationTarget::from_named(
|
||||
src.file_id.original_file(db),
|
||||
&*src.ast,
|
||||
src.ast.doc_comment_text(),
|
||||
src.ast.short_label(),
|
||||
)
|
||||
}
|
||||
hir::ModuleDef::Trait(e) => {
|
||||
let (file_id, node) = e.source(db);
|
||||
NavigationTarget::from_named(
|
||||
file_id.original_file(db),
|
||||
&*node,
|
||||
node.doc_comment_text(),
|
||||
node.short_label(),
|
||||
)
|
||||
}
|
||||
hir::ModuleDef::EnumVariant(it) => NavigationTarget::from_def_source(db, it),
|
||||
hir::ModuleDef::Trait(it) => NavigationTarget::from_def_source(db, it),
|
||||
hir::ModuleDef::TypeAlias(it) => NavigationTarget::from_def_source(db, it),
|
||||
hir::ModuleDef::BuiltinType(..) => {
|
||||
return None;
|
||||
|
@ -124,16 +124,10 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
||||
hir::ModuleDef::Struct(it) => res.extend(from_def_source(db, it)),
|
||||
hir::ModuleDef::Union(it) => res.extend(from_def_source(db, it)),
|
||||
hir::ModuleDef::Enum(it) => res.extend(from_def_source(db, it)),
|
||||
hir::ModuleDef::EnumVariant(it) => {
|
||||
let src = it.source(db);
|
||||
res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label()))
|
||||
}
|
||||
hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)),
|
||||
hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)),
|
||||
hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)),
|
||||
hir::ModuleDef::Trait(it) => {
|
||||
let it = it.source(db).1;
|
||||
res.extend(hover_text(it.doc_comment_text(), it.short_label()))
|
||||
}
|
||||
hir::ModuleDef::Trait(it) => res.extend(from_def_source(db, it)),
|
||||
hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)),
|
||||
hir::ModuleDef::BuiltinType(_) => {
|
||||
// FIXME: hover for builtin Type ?
|
||||
|
Loading…
x
Reference in New Issue
Block a user