Skip to content

Conversation

@evelez7
Copy link
Member

@evelez7 evelez7 commented Dec 10, 2025

Previously, the global namespace's "Name" field was left empty. It could
be identified this way, but it could also be identified by its USR.
Actually populating the "Name" field allows for nicer output in the
future.

Copy link
Member Author

evelez7 commented Dec 10, 2025

@evelez7 evelez7 marked this pull request as ready for review December 10, 2025 20:58
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-serialize-global-name branch from d16707e to b8e2dab Compare December 10, 2025 21:35
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-private-members branch from 6195426 to 5a303b8 Compare December 10, 2025 21:35
@github-actions
Copy link

github-actions bot commented Dec 10, 2025

🐧 Linux x64 Test Results

  • 3048 tests passed
  • 7 tests skipped

✅ The build succeeded and all tests passed.

@github-actions
Copy link

github-actions bot commented Dec 10, 2025

🪟 Windows x64 Test Results

  • 2986 tests passed
  • 30 tests skipped

✅ The build succeeded and all tests passed.

@llvmbot
Copy link
Member

llvmbot commented Dec 10, 2025

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

Author: Erick Velez (evelez7)

Changes

Previously, the global namespace's "Name" field was left empty. It could
be identified this way, but it could also be identified by its USR.
Actually populating the "Name" field allows for nicer output in the
future.


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

