llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

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

Author: Samrudh Nelli (SamrudhNelli)

<details>
<summary>Changes</summary>

Could not figure out how to use the `{{^End}}` on the just the inner scope as 
it would revert to the outer scope with `{{End}}` set for the final function. I 
think this is a bug and also affects the existing template, function printing.
Hence, reverted to trailing commas for all parameters.
Also disabled "language-cpp" highlighting as it enforced the `display : inline` 
rule and reset all the custom span classes, therefore implemented a custom 
highlighter to just colour the function name and parameter types.

@<!-- -->evelez7 Would like to hear your approach on tackling this issue and 
the changes to be made.
I’d appreciate your thoughts on this approach. I will update the regression 
tests once we finalize the design.
Fixes #<!-- -->181228 

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


3 Files Affected:

- (modified) clang-tools-extra/clang-doc/JSONGenerator.cpp (+18) 
- (modified) clang-tools-extra/clang-doc/assets/clang-doc-mustache.css (+18) 
- (modified) clang-tools-extra/clang-doc/assets/function-template.mustache 
(+1-2) 


``````````diff
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp 
b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 5051e7e6e690d..0586aca5f2b15 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -456,6 +456,24 @@ static void serializeArray(const Container &Records, 
Object &Obj,
       ItemObj["End"] = true;
     RecordsArrayRef.push_back(ItemVal);
   }
+  if (Key == "Params") {
+    size_t TotalLength = 0;
+    for (const auto &Val : RecordsArrayRef) {
+      if (const auto *ItemObj = Val.getAsObject()) {
+        if (auto Type = ItemObj->getString("Type")) 
+          TotalLength += Type->size();
+        if (auto Name = ItemObj->getString("Name"))
+          TotalLength += Name->size();
+        TotalLength += 2; // For ', '
+      }
+    }
+    if (TotalLength > 15) {
+      Obj["IsLong"] = true;
+    }
+    else {
+      Obj["IsLong"] = false;
+    }
+  }
   Obj[Key] = RecordsArray;
 }
 
diff --git a/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css 
b/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css
index 19fba2f9eae76..ae058fb2b9a24 100644
--- a/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css
+++ b/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css
@@ -520,3 +520,21 @@ a, a:visited, a:hover, a:active {
   overflow: hidden;
   padding: 10px;
 }
+
+.params-vertical {
+    display: block;
+    padding-left: 1ch;
+}
+
+.param {
+    display: block;
+}
+
+.hljs-type {
+    color: var(--brand-dark);
+}
+
+.hljs-title {
+    color: var(--brand-dark);
+    font-weight: bold;
+}
\ No newline at end of file
diff --git a/clang-tools-extra/clang-doc/assets/function-template.mustache 
b/clang-tools-extra/clang-doc/assets/function-template.mustache
index 510219a63d379..9c1355319bf73 100644
--- a/clang-tools-extra/clang-doc/assets/function-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/function-template.mustache
@@ -10,8 +10,7 @@
         <pre><code class="language-cpp code-clang-doc">template 
&lt;{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}&gt;</code></pre>
         {{/Template}}
         {{! Function Prototype }}
-        <pre><code class="language-cpp code-clang-doc">{{ReturnType.QualName}} 
{{Name}}{{#Template}}{{#Specialization}}&lt;{{#Parameters}}{{Param}}{{^End}}, 
{{/End}}{{/Parameters}}&gt;{{/Specialization}}{{/Template}} 
({{#Params}}{{Type.QualName}} {{Name}}{{^End}}, 
{{/End}}{{/Params}})</code></pre>
-        {{! Function Comments }}
+        <pre><code class="nohighlight code-clang-doc"><span 
class="hljs-type">{{ReturnType.QualName}}</span> <span 
class="hljs-title">{{Name}}</span> ({{#IsLong}}<span 
class="params-vertical">{{#Params}}<span class="param"><span 
class="hljs-type">{{Type.QualName}}</span> 
{{Name}},</span>{{/Params}}</span>{{/IsLong}}{{^IsLong}}{{#Params}}<span 
class="hljs-type">{{Type.QualName}}</span> {{Name}}{{^End}}, 
{{/End}}{{/Params}}{{/IsLong}})</code></pre>
         {{#Description}}
         <div class="doc-card">
             {{>Comments}}

``````````

</details>


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

Reply via email to