Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions private/buf/buflsp/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,22 +408,27 @@ func (s *symbol) getDocsFromComments() string {
_, start := def.Context().Stream().Around(def.Span().Start)
cursor := token.NewCursorAt(start)
t := cursor.PrevSkippable()
var addNewline bool
for !t.IsZero() {
switch t.Kind() {
case token.Comment:
comments = append(comments, commentToMarkdown(t.Text()))
text := t.Text()
if addNewline {
text += "\n"
addNewline = false
}
comments = append(comments, commentToMarkdown(text))
case token.Space:
// If the space token only contains spaces (e.g. code indentation), then we drop it.
// If the space token ends in a new-line, we append it to the comment above for formatting.
if strings.HasSuffix(t.Text(), "\n") {
addNewline = true
}
}
prev := cursor.PeekPrevSkippable()
if !prev.Kind().IsSkippable() {
break
}
if prev.Kind() == token.Space {
// Check if the whitespace contains a newline. If so, then we break. This is to prevent
// picking up comments that are not contiguous to the declaration.
if strings.Contains(prev.Text(), "\n") {
break
}
}
t = cursor.PrevSkippable()
}
comments = lineUpComments(comments)
Expand Down