5
5
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
6
*/
7
7
8
- use crate :: meta:: ClassName ;
9
- use crate :: registry:: plugin:: { ITraitImpl , InherentImpl , PluginItem , Struct } ;
10
8
use std:: collections:: HashMap ;
11
9
10
+ use crate :: meta:: ClassName ;
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
+ }
41
+
12
42
/// Created for documentation on
13
43
/// ```ignore
14
44
/// #[derive(GodotClass)]
@@ -28,7 +58,7 @@ pub struct StructDocs {
28
58
pub members : & ' static str ,
29
59
}
30
60
31
- /// Keeps documentation for inherent `impl` blocks, such as:
61
+ /// Keeps documentation for inherent `impl` blocks (primary and secondary) , such as:
32
62
/// ```ignore
33
63
/// #[godot_api]
34
64
/// impl Struct {
@@ -47,16 +77,17 @@ pub struct StructDocs {
47
77
/// All fields are XML parts, escaped where necessary.
48
78
#[ derive( Clone , Debug , Default ) ]
49
79
pub struct InherentImplDocs {
50
- pub methods : Vec < & ' static str > ,
51
- pub signals : Vec < & ' static str > ,
52
- pub constants : Vec < & ' static str > ,
80
+ pub methods : & ' static str ,
81
+ pub signals : & ' static str ,
82
+ pub constants : & ' static str ,
53
83
}
54
84
55
85
#[ derive( Default ) ]
56
86
struct DocPieces {
57
87
definition : StructDocs ,
58
- inherent : InherentImplDocs ,
59
- virtual_methods : Vec < & ' static str > ,
88
+ methods : Vec < & ' static str > ,
89
+ signals : Vec < & ' static str > ,
90
+ constants : Vec < & ' static str > ,
60
91
}
61
92
62
93
/// This function scours the registered plugins to find their documentation pieces,
@@ -75,68 +106,66 @@ struct DocPieces {
75
106
#[ doc( hidden) ]
76
107
pub fn gather_xml_docs ( ) -> impl Iterator < Item = String > {
77
108
let mut map = HashMap :: < ClassName , DocPieces > :: new ( ) ;
78
- crate :: private:: iterate_plugins ( |x| {
109
+ crate :: private:: iterate_docs_plugins ( |x| {
79
110
let class_name = x. class_name ;
80
-
81
111
match & x. item {
82
- PluginItem :: InherentImpl ( InherentImpl { docs , .. } ) => {
83
- map. entry ( class_name) . or_default ( ) . inherent = docs . clone ( ) ;
112
+ DocsItem :: Struct ( s ) => {
113
+ map. entry ( class_name) . or_default ( ) . definition = * s ;
84
114
}
85
- PluginItem :: ITraitImpl ( ITraitImpl {
86
- virtual_method_docs,
87
- ..
88
- } ) => map
89
- . entry ( class_name)
90
- . or_default ( )
91
- . virtual_methods
92
- . push ( virtual_method_docs) ,
93
-
94
- PluginItem :: Struct ( Struct { docs, .. } ) => {
95
- 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) ;
96
129
}
97
-
98
- _ => ( ) ,
99
130
}
100
131
} ) ;
101
132
102
133
map. into_iter ( ) . map ( |( class, pieces) | {
103
- let StructDocs {
104
- base,
105
- description,
106
- experimental,
107
- deprecated,
108
- members,
109
- } = pieces. definition ;
110
-
111
- let virtual_methods = pieces. virtual_methods ;
112
-
113
- let mut method_docs = String :: from_iter ( pieces. inherent . methods ) ;
114
- let signal_docs = String :: from_iter ( pieces. inherent . signals ) ;
115
- let constant_docs = String :: from_iter ( pieces. inherent . constants ) ;
116
-
117
- method_docs. extend ( virtual_methods) ;
118
- let methods_block = if method_docs. is_empty ( ) {
119
- String :: new ( )
120
- } else {
121
- format ! ( "<methods>{method_docs}</methods>" )
122
- } ;
123
- let signals_block = if signal_docs. is_empty ( ) {
124
- String :: new ( )
125
- } else {
126
- format ! ( "<signals>{signal_docs}</signals>" )
127
- } ;
128
- let constants_block = if constant_docs. is_empty ( ) {
129
- String :: new ( )
130
- } else {
131
- format ! ( "<constants>{constant_docs}</constants>" )
132
- } ;
133
- let ( brief, description) = match description
134
- . split_once ( "[br]" ) {
135
- Some ( ( brief, description) ) => ( brief, description. trim_start_matches ( "[br]" ) ) ,
136
- None => ( description, "" ) ,
137
- } ;
138
-
139
- 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"?>
140
169
<class name="{class}" inherits="{base}"{deprecated}{experimental} xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
141
170
<brief_description>{brief}</brief_description>
142
171
<description>{description}</description>
@@ -145,8 +174,8 @@ pub fn gather_xml_docs() -> impl Iterator<Item = String> {
145
174
{signals_block}
146
175
<members>{members}</members>
147
176
</class>"# )
148
- } ,
149
- )
177
+ } ,
178
+ )
150
179
}
151
180
152
181
/// # Safety
0 commit comments