mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Add ExternCrateDecl to HIR
This commit is contained in:
parent
151c750dac
commit
bcff166b3a
39 changed files with 585 additions and 167 deletions
|
@ -12,9 +12,9 @@ use hir_ty::db::HirDatabase;
|
|||
use syntax::{ast, AstNode};
|
||||
|
||||
use crate::{
|
||||
Adt, AssocItem, Const, ConstParam, Enum, Field, Function, GenericParam, Impl, LifetimeParam,
|
||||
Macro, Module, ModuleDef, Static, Struct, Trait, TraitAlias, TypeAlias, TypeParam, Union,
|
||||
Variant,
|
||||
Adt, AssocItem, Const, ConstParam, Enum, ExternCrateDecl, Field, Function, GenericParam, Impl,
|
||||
LifetimeParam, Macro, Module, ModuleDef, Static, Struct, Trait, TraitAlias, TypeAlias,
|
||||
TypeParam, Union, Variant,
|
||||
};
|
||||
|
||||
pub trait HasAttrs {
|
||||
|
@ -120,6 +120,39 @@ impl HasAttrs for AssocItem {
|
|||
}
|
||||
}
|
||||
|
||||
impl HasAttrs for ExternCrateDecl {
|
||||
fn attrs(self, db: &dyn HirDatabase) -> AttrsWithOwner {
|
||||
let def = AttrDefId::ExternCrateId(self.into());
|
||||
db.attrs_with_owner(def)
|
||||
}
|
||||
fn docs(self, db: &dyn HirDatabase) -> Option<Documentation> {
|
||||
let crate_docs = self.resolved_crate(db).root_module().attrs(db).docs().map(String::from);
|
||||
let def = AttrDefId::ExternCrateId(self.into());
|
||||
let decl_docs = db.attrs(def).docs().map(String::from);
|
||||
match (decl_docs, crate_docs) {
|
||||
(None, None) => None,
|
||||
(Some(decl_docs), None) => Some(decl_docs),
|
||||
(None, Some(crate_docs)) => Some(crate_docs),
|
||||
(Some(mut decl_docs), Some(crate_docs)) => {
|
||||
decl_docs.push('\n');
|
||||
decl_docs.push('\n');
|
||||
decl_docs += &crate_docs;
|
||||
Some(decl_docs)
|
||||
}
|
||||
}
|
||||
.map(Documentation::new)
|
||||
}
|
||||
fn resolve_doc_path(
|
||||
self,
|
||||
db: &dyn HirDatabase,
|
||||
link: &str,
|
||||
ns: Option<Namespace>,
|
||||
) -> Option<ModuleDef> {
|
||||
let def = AttrDefId::ExternCrateId(self.into());
|
||||
resolve_doc_path(db, def, link, ns).map(ModuleDef::from)
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolves the item `link` points to in the scope of `def`.
|
||||
fn resolve_doc_path(
|
||||
db: &dyn HirDatabase,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue