File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -352,11 +352,28 @@ func (s *symbol) getDocsFromComments() string {
352352 // traversing backwards for leading comemnts only.
353353 _ , start := def .Context ().Stream ().Around (def .Span ().Start )
354354 cursor := token .NewCursorAt (start )
355- for t := cursor .PrevSkippable (); t .Kind () == token .Comment ; t = cursor .PrevSkippable () {
356- comments = append (comments , commentToMarkdown (t .Text ()))
355+ t := cursor .PrevSkippable ()
356+ for ! t .IsZero () {
357+ switch t .Kind () {
358+ case token .Comment :
359+ comments = append (comments , commentToMarkdown (t .Text ()))
360+ }
361+ prev := cursor .PeekPrevSkippable ()
362+ if ! prev .Kind ().IsSkippable () {
363+ break
364+ }
365+ if prev .Kind () == token .Space {
366+ // Check if the whitespace contains a newline. If so, then we break. This is to prevent
367+ // picking up comments that are not contiguous to the declaration.
368+ if strings .Contains (prev .Text (), "\n " ) {
369+ break
370+ }
371+ }
372+ t = cursor .PrevSkippable ()
357373 }
374+ comments = lineUpComments (comments )
358375 // Reverse the list and return joined.
359- slices .Reverse (lineUpComments ( comments ) )
376+ slices .Reverse (comments )
360377
361378 var docs strings.Builder
362379 for _ , comment := range comments {
You can’t perform that action at this time.
0 commit comments