Skip to content

Conversation

@evelez7
Copy link
Member

@evelez7 evelez7 commented Jul 25, 2025

Serialize throw Doxygen comments for exceptions. Accepts both \throw and
\throws.

Copy link
Member Author

evelez7 commented Jul 25, 2025

@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Erick Velez (evelez7)

Changes

Serialize throw Doxygen comments for exceptions. Accepts both \throw and
\throws.


Full diff: https://github.com/llvm/llvm-project/pull/150649.diff

2 Files Affected:

  • (modified) clang-tools-extra/clang-doc/JSONGenerator.cpp (+7)
  • (modified) clang-tools-extra/clang-doc/assets/comment-template.mustache (+8)
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 599b381cea60d..2db6451259f60 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -140,6 +140,13 @@ static Object serializeComment(const CommentInfo &I, Object &Description) {
       insertComment(Description, TextCommentsArray, "BriefComments");
     else if (I.Name == "return")
       insertComment(Description, TextCommentsArray, "ReturnComments");
+    else if (I.Name == "throws" || I.Name == "throw") {
+      json::Value ThrowsVal = Object();
+      auto &ThrowsObj = *ThrowsVal.getAsObject();
+      ThrowsObj["Exception"] = I.Args.front();
+      ThrowsObj["Children"] = TextCommentsArray;
+      insertComment(Description, ThrowsVal, "ThrowsComments");
+    }
     return Obj;
   }
 
diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache
index 4e38e5fb92d18..60a4c70ec0dc4 100644
--- a/clang-tools-extra/clang-doc/assets/comment-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache
@@ -54,6 +54,14 @@
     </div>
     {{/CodeComments}}
 {{/HasCodeComments}}
+{{#HasThrowsComments}}
+    <h3>Throws</h3>
+    {{#ThrowsComments}}
+    <div>
+        <b>{{ThrowName}}</b> {{#Children}}{{>Comments}}{{/Children}}
+    </div>
+    {{/ThrowsComments}}
+{{/HasThrowsComments}}
 {{#BlockCommandComment}}
     <div class="block-command-comment__command">
         <div class="block-command-command">

@evelez7 evelez7 marked this pull request as draft July 25, 2025 17:19
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-throws-comments branch from 26f70f8 to e736a45 Compare July 25, 2025 17:25
@evelez7 evelez7 marked this pull request as ready for review July 25, 2025 17:38
@evelez7 evelez7 requested review from ilovepi and petrhosek July 25, 2025 17:38
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-code-comments branch from 9543783 to 7d6c38c Compare July 25, 2025 17:43
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-throws-comments branch from e736a45 to ff3d3ad Compare July 25, 2025 17:44
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-code-comments branch from 7d6c38c to e8795d0 Compare July 25, 2025 18:18
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-throws-comments branch from ff3d3ad to eb95d56 Compare July 25, 2025 18:19
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-code-comments branch 3 times, most recently from 1ef0736 to 3dbfb45 Compare July 25, 2025 20:05
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-code-comments branch from 3dbfb45 to 9c3d458 Compare July 25, 2025 20:08
Base automatically changed from users/evelez7/clang-doc-code-comments to main July 25, 2025 20:10
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-throws-comments branch from eb95d56 to 35762dd Compare July 25, 2025 20:13
@evelez7 evelez7 requested a review from ilovepi November 13, 2025 07:44
Copy link
Member Author

evelez7 commented Nov 13, 2025

Think I lost track of this during GSoC submission. Should still be valid.

Copy link
Contributor

@ilovepi ilovepi left a comment

Choose a reason for hiding this comment

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

LGTM. It'd be nice if that HTML output looked sane, but if the tests still pass, its probably fine.

@evelez7
Copy link
Member Author

evelez7 commented Nov 13, 2025

The extra div isn't just present in the throws comments, it's present in the param comments as well. Here's an updated link for the output of this PR, and this class has param and throws comments: https://erickvelez.com/clang-doc-mustache-output/pr150649/GlobalNamespace/_ZTV10Calculator.html

What these two have in common is that they recursively call the comment partial to render the text comments.

<b>{{ParamName}}</b> {{#Explicit}}{{Direction}}{{/Explicit}} {{#Children}}{{>Comments}}{{/Children}}

There's no <div> on this line, so I'm not sure how one is appearing even if there is a missing placeholder data.

@ilovepi
Copy link
Contributor

ilovepi commented Nov 13, 2025

The extra div isn't just present in the throws comments, it's present in the param comments as well. Here's an updated link for the output of this PR, and this class has param and throws comments: https://erickvelez.com/clang-doc-mustache-output/pr150649/GlobalNamespace/_ZTV10Calculator.html

What these two have in common is that they recursively call the comment partial to render the text comments.

<b>{{ParamName}}</b> {{#Explicit}}{{Direction}}{{/Explicit}} {{#Children}}{{>Comments}}{{/Children}}

There's no <div> on this line, so I'm not sure how one is appearing even if there is a missing placeholder data.

So what seems to be happening is that the div's aren't mismatched. I took the raw html from that link and threw it into a formatter. I think the fact that that's only the FileCheck output and matching is kind of fuzzy is what's going on. We're not using CHECK-NEXT: patterns, so its not like we notice if the the closing tags are generated or not.

@ilovepi
Copy link
Contributor

ilovepi commented Nov 13, 2025

As for why those dive are showing up, I'd guess one of the internal partials for paragraph comment or something is gettting matched when we process the children and you end up w/ more <div></div> tags for the partials. Could be something is strange w/ the partial expansion though, and it gets rendered in an odd way.

Serialize throw Doxygen comments for exceptions. Accepts both \throw and
\throws.
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-throws-comments branch from 35762dd to 45a83f5 Compare November 15, 2025 04:21
@evelez7
Copy link
Member Author

evelez7 commented Nov 15, 2025

I found the issue with the <div>. It's actually behaving correctly according to our implementation. The partial begins rendering on the line that it's called, so when the partial is called and matches with {{#TextComment}} on comment-template.mustache:77

the <div> is added on the first line, then the rest of the partial is rendered on newlines. So, I was misusing it thinking that the text would be rendered on the same line. Fixed that. That means I should be able to fix the other weird whitespace stuff.

Also yes, the wrong placeholder was being named for the exception. Updated the link to verify: https://erickvelez.com/clang-doc-mustache-output/pr150649/GlobalNamespace/_ZTV10Calculator.html

@evelez7 evelez7 requested a review from ilovepi November 15, 2025 04:23
Copy link
Contributor

@ilovepi ilovepi left a comment

Choose a reason for hiding this comment

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

Thanks for running that down. This looks great now.

Copy link
Member Author

evelez7 commented Nov 15, 2025

Merge activity

  • Nov 15, 6:26 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Nov 15, 6:28 PM UTC: @evelez7 merged this pull request with Graphite.

@evelez7 evelez7 merged commit 82214ff into main Nov 15, 2025
10 checks passed
@evelez7 evelez7 deleted the users/evelez7/clang-doc-throws-comments branch November 15, 2025 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants