Skip to content

Commit 331fb31

Browse files
authored
Fix comments (#4166)
1 parent 3312114 commit 331fb31

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

private/buf/buflsp/symbol.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff 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 {

0 commit comments

Comments
 (0)