From 958862093e83083b188427246323047a2c9e7bab Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 23 Nov 2019 14:43:38 +0300 Subject: Move docs to hir_def --- crates/ra_hir/src/code_model/docs.rs | 97 ------------------------------------ 1 file changed, 97 deletions(-) delete mode 100644 crates/ra_hir/src/code_model/docs.rs (limited to 'crates/ra_hir/src/code_model') diff --git a/crates/ra_hir/src/code_model/docs.rs b/crates/ra_hir/src/code_model/docs.rs deleted file mode 100644 index e40efef34..000000000 --- a/crates/ra_hir/src/code_model/docs.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! FIXME: write short doc here - -use std::sync::Arc; - -use ra_syntax::ast; - -use crate::{ - db::{AstDatabase, DefDatabase, HirDatabase}, - Adt, Const, Enum, EnumVariant, FieldSource, Function, HasSource, MacroDef, Module, Static, - Struct, StructField, Trait, TypeAlias, Union, -}; - -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub enum DocDef { - Module(Module), - StructField(StructField), - Adt(Adt), - EnumVariant(EnumVariant), - Static(Static), - Const(Const), - Function(Function), - Trait(Trait), - TypeAlias(TypeAlias), - MacroDef(MacroDef), -} - -impl_froms!( - DocDef: Module, - StructField, - Adt(Struct, Enum, Union), - EnumVariant, - Static, - Const, - Function, - Trait, - TypeAlias, - MacroDef -); - -/// Holds documentation -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct Documentation(Arc); - -impl Documentation { - fn new(s: &str) -> Documentation { - Documentation(s.into()) - } - - pub fn as_str(&self) -> &str { - &*self.0 - } -} - -impl Into for Documentation { - fn into(self) -> String { - self.as_str().to_owned() - } -} - -pub trait Docs { - fn docs(&self, db: &impl HirDatabase) -> Option; -} - -pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option { - node.doc_comment_text().map(|it| Documentation::new(&it)) -} - -pub(crate) fn documentation_query( - db: &(impl DefDatabase + AstDatabase), - def: DocDef, -) -> Option { - match def { - DocDef::Module(it) => docs_from_ast(&it.declaration_source(db)?.value), - DocDef::StructField(it) => match it.source(db).value { - FieldSource::Named(named) => docs_from_ast(&named), - FieldSource::Pos(..) => None, - }, - DocDef::Adt(it) => match it { - Adt::Struct(it) => docs_from_ast(&it.source(db).value), - Adt::Enum(it) => docs_from_ast(&it.source(db).value), - Adt::Union(it) => docs_from_ast(&it.source(db).value), - }, - DocDef::EnumVariant(it) => docs_from_ast(&it.source(db).value), - DocDef::Static(it) => docs_from_ast(&it.source(db).value), - DocDef::Const(it) => docs_from_ast(&it.source(db).value), - DocDef::Function(it) => docs_from_ast(&it.source(db).value), - DocDef::Trait(it) => docs_from_ast(&it.source(db).value), - DocDef::TypeAlias(it) => docs_from_ast(&it.source(db).value), - DocDef::MacroDef(it) => docs_from_ast(&it.source(db).value), - } -} - -impl + Copy> Docs for T { - fn docs(&self, db: &impl HirDatabase) -> Option { - db.documentation((*self).into()) - } -} -- cgit v1.2.3