Skip to content
Open
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
18 changes: 17 additions & 1 deletion internal/ls/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,24 @@ func (l *LanguageService) getDocumentationFromDeclaration(c *checker.Checker, de
}
comments := tag.Comments()
if tag.Kind == ast.KindJSDocTag && tag.TagName().Text() == "example" {
b.WriteString("\n")
commentText := strings.TrimRight(getCommentText(comments), " \t\r\n")
if strings.HasPrefix(commentText, "<caption>") {
if captionEnd := strings.Index(commentText, "</caption>"); captionEnd > 0 {
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition captionEnd > 0 allows empty captions (e.g., <caption></caption>) to be processed, which will result in an em-dash followed by nothing. Consider using captionEnd > len("<caption>") to only process captions that contain actual content, or document that empty captions are intentionally supported.

Suggested change
if captionEnd := strings.Index(commentText, "</caption>"); captionEnd > 0 {
if captionEnd := strings.Index(commentText, "</caption>"); captionEnd > len("<caption>") {

Copilot uses AI. Check for mistakes.
b.WriteString(" — ")
b.WriteString(commentText[len("<caption>"):captionEnd])
commentText = commentText[captionEnd+len("</caption>"):]
// Trim leading blank lines from commentText
for {
s1 := strings.TrimLeft(commentText, " \t")
s2 := strings.TrimLeft(s1, "\r\n")
if len(s1) == len(s2) {
break
}
commentText = s2
}
}
}
Comment on lines +113 to +128
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caption extraction feature lacks test coverage. According to the project guidelines, when implementing a new feature, at least one minimal test case should always be added to verify the fix. Please add a test case in testdata/tests/cases/compiler/ that demonstrates JSDoc @example tags with <caption></caption> tags to verify this functionality works correctly.

Copilot uses AI. Check for mistakes.
b.WriteString("\n")
if len(commentText) > 6 && strings.HasPrefix(commentText, "```") && strings.HasSuffix(commentText, "```") && strings.Contains(commentText, "\n") {
b.WriteString(commentText)
b.WriteString("\n")
Expand Down