Skip to content

Commit 1cae155

Browse files
authored
Fix documentation hovers for protocompile update (#4228)
1 parent 4c146e5 commit 1cae155

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

private/buf/buflsp/symbol.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)