From 6e5560fb97283106ee4713fdfa53043c0b232a47 Mon Sep 17 00:00:00 2001 From: Doria Keung Date: Mon, 15 Dec 2025 13:59:51 -0500 Subject: [PATCH 1/2] Fix documentation hovers for protocompile update --- private/buf/buflsp/symbol.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/private/buf/buflsp/symbol.go b/private/buf/buflsp/symbol.go index 7474ed99a7..70f12b4e93 100644 --- a/private/buf/buflsp/symbol.go +++ b/private/buf/buflsp/symbol.go @@ -408,22 +408,28 @@ func (s *symbol) getDocsFromComments() string { _, start := def.Context().Stream().Around(def.Span().Start) cursor := token.NewCursorAt(start) t := cursor.PrevSkippable() + var addNewline string for !t.IsZero() { switch t.Kind() { case token.Comment: - comments = append(comments, commentToMarkdown(t.Text())) + text := t.Text() + if addNewline != "" { + text += addNewline + addNewline = "" + } + 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 is a new-line, we append it to the comment above for formatting. + // We store the space token text to account for carriage returns (\r\n). + if t.Text() == "\n" || t.Text() == "\r\n" { + addNewline = t.Text() + } } 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) From ad283c53a55a77d15ce61a3f20be87fc2eb606f4 Mon Sep 17 00:00:00 2001 From: Doria Keung Date: Mon, 15 Dec 2025 15:03:53 -0500 Subject: [PATCH 2/2] Do not need to check for carriage returns --- private/buf/buflsp/symbol.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/private/buf/buflsp/symbol.go b/private/buf/buflsp/symbol.go index 70f12b4e93..12b8af3d26 100644 --- a/private/buf/buflsp/symbol.go +++ b/private/buf/buflsp/symbol.go @@ -408,22 +408,21 @@ func (s *symbol) getDocsFromComments() string { _, start := def.Context().Stream().Around(def.Span().Start) cursor := token.NewCursorAt(start) t := cursor.PrevSkippable() - var addNewline string + var addNewline bool for !t.IsZero() { switch t.Kind() { case token.Comment: text := t.Text() - if addNewline != "" { - text += addNewline - addNewline = "" + 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 is a new-line, we append it to the comment above for formatting. - // We store the space token text to account for carriage returns (\r\n). - if t.Text() == "\n" || t.Text() == "\r\n" { - addNewline = t.Text() + // 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()