File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed
Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -408,22 +408,27 @@ func (s *symbol) getDocsFromComments() string {
408408 _ , start := def .Context ().Stream ().Around (def .Span ().Start )
409409 cursor := token .NewCursorAt (start )
410410 t := cursor .PrevSkippable ()
411+ var addNewline bool
411412 for ! t .IsZero () {
412413 switch t .Kind () {
413414 case token .Comment :
414- comments = append (comments , commentToMarkdown (t .Text ()))
415+ text := t .Text ()
416+ if addNewline {
417+ text += "\n "
418+ addNewline = false
419+ }
420+ comments = append (comments , commentToMarkdown (text ))
421+ case token .Space :
422+ // If the space token only contains spaces (e.g. code indentation), then we drop it.
423+ // If the space token ends in a new-line, we append it to the comment above for formatting.
424+ if strings .HasSuffix (t .Text (), "\n " ) {
425+ addNewline = true
426+ }
415427 }
416428 prev := cursor .PeekPrevSkippable ()
417429 if ! prev .Kind ().IsSkippable () {
418430 break
419431 }
420- if prev .Kind () == token .Space {
421- // Check if the whitespace contains a newline. If so, then we break. This is to prevent
422- // picking up comments that are not contiguous to the declaration.
423- if strings .Contains (prev .Text (), "\n " ) {
424- break
425- }
426- }
427432 t = cursor .PrevSkippable ()
428433 }
429434 comments = lineUpComments (comments )
You can’t perform that action at this time.
0 commit comments