Skip to content

Conversation

@ahejlsberg
Copy link
Member

Fixes #2349.

Copy link
Contributor

Copilot AI left a 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

Comment on lines +113 to +128
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
}
}
}
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")
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support JSDoc <caption> tags for IntelliSense

2 participants