Skip to content

Commit f2ab229

Browse files
authored
Check for newlines in parsing docs comments (#4164)
1 parent c7068a4 commit f2ab229

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

private/buf/buflsp/symbol.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,17 @@ func (s *symbol) getDocsFromComments() string {
357357
case token.Comment:
358358
comments = append(comments, commentToMarkdown(t.Text()))
359359
}
360-
if !cursor.PeekPrevSkippable().Kind().IsSkippable() {
360+
prev := cursor.PeekPrevSkippable()
361+
if !prev.Kind().IsSkippable() {
361362
break
362363
}
364+
if prev.Kind() == token.Space {
365+
// Check if the whitespace contains a newline. If so, then we break. This is to prevent
366+
// picking up comments that are not contiguous to the declaration.
367+
if strings.Contains(prev.Text(), "\n") {
368+
break
369+
}
370+
}
363371
t = cursor.PrevSkippable()
364372
}
365373
// Reverse the list and return joined.

0 commit comments

Comments
 (0)