Skip to content

[clang-doc] add param comments to comment template #150470

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

Conversation

evelez7
Copy link
Member

@evelez7 evelez7 commented Jul 24, 2025

Serializes parameter comments for all descriptions. We do not support Doxygen's parameter checking, which warns if a documented parameter is not actually present.

@evelez7 evelez7 marked this pull request as ready for review July 24, 2025 17:15
@llvmbot
Copy link
Member

llvmbot commented Jul 24, 2025

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

Author: Erick Velez (evelez7)

Changes

T


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

3 Files Affected:

  • (modified) clang-tools-extra/clang-doc/JSONGenerator.cpp (+4-2)
  • (modified) clang-tools-extra/clang-doc/assets/comment-template.mustache (+8)
  • (modified) clang-tools-extra/test/clang-doc/basic-project.mustache.test (+90-90)
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 92a4117c4e534..5fc28406ee870 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -147,8 +147,10 @@ static Object serializeComment(const CommentInfo &I, Object &Description) {
     Child.insert({"ParamName", I.ParamName});
     Child.insert({"Direction", I.Direction});
     Child.insert({"Explicit", I.Explicit});
-    Child.insert({"Children", ChildArr});
-    Obj.insert({commentKindToString(I.Kind), ChildVal});
+    auto TextCommentsArray = extractTextComments(CARef.front().getAsObject());
+    Child.insert({"Children", TextCommentsArray});
+    if (I.Kind == CommentKind::CK_ParamCommandComment)
+      insertComment(Description, ChildVal, "ParamComments");
     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 f2edb1b2eb9ac..d55a53194ee5c 100644
--- a/clang-tools-extra/clang-doc/assets/comment-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache
@@ -24,6 +24,14 @@
     {{>Comments}}
     {{/Children}}
 {{/ParagraphComment}}
+{{#HasParamComments}}
+    <h3>Parameters</h3>
+    {{#ParamComments}}
+    <div>
+        <b>{{ParamName}}</b> {{#Explicit}}{{Direction}}{{/Explicit}} {{#Children}}{{>Comments}}{{/Children}}
+    </div> 
+    {{/ParamComments}}
+{{/HasParamComments}}
 {{#BlockCommandComment}}
     <div class="block-command-comment__command">
         <div class="block-command-command">
diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test
index 807ba1319e393..b55e0abe2cdef 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test
@@ -259,24 +259,24 @@ HTML-CALC:                        <p></p>
 HTML-CALC:                    </div>
 HTML-CALC:                        <div>
 HTML-CALC:                        <p></p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <h3>Parameters</h3>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <b>a</b>      <div>
-HTML-CALC-NOT:                        <p> First integer.</p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <p></p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <b>b</b>      <div>
-HTML-CALC-NOT:                        <p> Second integer.</p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <p></p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    </div>
+HTML-CALC:                    </div>
+HTML-CALC:                    <h3>Parameters</h3>
+HTML-CALC:                    <div>
+HTML-CALC:                        <b>a</b>      <div>
+HTML-CALC:                        <p> First integer.</p>
+HTML-CALC:                    </div>
+HTML-CALC:                    <div>
+HTML-CALC:                        <p></p>
+HTML-CALC:                    </div>
+HTML-CALC:                    </div>
+HTML-CALC:                    <div>
+HTML-CALC:                        <b>b</b>      <div>
+HTML-CALC:                        <p> Second integer.</p>
+HTML-CALC:                    </div>
+HTML-CALC:                    <div>
+HTML-CALC:                        <p></p>
+HTML-CALC:                    </div>
+HTML-CALC:                    </div>
 HTML-CALC:                        </div>
 HTML-CALC:     </div>
 HTML-CALC: </div>
@@ -316,24 +316,24 @@ HTML-CALC:                        <p></p>
 HTML-CALC:                    </div>
 HTML-CALC:                        <div>
 HTML-CALC:                        <p></p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <h3>Parameters</h3>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <b>a</b>      <div>
-HTML-CALC-NOT:                        <p> First integer.</p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <p></p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <b>b</b>      <div>
-HTML-CALC-NOT:                        <p> Second integer.</p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <p></p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    </div>
+HTML-CALC:                    </div>
+HTML-CALC:                    <h3>Parameters</h3>
+HTML-CALC:                    <div>
+HTML-CALC:                        <b>a</b>      <div>
+HTML-CALC:                        <p> First integer.</p>
+HTML-CALC:                    </div>
+HTML-CALC:                    <div>
+HTML-CALC:                        <p></p>
+HTML-CALC:                    </div>
+HTML-CALC:                    </div>
+HTML-CALC:                    <div>
+HTML-CALC:                        <b>b</b>      <div>
+HTML-CALC:                        <p> Second integer.</p>
+HTML-CALC:                    </div>
+HTML-CALC:                    <div>
+HTML-CALC:                        <p></p>
+HTML-CALC:                    </div>
+HTML-CALC:                    </div>
 HTML-CALC:                        </div>
 HTML-CALC:     </div>
 HTML-CALC: </div>
@@ -353,23 +353,23 @@ HTML-CALC:                        <p></p>
 HTML-CALC:                    </div>
 HTML-CALC:                        <div>
 HTML-CALC:                        <p></p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <h3>Parameters</h3>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <b>a</b>      <div>
-HTML-CALC-NOT:                        <p> First integer.</p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <p></p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <b>b</b>      <div>
-HTML-CALC-NOT:                        <p> Second integer.</p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <p></p>
-HTML-CALC-NOT:                    </div>
+HTML-CALC:                    </div>
+HTML-CALC:                    <h3>Parameters</h3>
+HTML-CALC:                    <div>
+HTML-CALC:                        <b>a</b>      <div>
+HTML-CALC:                        <p> First integer.</p>
+HTML-CALC:                    </div>
+HTML-CALC:                    <div>
+HTML-CALC:                        <p></p>
+HTML-CALC:                    </div>
+HTML-CALC:                    </div>
+HTML-CALC:                    <div>
+HTML-CALC:                        <b>b</b>      <div>
+HTML-CALC:                        <p> Second integer.</p>
+HTML-CALC:                    </div>
+HTML-CALC:                    <div>
+HTML-CALC:                        <p></p>
+HTML-CALC:                    </div>
 HTML-CALC:                    </div>
 HTML-CALC:                        </div>
 HTML-CALC:     </div>
@@ -390,23 +390,23 @@ HTML-CALC:                        <p></p>
 HTML-CALC:                    </div>
 HTML-CALC:                        <div>
 HTML-CALC:                        <p></p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <h3>Parameters</h3>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <b>a</b>      <div>
-HTML-CALC-NOT:                        <p> First integer.</p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <p></p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <b>b</b>      <div>
-HTML-CALC-NOT:                        <p> Second integer.</p>
-HTML-CALC-NOT:                    </div>
-HTML-CALC-NOT:                    <div>
-HTML-CALC-NOT:                        <p></p>
-HTML-CALC-NOT:                    </div>
+HTML-CALC:                    </div>
+HTML-CALC:                    <h3>Parameters</h3>
+HTML-CALC:                    <div>
+HTML-CALC:                        <b>a</b>      <div>
+HTML-CALC:                        <p> First integer.</p>
+HTML-CALC:                    </div>
+HTML-CALC:                    <div>
+HTML-CALC:                        <p></p>
+HTML-CALC:                    </div>
+HTML-CALC:                    </div>
+HTML-CALC:                    <div>
+HTML-CALC:                        <b>b</b>      <div>
+HTML-CALC:                        <p> Second integer.</p>
+HTML-CALC:                    </div>
+HTML-CALC:                    <div>
+HTML-CALC:                        <p></p>
+HTML-CALC:                    </div>
 HTML-CALC:                    </div>
 HTML-CALC:                        </div>
 HTML-CALC:     </div>
@@ -506,20 +506,20 @@ HTML-RECTANGLE:                        <p></p>
 HTML-RECTANGLE:                    </div>
 HTML-RECTANGLE:                        <div>
 HTML-RECTANGLE:                        <p></p>
-HTML-RECTANGLE-NOT:                    </div>
-HTML-RECTANGLE-NOT:                    <h3>Parameters</h3>
-HTML-RECTANGLE-NOT:                    <div>
-HTML-RECTANGLE-NOT:                        <b>width</b>      <div>
-HTML-RECTANGLE-NOT:                        <p> Width of the rectangle.</p>
-HTML-RECTANGLE-NOT:                    </div>
-HTML-RECTANGLE-NOT:                    <div>
-HTML-RECTANGLE-NOT:                        <p></p>
-HTML-RECTANGLE-NOT:                    </div>
-HTML-RECTANGLE-NOT:                    </div>
-HTML-RECTANGLE-NOT:                    <div>
-HTML-RECTANGLE-NOT:                        <b>height</b>      <div>
-HTML-RECTANGLE-NOT:                        <p> Height of the rectangle.</p>
-HTML-RECTANGLE-NOT:                    </div>
+HTML-RECTANGLE:                    </div>
+HTML-RECTANGLE:                    <h3>Parameters</h3>
+HTML-RECTANGLE:                    <div>
+HTML-RECTANGLE:                        <b>width</b>      <div>
+HTML-RECTANGLE:                        <p> Width of the rectangle.</p>
+HTML-RECTANGLE:                    </div>
+HTML-RECTANGLE:                    <div>
+HTML-RECTANGLE:                        <p></p>
+HTML-RECTANGLE:                    </div>
+HTML-RECTANGLE:                    </div>
+HTML-RECTANGLE:                    <div>
+HTML-RECTANGLE:                        <b>height</b>      <div>
+HTML-RECTANGLE:                        <p> Height of the rectangle.</p>
+HTML-RECTANGLE:                    </div>
 HTML-RECTANGLE:                    </div>
 HTML-RECTANGLE:                        </div>
 HTML-RECTANGLE:     </div>
@@ -659,12 +659,12 @@ HTML-CIRCLE:                        <p></p>
 HTML-CIRCLE:                    </div>
 HTML-CIRCLE:                        <div>
 HTML-CIRCLE:                        <p></p>
-HTML-CIRCLE-NOT:                    </div>
-HTML-CIRCLE-NOT:                    <h3>Parameters</h3>
-HTML-CIRCLE-NOT:                    <div>
-HTML-CIRCLE-NOT:                        <b>radius</b>      <div>
-HTML-CIRCLE-NOT:                        <p> Radius of the circle.</p>
-HTML-CIRCLE-NOT:                    </div>
+HTML-CIRCLE:                    </div>
+HTML-CIRCLE:                    <h3>Parameters</h3>
+HTML-CIRCLE:                    <div>
+HTML-CIRCLE:                        <b>radius</b>      <div>
+HTML-CIRCLE:                        <p> Radius of the circle.</p>
+HTML-CIRCLE:                    </div>
 HTML-CIRCLE:                    </div>
 HTML-CIRCLE:                        </div>
 HTML-CIRCLE:     </div>

@evelez7 evelez7 requested review from ilovepi and petrhosek July 24, 2025 17:50
Copy link
Contributor

ilovepi commented Jul 24, 2025

Can the description be more than T? assuming it got cut off or was a typo.

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. Consider squashing this with the precommit tests, though. It's pretty clear how the output changed, and all the tests just end up dropping -NOT, which isn't great. plus I'd expect those tests to fail when something like a tag matches on a later line in the HTML.

@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-precommit-param-comments branch from 625b470 to f678074 Compare July 25, 2025 01:40
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-param-comments branch from 9ca2a7b to 11b5659 Compare July 25, 2025 01:41
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-precommit-param-comments branch from f678074 to e2e10a6 Compare July 25, 2025 02:20
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-param-comments branch from 11b5659 to 6441335 Compare July 25, 2025 02:20
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-precommit-param-comments branch from e2e10a6 to 6f21379 Compare July 25, 2025 02:52
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-param-comments branch from 6441335 to 9817249 Compare July 25, 2025 02:53
@evelez7 evelez7 closed this Jul 25, 2025
@evelez7 evelez7 reopened this Jul 25, 2025
@evelez7 evelez7 closed this Jul 25, 2025
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.

3 participants