From 5dc27898959d2330b0822d95a9ee2488e687895a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Jun 2019 13:51:18 +0300 Subject: Move docs to dedicated module --- crates/ra_hir/src/code_model.rs | 68 --------------------------------------- crates/ra_hir/src/docs.rs | 71 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 69 deletions(-) diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 6ee6bd627..59d7d589a 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -319,12 +319,6 @@ impl Module { } } -impl Docs for Module { - fn docs(&self, db: &impl HirDatabase) -> Option { - self.declaration_source(db).and_then(|it| docs_from_ast(&*it.1)) - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct StructField { pub(crate) parent: VariantDef, @@ -355,15 +349,6 @@ impl StructField { } } -impl Docs for StructField { - fn docs(&self, db: &impl HirDatabase) -> Option { - match self.source(db).1 { - FieldSource::Named(named) => docs_from_ast(&*named), - FieldSource::Pos(..) => return None, - } - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Struct { pub(crate) id: StructId, @@ -425,12 +410,6 @@ impl Struct { } } -impl Docs for Struct { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Union { pub(crate) id: StructId, @@ -464,12 +443,6 @@ impl Union { } } -impl Docs for Union { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Enum { pub(crate) id: EnumId, @@ -519,12 +492,6 @@ impl Enum { } } -impl Docs for Enum { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct EnumVariant { pub(crate) parent: Enum, @@ -568,12 +535,6 @@ impl EnumVariant { } } -impl Docs for EnumVariant { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - /// The defs which have a body. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum DefWithBody { @@ -757,12 +718,6 @@ impl Function { } } -impl Docs for Function { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Const { pub(crate) id: ConstId, @@ -806,12 +761,6 @@ impl Const { } } -impl Docs for Const { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - /// The declared signature of a const. #[derive(Debug, Clone, PartialEq, Eq)] pub struct ConstSignature { @@ -884,12 +833,6 @@ impl Static { } } -impl Docs for Static { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Trait { pub(crate) id: TraitId, @@ -936,12 +879,6 @@ impl Trait { } } -impl Docs for Trait { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct TypeAlias { pub(crate) id: TypeAliasId, @@ -998,11 +935,6 @@ impl TypeAlias { } } -impl Docs for TypeAlias { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct MacroDef { pub(crate) id: MacroDefId, diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs index 5db72c08a..c2279fe95 100644 --- a/crates/ra_hir/src/docs.rs +++ b/crates/ra_hir/src/docs.rs @@ -1,6 +1,6 @@ use ra_syntax::ast; -use crate::HirDatabase; +use crate::{HirDatabase, Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union}; /// Holds documentation #[derive(Debug, Clone)] @@ -29,3 +29,72 @@ pub trait Docs { pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option { node.doc_comment_text().map(|it| Documentation::new(&it)) } + +impl Docs for Module { + fn docs(&self, db: &impl HirDatabase) -> Option { + self.declaration_source(db).and_then(|it| docs_from_ast(&*it.1)) + } +} + +impl Docs for StructField { + fn docs(&self, db: &impl HirDatabase) -> Option { + match self.source(db).1 { + FieldSource::Named(named) => docs_from_ast(&*named), + FieldSource::Pos(..) => return None, + } + } +} + +impl Docs for Struct { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for Union { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for Enum { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for EnumVariant { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for Function { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for Const { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for Static { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for Trait { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for TypeAlias { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} -- cgit v1.2.3