-
Notifications
You must be signed in to change notification settings - Fork 764
Support <caption></caption> in JSDoc @example tags
#2374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for parsing <caption></caption> tags within JSDoc @example tags. When a caption is present, it's extracted and displayed as part of the hover documentation, separated by an em-dash, with the caption text appearing before the example code.
Key changes:
- Caption extraction logic that finds and extracts text between
<caption>and</caption>tags - Blank line trimming to clean up whitespace after the caption tags
- Repositioning of the newline output to occur after caption processing
| if strings.HasPrefix(commentText, "<caption>") { | ||
| if captionEnd := strings.Index(commentText, "</caption>"); captionEnd > 0 { | ||
| 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 | ||
| } | ||
| } | ||
| } |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
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.
| b.WriteString("\n") | ||
| commentText := strings.TrimRight(getCommentText(comments), " \t\r\n") | ||
| if strings.HasPrefix(commentText, "<caption>") { | ||
| if captionEnd := strings.Index(commentText, "</caption>"); captionEnd > 0 { |
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
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.
| if captionEnd := strings.Index(commentText, "</caption>"); captionEnd > 0 { | |
| if captionEnd := strings.Index(commentText, "</caption>"); captionEnd > len("<caption>") { |
Fixes #2349.