File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -345,27 +345,60 @@ impl Backend {
345345}
346346
347347fn get_comments_from_lines ( line : u32 , rope : & Rope ) -> String {
348- let mut result = vec ! [ ] ;
348+ let mut lines = Vec :: new ( ) ;
349349
350350 if line == 0 {
351351 return String :: new ( ) ;
352352 }
353+
353354 for i in ( 0 ..line) . rev ( ) {
354355 let Some ( rope_slice) = rope. get_line ( i as usize ) else {
355356 break ;
356357 } ;
357358 let text = rope_slice. to_string ( ) ;
358359
359360 if text. starts_with ( "///" ) {
360- let doc = text. strip_prefix ( "///" ) . unwrap_or ( "" ) . to_string ( ) ;
361- result. push ( doc) ;
361+ let doc = text
362+ . strip_prefix ( "///" )
363+ . unwrap_or ( "" )
364+ . trim_end ( )
365+ . to_string ( ) ;
366+ lines. push ( doc) ;
362367 } else {
363368 break ;
364369 }
365370 }
366371
367- result. reverse ( ) ;
368- result. join ( "\n " )
372+ lines. reverse ( ) ;
373+
374+ let mut result = String :: new ( ) ;
375+ let mut prev_line_was_text = false ;
376+
377+ for line in lines {
378+ let trimmed = line. trim ( ) ;
379+
380+ let is_md_block = trimmed. is_empty ( )
381+ || trimmed. starts_with ( '#' )
382+ || trimmed. starts_with ( '-' )
383+ || trimmed. starts_with ( '*' )
384+ || trimmed. starts_with ( '>' )
385+ || trimmed. starts_with ( "```" )
386+ || trimmed. starts_with ( " " ) ;
387+
388+ if result. is_empty ( ) {
389+ result. push_str ( trimmed) ;
390+ } else if prev_line_was_text && !is_md_block {
391+ result. push ( ' ' ) ;
392+ result. push_str ( trimmed) ;
393+ } else {
394+ result. push ( '\n' ) ;
395+ result. push_str ( trimmed) ;
396+ }
397+
398+ prev_line_was_text = !trimmed. is_empty ( ) && !is_md_block;
399+ }
400+
401+ result
369402}
370403
371404fn find_related_call (
You can’t perform that action at this time.
0 commit comments