mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Move docs to dedicated module
This commit is contained in:
parent
2a6b363b44
commit
5dc2789895
2 changed files with 70 additions and 69 deletions
|
@ -319,12 +319,6 @@ impl Module {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Docs for Module {
|
|
||||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
|
||||||
self.declaration_source(db).and_then(|it| docs_from_ast(&*it.1))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct StructField {
|
pub struct StructField {
|
||||||
pub(crate) parent: VariantDef,
|
pub(crate) parent: VariantDef,
|
||||||
|
@ -355,15 +349,6 @@ impl StructField {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Docs for StructField {
|
|
||||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
|
||||||
match self.source(db).1 {
|
|
||||||
FieldSource::Named(named) => docs_from_ast(&*named),
|
|
||||||
FieldSource::Pos(..) => return None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Struct {
|
pub struct Struct {
|
||||||
pub(crate) id: StructId,
|
pub(crate) id: StructId,
|
||||||
|
@ -425,12 +410,6 @@ impl Struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Docs for Struct {
|
|
||||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
|
||||||
docs_from_ast(&*self.source(db).1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Union {
|
pub struct Union {
|
||||||
pub(crate) id: StructId,
|
pub(crate) id: StructId,
|
||||||
|
@ -464,12 +443,6 @@ impl Union {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Docs for Union {
|
|
||||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
|
||||||
docs_from_ast(&*self.source(db).1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Enum {
|
pub struct Enum {
|
||||||
pub(crate) id: EnumId,
|
pub(crate) id: EnumId,
|
||||||
|
@ -519,12 +492,6 @@ impl Enum {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Docs for Enum {
|
|
||||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
|
||||||
docs_from_ast(&*self.source(db).1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct EnumVariant {
|
pub struct EnumVariant {
|
||||||
pub(crate) parent: Enum,
|
pub(crate) parent: Enum,
|
||||||
|
@ -568,12 +535,6 @@ impl EnumVariant {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Docs for EnumVariant {
|
|
||||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
|
||||||
docs_from_ast(&*self.source(db).1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The defs which have a body.
|
/// The defs which have a body.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub enum DefWithBody {
|
pub enum DefWithBody {
|
||||||
|
@ -757,12 +718,6 @@ impl Function {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Docs for Function {
|
|
||||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
|
||||||
docs_from_ast(&*self.source(db).1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Const {
|
pub struct Const {
|
||||||
pub(crate) id: ConstId,
|
pub(crate) id: ConstId,
|
||||||
|
@ -806,12 +761,6 @@ impl Const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Docs for Const {
|
|
||||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
|
||||||
docs_from_ast(&*self.source(db).1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The declared signature of a const.
|
/// The declared signature of a const.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct ConstSignature {
|
pub struct ConstSignature {
|
||||||
|
@ -884,12 +833,6 @@ impl Static {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Docs for Static {
|
|
||||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
|
||||||
docs_from_ast(&*self.source(db).1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Trait {
|
pub struct Trait {
|
||||||
pub(crate) id: TraitId,
|
pub(crate) id: TraitId,
|
||||||
|
@ -936,12 +879,6 @@ impl Trait {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Docs for Trait {
|
|
||||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
|
||||||
docs_from_ast(&*self.source(db).1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct TypeAlias {
|
pub struct TypeAlias {
|
||||||
pub(crate) id: TypeAliasId,
|
pub(crate) id: TypeAliasId,
|
||||||
|
@ -998,11 +935,6 @@ impl TypeAlias {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Docs for TypeAlias {
|
|
||||||
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
|
||||||
docs_from_ast(&*self.source(db).1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct MacroDef {
|
pub struct MacroDef {
|
||||||
pub(crate) id: MacroDefId,
|
pub(crate) id: MacroDefId,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use ra_syntax::ast;
|
use ra_syntax::ast;
|
||||||
|
|
||||||
use crate::HirDatabase;
|
use crate::{HirDatabase, Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union};
|
||||||
|
|
||||||
/// Holds documentation
|
/// Holds documentation
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -29,3 +29,72 @@ pub trait Docs {
|
||||||
pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option<Documentation> {
|
pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option<Documentation> {
|
||||||
node.doc_comment_text().map(|it| Documentation::new(&it))
|
node.doc_comment_text().map(|it| Documentation::new(&it))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Docs for Module {
|
||||||
|
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
||||||
|
self.declaration_source(db).and_then(|it| docs_from_ast(&*it.1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Docs for StructField {
|
||||||
|
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
||||||
|
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<Documentation> {
|
||||||
|
docs_from_ast(&*self.source(db).1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Docs for Union {
|
||||||
|
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
||||||
|
docs_from_ast(&*self.source(db).1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Docs for Enum {
|
||||||
|
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
||||||
|
docs_from_ast(&*self.source(db).1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Docs for EnumVariant {
|
||||||
|
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
||||||
|
docs_from_ast(&*self.source(db).1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Docs for Function {
|
||||||
|
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
||||||
|
docs_from_ast(&*self.source(db).1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Docs for Const {
|
||||||
|
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
||||||
|
docs_from_ast(&*self.source(db).1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Docs for Static {
|
||||||
|
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
||||||
|
docs_from_ast(&*self.source(db).1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Docs for Trait {
|
||||||
|
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
||||||
|
docs_from_ast(&*self.source(db).1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Docs for TypeAlias {
|
||||||
|
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
|
||||||
|
docs_from_ast(&*self.source(db).1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue