mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
use Source for Trait
This commit is contained in:
parent
5e6213b516
commit
f411c2988d
7 changed files with 28 additions and 39 deletions
|
@ -110,7 +110,7 @@ fn resolve_target_trait_def(
|
||||||
impl_block.target_trait().map(AstNode::syntax).and_then(ast::PathType::cast)?.path()?;
|
impl_block.target_trait().map(AstNode::syntax).and_then(ast::PathType::cast)?.path()?;
|
||||||
|
|
||||||
match analyzer.resolve_path(db, &ast_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,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -528,6 +528,13 @@ pub struct EnumVariant {
|
||||||
pub(crate) id: EnumVariantId,
|
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 {
|
impl EnumVariant {
|
||||||
pub fn source(
|
pub fn source(
|
||||||
&self,
|
&self,
|
||||||
|
@ -886,12 +893,16 @@ pub struct Trait {
|
||||||
pub(crate) id: TraitId,
|
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 {
|
impl Trait {
|
||||||
pub fn source(
|
pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::TraitDef>> {
|
||||||
self,
|
self.id.source(db).into()
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
|
||||||
) -> (HirFileId, TreeArc<ast::TraitDef>) {
|
|
||||||
self.id.source(db)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn module(self, db: &impl DefDatabase) -> Module {
|
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::Const(it) => docs_from_ast(&*it.source(db).ast),
|
||||||
DocDef::Function(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::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::TypeAlias(it) => docs_from_ast(&*it.source(db).ast),
|
||||||
DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).1),
|
DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).1),
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ impl GenericParams {
|
||||||
name: Name::self_type(),
|
name: Name::self_type(),
|
||||||
default: None,
|
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::TypeAlias(it) => generics.fill(&*it.source(db).ast, start),
|
||||||
GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).1, start),
|
GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).1, start),
|
||||||
|
|
|
@ -22,12 +22,12 @@ impl TraitData {
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
db: &(impl DefDatabase + AstDatabase),
|
||||||
tr: Trait,
|
tr: Trait,
|
||||||
) -> Arc<TraitData> {
|
) -> Arc<TraitData> {
|
||||||
let (file_id, node) = tr.source(db);
|
let src = tr.source(db);
|
||||||
let name = node.name().map(|n| n.as_name());
|
let name = src.ast.name().map(|n| n.as_name());
|
||||||
let module = tr.module(db);
|
let module = tr.module(db);
|
||||||
let ctx = LocationCtx::new(db, module, file_id);
|
let ctx = LocationCtx::new(db, module, src.file_id);
|
||||||
let auto = node.is_auto();
|
let auto = src.ast.is_auto();
|
||||||
let items = if let Some(item_list) = node.item_list() {
|
let items = if let Some(item_list) = src.ast.item_list() {
|
||||||
item_list
|
item_list
|
||||||
.impl_items()
|
.impl_items()
|
||||||
.map(|item_node| match item_node.kind() {
|
.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::Union(it) => NavigationTarget::from_adt_def(db, it.into()),
|
||||||
hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it),
|
hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it),
|
||||||
hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it),
|
hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it),
|
||||||
hir::ModuleDef::EnumVariant(var) => {
|
hir::ModuleDef::EnumVariant(it) => NavigationTarget::from_def_source(db, it),
|
||||||
let src = var.source(db);
|
hir::ModuleDef::Trait(it) => NavigationTarget::from_def_source(db, it),
|
||||||
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::TypeAlias(it) => NavigationTarget::from_def_source(db, it),
|
hir::ModuleDef::TypeAlias(it) => NavigationTarget::from_def_source(db, it),
|
||||||
hir::ModuleDef::BuiltinType(..) => {
|
hir::ModuleDef::BuiltinType(..) => {
|
||||||
return None;
|
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::Struct(it) => res.extend(from_def_source(db, it)),
|
||||||
hir::ModuleDef::Union(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::Enum(it) => res.extend(from_def_source(db, it)),
|
||||||
hir::ModuleDef::EnumVariant(it) => {
|
hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)),
|
||||||
let src = it.source(db);
|
|
||||||
res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label()))
|
|
||||||
}
|
|
||||||
hir::ModuleDef::Const(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::Static(it) => res.extend(from_def_source(db, it)),
|
||||||
hir::ModuleDef::Trait(it) => {
|
hir::ModuleDef::Trait(it) => res.extend(from_def_source(db, it)),
|
||||||
let it = it.source(db).1;
|
|
||||||
res.extend(hover_text(it.doc_comment_text(), it.short_label()))
|
|
||||||
}
|
|
||||||
hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)),
|
hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)),
|
||||||
hir::ModuleDef::BuiltinType(_) => {
|
hir::ModuleDef::BuiltinType(_) => {
|
||||||
// FIXME: hover for builtin Type ?
|
// FIXME: hover for builtin Type ?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue