https://github.com/evelez7 updated 
https://github.com/llvm/llvm-project/pull/175226

>From 3ab5d53fec02374ec5582bcae5e5405f864008da Mon Sep 17 00:00:00 2001
From: Erick Velez <[email protected]>
Date: Thu, 8 Jan 2026 22:06:51 -0800
Subject: [PATCH] [clang-doc] Add variables to the namespace HTML template

---
 clang-tools-extra/clang-doc/JSONGenerator.cpp |  4 ++-
 .../assets/namespace-template.mustache        | 31 +++++++++++++++++++
 .../test/clang-doc/json/namespace.cpp         | 20 +++++++++---
 3 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp 
b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index ec234db19ed1a..1757293cbeebd 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -755,8 +755,10 @@ static void serializeInfo(const NamespaceInfo &I, 
json::Object &Obj,
     Obj["HasConcepts"] = true;
   }
 
-  if (!I.Children.Variables.empty())
+  if (!I.Children.Variables.empty()) {
     serializeArray(I.Children.Variables, Obj, "Variables", SerializeInfo);
+    Obj["HasVariables"] = true;
+  }
 
   serializeCommonChildren(I.Children, Obj, RepositoryUrl, 
RepositoryLinePrefix);
 }
diff --git a/clang-tools-extra/clang-doc/assets/namespace-template.mustache 
b/clang-tools-extra/clang-doc/assets/namespace-template.mustache
index 04c31fb140962..7fbbfa69f7f89 100644
--- a/clang-tools-extra/clang-doc/assets/namespace-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/namespace-template.mustache
@@ -113,6 +113,22 @@
                         </details>
                     </li>
                     {{/HasTypedefs}}
+                    {{#HasVariables}}
+                    <li>
+                        <details open>
+                            <summary class="sidebar-section">
+                                <a class="sidebar-item" 
href="#Variables">Variables</a>
+                            </summary>
+                            <ul>
+                                {{#Variables}}
+                                <li class="sidebar-item-container">
+                                    <a class="sidebar-item" 
href="#{{USR}}">{{Name}}</a>
+                                </li>
+                                {{/Variables}}
+                            </ul>
+                        </details>
+                    </li>
+                    {{/HasVariables}}
                 </ul>
             </div>
             <div class="resizer" id="resizer"></div>
@@ -193,6 +209,21 @@
                     {{/Typedefs}}
                 </section>
                 {{/HasTypedefs}}
+                {{#HasVariables}}
+                <section id="Variables" class="section-container">
+                    <h2>Variables</h2>
+                    <div>
+                        {{#Variables}}
+                        <div id="{{USR}}" class="delimiter-container">
+                            <pre><code class="language-cpp code-clang-doc" 
>{{#IsStatic}}static {{/IsStatic}}{{Type.QualName}} {{Name}}</code></pre>
+                            {{#Location}}
+                            <p>Defined at line {{LineNumber}} of file 
{{^FileURL}}{{Filename}}{{/FileURL}}{{#FileURL}}<a 
href="{{FileURL}}">{{Filename}}</a>{{/FileURL}}</p>
+                            {{/Location}}
+                        </div>
+                        {{/Variables}}
+                    </div>
+                </section>
+                {{/HasVariables}}
             </div>
         </div>
     </main>
diff --git a/clang-tools-extra/test/clang-doc/json/namespace.cpp 
b/clang-tools-extra/test/clang-doc/json/namespace.cpp
index 34f4eb3cb8f81..8681c15bf1048 100644
--- a/clang-tools-extra/test/clang-doc/json/namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/json/namespace.cpp
@@ -1,6 +1,7 @@
 // RUN: rm -rf %t && mkdir -p %t
-// RUN: clang-doc --output=%t --format=json --executor=standalone %s
+// RUN: clang-doc --output=%t --format=html --executor=standalone %s
 // RUN: FileCheck %s < %t/json/GlobalNamespace/index.json
+// RUN: FileCheck %s < %t/html/GlobalNamespace/index.html 
-check-prefix=HTML-CHECK
 
 class MyClass {};
 
@@ -27,7 +28,7 @@ typedef int MyTypedef;
 // CHECK-NEXT:        "InfoType": "enum",
 // CHECK-NEXT:        "Location": {
 // CHECK-NEXT:          "Filename": "{{.*}}namespace.cpp",
-// CHECK-NEXT:          "LineNumber": 14
+// CHECK-NEXT:          "LineNumber": 15
 // CHECK-NEXT:        },
 // CHECK-NEXT:        "Members": [
 // CHECK-NEXT:          {
@@ -81,6 +82,7 @@ typedef int MyTypedef;
 // CHECK-NEXT:   "HasNamespaces": true,
 // CHECK-NEXT:   "HasRecords": true,
 // CHECK-NEXT:   "HasTypedefs": true,
+// CHECK-NEXT:   "HasVariables": true,
 // CHECK-NEXT:   "InfoType": "namespace",
 // CHECK-NEXT:   "Name": "Global Namespace",
 // CHECK-NEXT:   "Namespaces": [
@@ -108,7 +110,7 @@ typedef int MyTypedef;
 // CHECK-NEXT:      "IsUsing": false,
 // CHECK-NEXT:      "Location": {
 // CHECK-NEXT:        "Filename": "{{.*}}namespace.cpp",
-// CHECK-NEXT:        "LineNumber": 20
+// CHECK-NEXT:        "LineNumber": 21
 // CHECK-NEXT:      },
 // CHECK-NEXT:      "Name": "MyTypedef",
 // CHECK-NEXT:      "TypeDeclaration": "",
@@ -130,7 +132,7 @@ typedef int MyTypedef;
 // CHECK-NEXT:       "IsStatic": true,
 // CHECK-NEXT:       "Location": {
 // CHECK-NEXT:         "Filename": "{{.*}}namespace.cpp",
-// CHECK-NEXT:         "LineNumber": 12
+// CHECK-NEXT:         "LineNumber": 13
 // CHECK-NEXT:       },
 // CHECK-NEXT:       "Name": "Global",
 // CHECK-NEXT:       "Type": {
@@ -144,3 +146,13 @@ typedef int MyTypedef;
 // CHECK-NEXT:     }
 // CHECK-NEXT:   ]
 // CHECK-NEXT:  }
+
+// HTML-CHECK:      <section id="Variables" class="section-container">
+// HTML-CHECK-NEXT:     <h2>Variables</h2>
+// HTML-CHECK-NEXT:     <div>
+// HTML-CHECK-NEXT:         <div id="{{([0-9A-F]{40})}}" 
class="delimiter-container">
+// HTML-CHECK-NEXT:             <pre><code class="language-cpp code-clang-doc" 
>static int Global</code></pre>
+// HTML-CHECK-NEXT:             <p>Defined at line 13 of file 
{{.*}}namespace.cpp</p>
+// HTML-CHECK-NEXT:         </div>
+// HTML-CHECK-NEXT:     </div>
+// HTML-CHECK-NEXT: </section>

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to