8
8
use std:: collections:: HashMap ;
9
9
10
10
use crate :: meta:: ClassId ;
11
- use crate :: registry:: plugin:: { ITraitImpl , InherentImpl , PluginItem , Struct } ;
11
+ use crate :: obj:: GodotClass ;
12
+
13
+ /// Piece of information that is gathered by the self-registration ("plugin") system.
14
+ ///
15
+ /// You should not manually construct this struct, but rather use [`DocsPlugin::new()`].
16
+ #[ derive( Debug ) ]
17
+ pub struct DocsPlugin {
18
+ /// The name of the class to register docs for.
19
+ pub ( crate ) class_name : ClassId ,
20
+
21
+ /// The actual item being registered.
22
+ pub item : DocsItem ,
23
+ }
24
+
25
+ impl DocsPlugin {
26
+ /// Creates a new `DocsPlugin`, automatically setting the `class_name` to the values defined in [`GodotClass`].
27
+ pub fn new < T : GodotClass > ( item : DocsItem ) -> Self {
28
+ Self {
29
+ class_name : T :: class_id ( ) ,
30
+ item,
31
+ }
32
+ }
33
+ }
34
+
35
+ #[ derive( Debug ) ]
36
+ pub enum DocsItem {
37
+ Struct ( StructDocs ) ,
38
+ InherentImpl ( InherentImplDocs ) ,
39
+ VirtualMethods ( & ' static str ) ,
40
+ }
12
41
13
42
/// Created for documentation on
14
43
/// ```ignore
@@ -29,7 +58,7 @@ pub struct StructDocs {
29
58
pub members : & ' static str ,
30
59
}
31
60
32
- /// Keeps documentation for inherent `impl` blocks, such as:
61
+ /// Keeps documentation for inherent `impl` blocks (primary and secondary) , such as:
33
62
/// ```ignore
34
63
/// #[godot_api]
35
64
/// impl Struct {
@@ -46,18 +75,19 @@ pub struct StructDocs {
46
75
/// }
47
76
/// ```
48
77
/// All fields are XML parts, escaped where necessary.
49
- #[ derive( Default , Copy , Clone , Debug ) ]
78
+ #[ derive( Default , Clone , Debug ) ]
50
79
pub struct InherentImplDocs {
51
- pub methods : Vec < & ' static str > ,
52
- pub signals : Vec < & ' static str > ,
53
- pub constants : Vec < & ' static str > ,
80
+ pub methods : & ' static str ,
81
+ pub signals : & ' static str ,
82
+ pub constants : & ' static str ,
54
83
}
55
84
56
85
#[ derive( Default ) ]
57
86
struct DocPieces {
58
87
definition : StructDocs ,
59
- inherent : InherentImplDocs ,
60
- virtual_methods : Vec < & ' static str > ,
88
+ methods : Vec < & ' static str > ,
89
+ signals : Vec < & ' static str > ,
90
+ constants : Vec < & ' static str > ,
61
91
}
62
92
63
93
/// This function scours the registered plugins to find their documentation pieces,
@@ -76,68 +106,66 @@ struct DocPieces {
76
106
#[ doc( hidden) ]
77
107
pub fn gather_xml_docs ( ) -> impl Iterator < Item = String > {
78
108
let mut map = HashMap :: < ClassId , DocPieces > :: new ( ) ;
79
- crate :: private:: iterate_plugins ( |x| {
109
+ crate :: private:: iterate_docs_plugins ( |x| {
80
110
let class_name = x. class_name ;
81
-
82
111
match & x. item {
83
- PluginItem :: InherentImpl ( InherentImpl { docs , .. } ) => {
84
- map. entry ( class_name) . or_default ( ) . inherent = docs . clone ( ) ;
112
+ DocsItem :: Struct ( s ) => {
113
+ map. entry ( class_name) . or_default ( ) . definition = * s ;
85
114
}
86
- PluginItem :: ITraitImpl ( ITraitImpl {
87
- virtual_method_docs,
88
- ..
89
- } ) => map
90
- . entry ( class_name)
91
- . or_default ( )
92
- . virtual_methods
93
- . push ( virtual_method_docs) ,
94
-
95
- PluginItem :: Struct ( Struct { docs, .. } ) => {
96
- map. entry ( class_name) . or_default ( ) . definition = * docs;
115
+ DocsItem :: InherentImpl ( i) => {
116
+ let InherentImplDocs {
117
+ methods,
118
+ constants,
119
+ signals,
120
+ } = i;
121
+ map. entry ( class_name) . or_default ( ) . methods . push ( methods) ;
122
+ map. entry ( class_name)
123
+ . and_modify ( |pieces| pieces. constants . push ( constants) ) ;
124
+ map. entry ( class_name)
125
+ . and_modify ( |pieces| pieces. signals . push ( signals) ) ;
126
+ }
127
+ DocsItem :: VirtualMethods ( methods) => {
128
+ map. entry ( class_name) . or_default ( ) . methods . push ( methods) ;
97
129
}
98
-
99
- _ => ( ) ,
100
130
}
101
131
} ) ;
102
132
103
133
map. into_iter ( ) . map ( |( class, pieces) | {
104
- let StructDocs {
105
- base,
106
- description,
107
- experimental,
108
- deprecated,
109
- members,
110
- } = pieces. definition ;
111
-
112
- let virtual_methods = pieces. virtual_methods ;
113
-
114
- let mut method_docs = String :: from_iter ( pieces. inherent . methods ) ;
115
- let signal_docs = String :: from_iter ( pieces. inherent . signals ) ;
116
- let constant_docs = String :: from_iter ( pieces. inherent . constants ) ;
117
-
118
- method_docs. extend ( virtual_methods) ;
119
- let methods_block = if method_docs. is_empty ( ) {
120
- String :: new ( )
121
- } else {
122
- format ! ( "<methods>{method_docs}</methods>" )
123
- } ;
124
- let signals_block = if signal_docs. is_empty ( ) {
125
- String :: new ( )
126
- } else {
127
- format ! ( "<signals>{signal_docs}</signals>" )
128
- } ;
129
- let constants_block = if constant_docs. is_empty ( ) {
130
- String :: new ( )
131
- } else {
132
- format ! ( "<constants>{constant_docs}</constants>" )
133
- } ;
134
- let ( brief, description) = match description
135
- . split_once ( "[br]" ) {
136
- Some ( ( brief, description) ) => ( brief, description. trim_start_matches ( "[br]" ) ) ,
137
- None => ( description, "" ) ,
138
- } ;
139
-
140
- format ! ( r#"<?xml version="1.0" encoding="UTF-8"?>
134
+ let StructDocs {
135
+ base,
136
+ description,
137
+ experimental,
138
+ deprecated,
139
+ members,
140
+ } = pieces. definition ;
141
+
142
+
143
+ let method_docs = String :: from_iter ( pieces. methods ) ;
144
+ let signal_docs = String :: from_iter ( pieces. signals ) ;
145
+ let constant_docs = String :: from_iter ( pieces. constants ) ;
146
+
147
+ let methods_block = if method_docs. is_empty ( ) {
148
+ String :: new ( )
149
+ } else {
150
+ format ! ( "<methods>{method_docs}</methods>" )
151
+ } ;
152
+ let signals_block = if signal_docs. is_empty ( ) {
153
+ String :: new ( )
154
+ } else {
155
+ format ! ( "<signals>{signal_docs}</signals>" )
156
+ } ;
157
+ let constants_block = if constant_docs. is_empty ( ) {
158
+ String :: new ( )
159
+ } else {
160
+ format ! ( "<constants>{constant_docs}</constants>" )
161
+ } ;
162
+ let ( brief, description) = match description
163
+ . split_once ( "[br]" ) {
164
+ Some ( ( brief, description) ) => ( brief, description. trim_start_matches ( "[br]" ) ) ,
165
+ None => ( description, "" ) ,
166
+ } ;
167
+
168
+ format ! ( r#"<?xml version="1.0" encoding="UTF-8"?>
141
169
<class name="{class}" inherits="{base}"{deprecated}{experimental} xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
142
170
<brief_description>{brief}</brief_description>
143
171
<description>{description}</description>
@@ -146,8 +174,8 @@ pub fn gather_xml_docs() -> impl Iterator<Item = String> {
146
174
{signals_block}
147
175
<members>{members}</members>
148
176
</class>"# )
149
- } ,
150
- )
177
+ } ,
178
+ )
151
179
}
152
180
153
181
/// # Safety
0 commit comments