7 Files Affected:

  • (modified) clang-tools-extra/clang-doc/JSONGenerator.cpp (+2)
  • (modified) clang-tools-extra/clang-doc/assets/namespace-template.mustache (+1-1)
  • (modified) clang-tools-extra/test/clang-doc/json/concept.cpp (+1-1)
  • (modified) clang-tools-extra/test/clang-doc/json/namespace.cpp (+1-1)
  • (modified) clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp (+1-1)
  • (modified) clang-tools-extra/test/clang-doc/namespace.cpp (+4-4)
  • (modified) clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp (+1-1)
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index c47c65ddc2d73..83fa556782793 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -610,6 +610,8 @@ static void serializeInfo(const VarInfo &I, json::Object &Obj,
 static void serializeInfo(const NamespaceInfo &I, json::Object &Obj,
                           const std::optional<StringRef> RepositoryUrl) {
   serializeCommonAttributes(I, Obj, RepositoryUrl);
+  if (I.USR == GlobalNamespaceID)
+    Obj["Name"] = "Global Namespace";
 
   if (!I.Children.Namespaces.empty())
     serializeArray(I.Children.Namespaces, Obj, "Namespaces",
diff --git a/clang-tools-extra/clang-doc/assets/namespace-template.mustache b/clang-tools-extra/clang-doc/assets/namespace-template.mustache
index 7fb66cadbb8e8..9450f9b4fc684 100644
--- a/clang-tools-extra/clang-doc/assets/namespace-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/namespace-template.mustache
@@ -44,7 +44,7 @@
     <main>
         <div class="container">
             <div class="sidebar">
-                <h2>{{RecordType}} {{Name}}</h2>
+                <h2>{{#RecordType}}{{RecordType}} {{/RecordType}}{{Name}}</h2>
                 <ul>
                     {{#HasEnums}}
                     <li class="sidebar-section">
diff --git a/clang-tools-extra/test/clang-doc/json/concept.cpp b/clang-tools-extra/test/clang-doc/json/concept.cpp
index 5d8c47eff0a16..f4c4ad3946d47 100644
--- a/clang-tools-extra/test/clang-doc/json/concept.cpp
+++ b/clang-tools-extra/test/clang-doc/json/concept.cpp
@@ -31,6 +31,6 @@ concept Incrementable = requires(T x) {
 // CHECK-NEXT:        "USR": "{{[0-9A-F]*}}"
 // CHECK-NEXT:      }
 // CHECK-NEXT:    ],
-// CHECK:        "Name": "",
+// CHECK:        "Name": "Global Namespace",
 // CHECK:        "USR": "0000000000000000000000000000000000000000"
 // CHECK:      }
diff --git a/clang-tools-extra/test/clang-doc/json/namespace.cpp b/clang-tools-extra/test/clang-doc/json/namespace.cpp
index dd7a9af9c82a0..c1370d9fe379f 100644
--- a/clang-tools-extra/test/clang-doc/json/namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/json/namespace.cpp
@@ -75,7 +75,7 @@ typedef int MyTypedef;
 // CHECK-NEXT:   "HasEnums": true,
 // CHECK-NEXT:   "HasRecords": true,
 // CHECK-NEXT:   "InfoType": "namespace",
-// CHECK-NEXT:   "Name": "",
+// CHECK-NEXT:   "Name": "Global Namespace",
 // CHECK-NEXT:   "Namespaces": [
 // CHECK-NEXT:     {
 // CHECK-NEXT:       "End": true,
diff --git a/clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp b/clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp
index cb0f9dc64bba6..7fbf51c4efd30 100644
--- a/clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp
@@ -19,7 +19,7 @@ namespace MyNamespace {
 // CHECK-GLOBAL:             <main>
 // CHECK-GLOBAL-NEXT:            <div class="container">
 // CHECK-GLOBAL-NEXT:                <div class="sidebar">
-// CHECK-GLOBAL-NEXT:                    <h2> </h2>
+// CHECK-GLOBAL-NEXT:                    <h2>Global Namespace</h2>
 // CHECK-GLOBAL-NEXT:                    <ul>
 // CHECK-GLOBAL-NEXT:                    </ul>
 // CHECK-GLOBAL-NEXT:                </div>
diff --git a/clang-tools-extra/test/clang-doc/namespace.cpp b/clang-tools-extra/test/clang-doc/namespace.cpp
index 029f9974e775e..8580ea6739a21 100644
--- a/clang-tools-extra/test/clang-doc/namespace.cpp
+++ b/clang-tools-extra/test/clang-doc/namespace.cpp
@@ -63,7 +63,7 @@ class AnonClass {};
 // MD-ANON-INDEX: ### anonFunction
 // MD-ANON-INDEX: *void anonFunction()*
 
-// HTML-ANON-INDEX: <h2> @nonymous_namespace</h2>
+// HTML-ANON-INDEX: <h2>@nonymous_namespace</h2>
 // HTML-ANON-INDEX:     <h2>Inner Classes</h2>
 // HTML-ANON-INDEX:         <ul class="class-container">
 // HTML-ANON-INDEX:             <li id="{{([0-9A-F]{40})}}" style="max-height: 40px;">
@@ -119,7 +119,7 @@ class ClassInNestedNamespace {};
 // MD-NESTED-INDEX: *void functionInNestedNamespace()*
 // MD-NESTED-INDEX: Function in NestedNamespace
 
-// HTML-NESTED-INDEX: <h2> NestedNamespace</h2>
+// HTML-NESTED-INDEX: <h2>NestedNamespace</h2>
 // HTML-NESTED-INDEX:     <h2>Inner Classes</h2>
 // HTML-NESTED-INDEX:     <ul class="class-container">
 // HTML-NESTED-INDEX:         <li id="{{([0-9A-F]{40})}}" style="max-height: 40px;">
@@ -145,7 +145,7 @@ class ClassInNestedNamespace {};
 // MD-PRIMARY-INDEX: *void functionInPrimaryNamespace()*
 // MD-PRIMARY-INDEX:  Function in PrimaryNamespace
 
-// HTML-PRIMARY-INDEX: <h2> PrimaryNamespace</h2>
+// HTML-PRIMARY-INDEX: <h2>PrimaryNamespace</h2>
 // HTML-PRIMARY-INDEX-NOT: <h2 id="Namespaces">Namespaces</h2>
 // HTML-PRIMARY-INDEX-NOT: <a href="NestedNamespace{{[\/]}}index.html">NestedNamespace</a>
 // HTML-PRIMARY-INDEX      <h2>Inner Classes</h2>
@@ -189,7 +189,7 @@ class ClassInAnotherNamespace {};
 // MD-ANOTHER-INDEX: *void functionInAnotherNamespace()*
 // MD-ANOTHER-INDEX: Function in AnotherNamespace
 
-// HTML-ANOTHER-INDEX: <h2> AnotherNamespace</h2>
+// HTML-ANOTHER-INDEX: <h2>AnotherNamespace</h2>
 // HTML-ANOTHER-INDEX:     <h2>Inner Classes</h2>
 // HTML-ANOTHER-INDEX:     <ul class="class-container">
 // HTML-ANOTHER-INDEX:         <li id="{{([0-9A-F]{40})}}" style="max-height: 40px;">
diff --git a/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp
index bcb9fd8e47bc6..b468964630d45 100644
--- a/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp
@@ -245,7 +245,7 @@ TEST_F(JSONGeneratorTest, emitNamespaceJSON) {
   "HasEnums": true,
   "HasRecords": true,
   "InfoType": "namespace",
-  "Name": "Namespace",
+  "Name": "Global Namespace",
   "Namespace": [
     "A"
   ],

@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-private-members branch from 5a303b8 to 0be4b36 Compare December 11, 2025 16:54
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-serialize-global-name branch from b8e2dab to 28f8a29 Compare December 11, 2025 16:55
Base automatically changed from users/evelez7/clang-doc-private-members to main December 11, 2025 19:00
@evelez7 evelez7 force-pushed the users/evelez7/clang-doc-serialize-global-name branch from 28f8a29 to 69c7ba7 Compare December 11, 2025 19:05
@evelez7 evelez7 merged commit f6c04cd into main Dec 11, 2025
5 of 9 checks passed
@evelez7 evelez7 deleted the users/evelez7/clang-doc-serialize-global-name branch December 11, 2025 19:06
Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Dec 20, 2025
Previously, the global namespace's "Name" field was left empty. It could
be identified this way, but it could also be identified by its USR.
Actually populating the "Name" field allows for nicer output in the
future.
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