aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-06-08 11:51:18 +0100
committerAleksey Kladov <[email protected]>2019-06-08 11:53:14 +0100
commit5dc27898959d2330b0822d95a9ee2488e687895a (patch)
tree546680fa805ab2926106ec4ce2f35ae12831e135
parent2a6b363b44e335af5f26ac503461ef15cca82ace (diff)
Move docs to dedicated module
-rw-r--r--crates/ra_hir/src/code_model.rs68
-rw-r--r--crates/ra_hir/src/docs.rs71
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 {
319 } 319 }
320} 320}
321 321
322impl Docs for Module {
323 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
324 self.declaration_source(db).and_then(|it| docs_from_ast(&*it.1))
325 }
326}
327
328#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 322#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
329pub struct StructField { 323pub struct StructField {
330 pub(crate) parent: VariantDef, 324 pub(crate) parent: VariantDef,
@@ -355,15 +349,6 @@ impl StructField {
355 } 349 }
356} 350}
357 351
358impl Docs for StructField {
359 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
360 match self.source(db).1 {
361 FieldSource::Named(named) => docs_from_ast(&*named),
362 FieldSource::Pos(..) => return None,
363 }
364 }
365}
366
367#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 352#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
368pub struct Struct { 353pub struct Struct {
369 pub(crate) id: StructId, 354 pub(crate) id: StructId,
@@ -425,12 +410,6 @@ impl Struct {
425 } 410 }
426} 411}
427 412
428impl Docs for Struct {
429 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
430 docs_from_ast(&*self.source(db).1)
431 }
432}
433
434#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 413#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
435pub struct Union { 414pub struct Union {
436 pub(crate) id: StructId, 415 pub(crate) id: StructId,
@@ -464,12 +443,6 @@ impl Union {
464 } 443 }
465} 444}
466 445
467impl Docs for Union {
468 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
469 docs_from_ast(&*self.source(db).1)
470 }
471}
472
473#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 446#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
474pub struct Enum { 447pub struct Enum {
475 pub(crate) id: EnumId, 448 pub(crate) id: EnumId,
@@ -519,12 +492,6 @@ impl Enum {
519 } 492 }
520} 493}
521 494
522impl Docs for Enum {
523 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
524 docs_from_ast(&*self.source(db).1)
525 }
526}
527
528#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 495#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
529pub struct EnumVariant { 496pub struct EnumVariant {
530 pub(crate) parent: Enum, 497 pub(crate) parent: Enum,
@@ -568,12 +535,6 @@ impl EnumVariant {
568 } 535 }
569} 536}
570 537
571impl Docs for EnumVariant {
572 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
573 docs_from_ast(&*self.source(db).1)
574 }
575}
576
577/// The defs which have a body. 538/// The defs which have a body.
578#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 539#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
579pub enum DefWithBody { 540pub enum DefWithBody {
@@ -757,12 +718,6 @@ impl Function {
757 } 718 }
758} 719}
759 720
760impl Docs for Function {
761 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
762 docs_from_ast(&*self.source(db).1)
763 }
764}
765
766#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 721#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
767pub struct Const { 722pub struct Const {
768 pub(crate) id: ConstId, 723 pub(crate) id: ConstId,
@@ -806,12 +761,6 @@ impl Const {
806 } 761 }
807} 762}
808 763
809impl Docs for Const {
810 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
811 docs_from_ast(&*self.source(db).1)
812 }
813}
814
815/// The declared signature of a const. 764/// The declared signature of a const.
816#[derive(Debug, Clone, PartialEq, Eq)] 765#[derive(Debug, Clone, PartialEq, Eq)]
817pub struct ConstSignature { 766pub struct ConstSignature {
@@ -884,12 +833,6 @@ impl Static {
884 } 833 }
885} 834}
886 835
887impl Docs for Static {
888 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
889 docs_from_ast(&*self.source(db).1)
890 }
891}
892
893#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 836#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
894pub struct Trait { 837pub struct Trait {
895 pub(crate) id: TraitId, 838 pub(crate) id: TraitId,
@@ -936,12 +879,6 @@ impl Trait {
936 } 879 }
937} 880}
938 881
939impl Docs for Trait {
940 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
941 docs_from_ast(&*self.source(db).1)
942 }
943}
944
945#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 882#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
946pub struct TypeAlias { 883pub struct TypeAlias {
947 pub(crate) id: TypeAliasId, 884 pub(crate) id: TypeAliasId,
@@ -998,11 +935,6 @@ impl TypeAlias {
998 } 935 }
999} 936}
1000 937
1001impl Docs for TypeAlias {
1002 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
1003 docs_from_ast(&*self.source(db).1)
1004 }
1005}
1006#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 938#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1007pub struct MacroDef { 939pub struct MacroDef {
1008 pub(crate) id: MacroDefId, 940 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 @@
1use ra_syntax::ast; 1use ra_syntax::ast;
2 2
3use crate::HirDatabase; 3use crate::{HirDatabase, Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union};
4 4
5/// Holds documentation 5/// Holds documentation
6#[derive(Debug, Clone)] 6#[derive(Debug, Clone)]
@@ -29,3 +29,72 @@ pub trait Docs {
29pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option<Documentation> { 29pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option<Documentation> {
30 node.doc_comment_text().map(|it| Documentation::new(&it)) 30 node.doc_comment_text().map(|it| Documentation::new(&it))
31} 31}
32
33impl Docs for Module {
34 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
35 self.declaration_source(db).and_then(|it| docs_from_ast(&*it.1))
36 }
37}
38
39impl Docs for StructField {
40 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
41 match self.source(db).1 {
42 FieldSource::Named(named) => docs_from_ast(&*named),
43 FieldSource::Pos(..) => return None,
44 }
45 }
46}
47
48impl Docs for Struct {
49 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
50 docs_from_ast(&*self.source(db).1)
51 }
52}
53
54impl Docs for Union {
55 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
56 docs_from_ast(&*self.source(db).1)
57 }
58}
59
60impl Docs for Enum {
61 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
62 docs_from_ast(&*self.source(db).1)
63 }
64}
65
66impl Docs for EnumVariant {
67 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
68 docs_from_ast(&*self.source(db).1)
69 }
70}
71
72impl Docs for Function {
73 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
74 docs_from_ast(&*self.source(db).1)
75 }
76}
77
78impl Docs for Const {
79 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
80 docs_from_ast(&*self.source(db).1)
81 }
82}
83
84impl Docs for Static {
85 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
86 docs_from_ast(&*self.source(db).1)
87 }
88}
89
90impl Docs for Trait {
91 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
92 docs_from_ast(&*self.source(db).1)
93 }
94}
95
96impl Docs for TypeAlias {
97 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
98 docs_from_ast(&*self.source(db).1)
99 }
100}