diff options
author | Aleksey Kladov <[email protected]> | 2019-06-08 11:51:18 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-06-08 11:53:14 +0100 |
commit | 5dc27898959d2330b0822d95a9ee2488e687895a (patch) | |
tree | 546680fa805ab2926106ec4ce2f35ae12831e135 /crates/ra_hir | |
parent | 2a6b363b44e335af5f26ac503461ef15cca82ace (diff) |
Move docs to dedicated module
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 68 | ||||
-rw-r--r-- | 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 { | |||
319 | } | 319 | } |
320 | } | 320 | } |
321 | 321 | ||
322 | impl 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)] |
329 | pub struct StructField { | 323 | pub struct StructField { |
330 | pub(crate) parent: VariantDef, | 324 | pub(crate) parent: VariantDef, |
@@ -355,15 +349,6 @@ impl StructField { | |||
355 | } | 349 | } |
356 | } | 350 | } |
357 | 351 | ||
358 | impl 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)] |
368 | pub struct Struct { | 353 | pub struct Struct { |
369 | pub(crate) id: StructId, | 354 | pub(crate) id: StructId, |
@@ -425,12 +410,6 @@ impl Struct { | |||
425 | } | 410 | } |
426 | } | 411 | } |
427 | 412 | ||
428 | impl 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)] |
435 | pub struct Union { | 414 | pub struct Union { |
436 | pub(crate) id: StructId, | 415 | pub(crate) id: StructId, |
@@ -464,12 +443,6 @@ impl Union { | |||
464 | } | 443 | } |
465 | } | 444 | } |
466 | 445 | ||
467 | impl 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)] |
474 | pub struct Enum { | 447 | pub struct Enum { |
475 | pub(crate) id: EnumId, | 448 | pub(crate) id: EnumId, |
@@ -519,12 +492,6 @@ impl Enum { | |||
519 | } | 492 | } |
520 | } | 493 | } |
521 | 494 | ||
522 | impl 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)] |
529 | pub struct EnumVariant { | 496 | pub struct EnumVariant { |
530 | pub(crate) parent: Enum, | 497 | pub(crate) parent: Enum, |
@@ -568,12 +535,6 @@ impl EnumVariant { | |||
568 | } | 535 | } |
569 | } | 536 | } |
570 | 537 | ||
571 | impl 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)] |
579 | pub enum DefWithBody { | 540 | pub enum DefWithBody { |
@@ -757,12 +718,6 @@ impl Function { | |||
757 | } | 718 | } |
758 | } | 719 | } |
759 | 720 | ||
760 | impl 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)] |
767 | pub struct Const { | 722 | pub struct Const { |
768 | pub(crate) id: ConstId, | 723 | pub(crate) id: ConstId, |
@@ -806,12 +761,6 @@ impl Const { | |||
806 | } | 761 | } |
807 | } | 762 | } |
808 | 763 | ||
809 | impl 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)] |
817 | pub struct ConstSignature { | 766 | pub struct ConstSignature { |
@@ -884,12 +833,6 @@ impl Static { | |||
884 | } | 833 | } |
885 | } | 834 | } |
886 | 835 | ||
887 | impl 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)] |
894 | pub struct Trait { | 837 | pub struct Trait { |
895 | pub(crate) id: TraitId, | 838 | pub(crate) id: TraitId, |
@@ -936,12 +879,6 @@ impl Trait { | |||
936 | } | 879 | } |
937 | } | 880 | } |
938 | 881 | ||
939 | impl 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)] |
946 | pub struct TypeAlias { | 883 | pub struct TypeAlias { |
947 | pub(crate) id: TypeAliasId, | 884 | pub(crate) id: TypeAliasId, |
@@ -998,11 +935,6 @@ impl TypeAlias { | |||
998 | } | 935 | } |
999 | } | 936 | } |
1000 | 937 | ||
1001 | impl 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)] |
1007 | pub struct MacroDef { | 939 | pub 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 @@ | |||
1 | use ra_syntax::ast; | 1 | use ra_syntax::ast; |
2 | 2 | ||
3 | use crate::HirDatabase; | 3 | use 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 { | |||
29 | pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option<Documentation> { | 29 | pub(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 | |||
33 | impl 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 | |||
39 | impl 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 | |||
48 | impl Docs for Struct { | ||
49 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { | ||
50 | docs_from_ast(&*self.source(db).1) | ||
51 | } | ||
52 | } | ||
53 | |||
54 | impl Docs for Union { | ||
55 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { | ||
56 | docs_from_ast(&*self.source(db).1) | ||
57 | } | ||
58 | } | ||
59 | |||
60 | impl Docs for Enum { | ||
61 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { | ||
62 | docs_from_ast(&*self.source(db).1) | ||
63 | } | ||
64 | } | ||
65 | |||
66 | impl Docs for EnumVariant { | ||
67 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { | ||
68 | docs_from_ast(&*self.source(db).1) | ||
69 | } | ||
70 | } | ||
71 | |||
72 | impl Docs for Function { | ||
73 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { | ||
74 | docs_from_ast(&*self.source(db).1) | ||
75 | } | ||
76 | } | ||
77 | |||
78 | impl Docs for Const { | ||
79 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { | ||
80 | docs_from_ast(&*self.source(db).1) | ||
81 | } | ||
82 | } | ||
83 | |||
84 | impl Docs for Static { | ||
85 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { | ||
86 | docs_from_ast(&*self.source(db).1) | ||
87 | } | ||
88 | } | ||
89 | |||
90 | impl Docs for Trait { | ||
91 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { | ||
92 | docs_from_ast(&*self.source(db).1) | ||
93 | } | ||
94 | } | ||
95 | |||
96 | impl Docs for TypeAlias { | ||
97 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { | ||
98 | docs_from_ast(&*self.source(db).1) | ||
99 | } | ||
100 | } | ||