@@ -2,7 +2,7 @@ use axum::response::Html;
22use prost:: Message ;
33use prost_types:: { FileDescriptorSet , SourceCodeInfo } ;
44
5- use crate :: lib :: proto:: FILE_DESCRIPTOR_SET ;
5+ use crate :: service :: proto:: FILE_DESCRIPTOR_SET ;
66
77/// Resolve a path in source_code_info to find the leading comment.
88/// Proto paths are documented in descriptor.proto's SourceCodeInfo.
@@ -19,7 +19,10 @@ fn find_comment(source_info: &SourceCodeInfo, path: &[i32]) -> Option<String> {
1919 } )
2020}
2121
22- fn field_type_name ( field : & prost_types:: FieldDescriptorProto , package : & str ) -> String {
22+ fn field_type_name (
23+ field : & prost_types:: FieldDescriptorProto ,
24+ package : & str ,
25+ ) -> String {
2326 if let Some ( ref type_name) = field. type_name {
2427 // Strip leading dot and package prefix from fully-qualified names
2528 let stripped = type_name. strip_prefix ( '.' ) . unwrap_or ( type_name) ;
@@ -73,7 +76,8 @@ fn escape_html(s: &str) -> String {
7376}
7477
7578pub async fn reflection_ui ( ) -> Html < String > {
76- let fds = FileDescriptorSet :: decode ( FILE_DESCRIPTOR_SET ) . expect ( "failed to decode descriptor" ) ;
79+ let fds = FileDescriptorSet :: decode ( FILE_DESCRIPTOR_SET )
80+ . expect ( "failed to decode descriptor" ) ;
7781
7882 let mut html = String :: from (
7983 r#"<!DOCTYPE html>
@@ -118,12 +122,18 @@ pub async fn reflection_ui() -> Html<String> {
118122 for ( si, service) in file. service . iter ( ) . enumerate ( ) {
119123 let service_name = service. name . as_deref ( ) . unwrap_or ( "Unknown" ) ;
120124
121- html. push_str ( & format ! ( r#"<div class="service"><h2>{}</h2>"# , escape_html( service_name) ) ) ;
125+ html. push_str ( & format ! (
126+ r#"<div class="service"><h2>{}</h2>"# ,
127+ escape_html( service_name)
128+ ) ) ;
122129
123- if let Some ( ref si_info) = source_info {
124- if let Some ( comment) = find_comment ( si_info, & [ 6 , si as i32 ] ) {
125- html. push_str ( & format ! ( r#"<p class="comment">{}</p>"# , escape_html( & comment) ) ) ;
126- }
130+ if let Some ( si_info) = source_info
131+ && let Some ( comment) = find_comment ( si_info, & [ 6 , si as i32 ] )
132+ {
133+ html. push_str ( & format ! (
134+ r#"<p class="comment">{}</p>"# ,
135+ escape_html( & comment)
136+ ) ) ;
127137 }
128138
129139 // Methods: path [6, service_index, 2, method_index]
@@ -146,24 +156,29 @@ pub async fn reflection_ui() -> Html<String> {
146156
147157 html. push_str ( r#"<div class="method">"# ) ;
148158
149- if let Some ( ref si_info) = source_info {
150- if let Some ( comment) = find_comment ( si_info, & [ 6 , si as i32 , 2 , mi as i32 ] ) {
151- html. push_str ( & format ! (
152- r#"<p class="comment">{}</p>"# ,
153- escape_html( & comment)
154- ) ) ;
155- }
159+ if let Some ( si_info) = source_info
160+ && let Some ( comment) =
161+ find_comment ( si_info, & [ 6 , si as i32 , 2 , mi as i32 ] )
162+ {
163+ html. push_str ( & format ! (
164+ r#"<p class="comment">{}</p>"# ,
165+ escape_html( & comment)
166+ ) ) ;
156167 }
157168
158169 let client_streaming = method. client_streaming . unwrap_or ( false ) ;
159170 let server_streaming = method. server_streaming . unwrap_or ( false ) ;
160171
161172 let mut tags = String :: new ( ) ;
162173 if client_streaming {
163- tags. push_str ( r#"<span class="tag">client streaming</span>"# ) ;
174+ tags. push_str (
175+ r#"<span class="tag">client streaming</span>"# ,
176+ ) ;
164177 }
165178 if server_streaming {
166- tags. push_str ( r#"<span class="tag">server streaming</span>"# ) ;
179+ tags. push_str (
180+ r#"<span class="tag">server streaming</span>"# ,
181+ ) ;
167182 }
168183 if !client_streaming && !server_streaming {
169184 tags. push_str ( r#"<span class="tag">unary</span>"# ) ;
@@ -195,10 +210,13 @@ pub async fn reflection_ui() -> Html<String> {
195210 escape_html( msg_name)
196211 ) ) ;
197212
198- if let Some ( ref si_info) = source_info {
199- if let Some ( comment) = find_comment ( si_info, & [ 4 , mi as i32 ] ) {
200- html. push_str ( & format ! ( r#"<p class="comment">{}</p>"# , escape_html( & comment) ) ) ;
201- }
213+ if let Some ( si_info) = source_info
214+ && let Some ( comment) = find_comment ( si_info, & [ 4 , mi as i32 ] )
215+ {
216+ html. push_str ( & format ! (
217+ r#"<p class="comment">{}</p>"# ,
218+ escape_html( & comment)
219+ ) ) ;
202220 }
203221
204222 if !message. field . is_empty ( ) {
@@ -213,12 +231,15 @@ pub async fn reflection_ui() -> Html<String> {
213231 let flabel = label_str ( field) ;
214232
215233 let field_comment = source_info
216- . and_then ( |si| find_comment ( si, & [ 4 , mi as i32 , 2 , fi as i32 ] ) )
234+ . and_then ( |si| {
235+ find_comment ( si, & [ 4 , mi as i32 , 2 , fi as i32 ] )
236+ } )
217237 . or_else ( || {
218238 // Also check trailing comments
219239 source_info. and_then ( |si| {
220240 si. location . iter ( ) . find_map ( |loc| {
221- if loc. path == [ 4 , mi as i32 , 2 , fi as i32 ] {
241+ if loc. path == [ 4 , mi as i32 , 2 , fi as i32 ]
242+ {
222243 loc. trailing_comments
223244 . as_ref ( )
224245 . map ( |c| c. trim ( ) . to_string ( ) )
@@ -256,10 +277,13 @@ pub async fn reflection_ui() -> Html<String> {
256277 escape_html( enum_name)
257278 ) ) ;
258279
259- if let Some ( ref si_info) = source_info {
260- if let Some ( comment) = find_comment ( si_info, & [ 5 , ei as i32 ] ) {
261- html. push_str ( & format ! ( r#"<p class="comment">{}</p>"# , escape_html( & comment) ) ) ;
262- }
280+ if let Some ( si_info) = source_info
281+ && let Some ( comment) = find_comment ( si_info, & [ 5 , ei as i32 ] )
282+ {
283+ html. push_str ( & format ! (
284+ r#"<p class="comment">{}</p>"# ,
285+ escape_html( & comment)
286+ ) ) ;
263287 }
264288
265289 if !enum_type. value . is_empty ( ) {
@@ -270,7 +294,9 @@ pub async fn reflection_ui() -> Html<String> {
270294 let vnum = value. number . unwrap_or ( 0 ) ;
271295
272296 let value_comment = source_info
273- . and_then ( |si| find_comment ( si, & [ 5 , ei as i32 , 2 , vi as i32 ] ) )
297+ . and_then ( |si| {
298+ find_comment ( si, & [ 5 , ei as i32 , 2 , vi as i32 ] )
299+ } )
274300 . unwrap_or_default ( ) ;
275301
276302 html. push_str ( & format ! (
@@ -290,4 +316,4 @@ pub async fn reflection_ui() -> Html<String> {
290316
291317 html. push_str ( "</body></html>" ) ;
292318 Html ( html)
293- }
319+ }
0 commit comments