-
Notifications
You must be signed in to change notification settings - Fork 15.7k
[clang-doc] Add variables to the namespace HTML template #175226
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
Open
evelez7
wants to merge
1
commit into
main
Choose a base branch
from
users/evelez7/clang-doc-global-variables-html
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+50
−5
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Jan 9, 2026
Member
Author
Member
|
@llvm/pr-subscribers-clang-tools-extra Author: Erick Velez (evelez7) ChangesFull diff: https://github.com/llvm/llvm-project/pull/175226.diff 3 Files Affected:
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 12d439c6acbe4..9863749c233b4 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -752,8 +752,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 fc0b9e2c388d9..e4d61f1823f86 100644
--- a/clang-tools-extra/clang-doc/assets/namespace-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/namespace-template.mustache
@@ -111,6 +111,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>
@@ -191,6 +207,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>
|
Member
Author
ilovepi
approved these changes
Jan 9, 2026
085d7a3 to
aa58492
Compare
4469576 to
8f8d9f7
Compare
Base automatically changed from
users/evelez7/clang-doc-repository-url-templates
to
main
January 10, 2026 04:07
8f8d9f7 to
3ab5d53
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

No description provided.