https://github.com/SamrudhNelli updated https://github.com/llvm/llvm-project/pull/181417
>From 0144736b981f4c13a464c3444661c7858e8cdc18 Mon Sep 17 00:00:00 2001 From: Samrudh Nelli <[email protected]> Date: Fri, 13 Feb 2026 22:38:54 +0530 Subject: [PATCH 01/14] fix: Enable vertical wrapping on longer function and template definitions --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 7 ++++-- .../clang-doc/assets/clang-doc-mustache.css | 22 +++++++++++++++++++ .../assets/function-template.mustache | 3 +-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 5051e7e6e690d..c3c14b9ee6f4e 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -452,8 +452,7 @@ static void serializeArray(const Container &Records, Object &Obj, json::Value ItemVal = Object(); auto &ItemObj = *ItemVal.getAsObject(); SerializeInfo(Records[Index], ItemObj); - if (Index == Records.size() - 1) - ItemObj["End"] = true; + ItemObj["End"] = (Index == Records.size() - 1); RecordsArrayRef.push_back(ItemVal); } Obj[Key] = RecordsArray; @@ -536,10 +535,14 @@ static void serializeInfo(const FunctionInfo &F, json::Object &Obj, const std::optional<StringRef> RepositoryLine) { serializeCommonAttributes(F, Obj, RepositoryURL, RepositoryLine); Obj["IsStatic"] = F.IsStatic; + size_t ParamLen = F.Name.size() + 1; auto ReturnTypeObj = Object(); serializeInfo(F.ReturnType, ReturnTypeObj); Obj["ReturnType"] = std::move(ReturnTypeObj); + ParamLen += F.ReturnType.Type.Name.size(); + ParamLen += 2; + Obj["ParamLength"] = ParamLen; if (!F.Params.empty()) serializeArray(F.Params, Obj, "Params", SerializeInfoLambda); 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..922166d8ee258 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,25 @@ a, a:visited, a:hover, a:active { overflow: hidden; padding: 10px; } + + +.params-vertical { + display: flex; + flex-wrap: wrap; +} + + +.param { + display: block; + margin-right: 5px; + padding-left: 100px; +} + +.format-text { + color: #800; +} + +.format-title { + color: #800; + 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..64845bc2d89e6 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 <{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}></code></pre> {{/Template}} {{! Function Prototype }} - <pre><code class="language-cpp code-clang-doc">{{ReturnType.QualName}} {{Name}}{{#Template}}{{#Specialization}}<{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}>{{/Specialization}}{{/Template}} ({{#Params}}{{Type.QualName}} {{Name}}{{^End}}, {{/End}}{{/Params}})</code></pre> - {{! Function Comments }} + <pre><code class="nohighlight code-clang-doc"><span class="format-text">{{ReturnType.QualName}}</span> <span class="format-title">{{Name}}</span> (<span class="params-vertical" style="padding-left: {{ParamLength}}ch;">{{#Params}}<span class="param"><span class="format-text">{{Type.QualName}}</span> {{Name}}{{^End}}, {{/End}}</span>{{/Params}}</span><span class="params-vertical" style="padding-left: {{ParamLength}}ch;">)</span></code></pre> {{#Description}} <div class="doc-card"> {{>Comments}} >From 66ba32298f929b4db6f57ef58a2d1d7dbc883c3f Mon Sep 17 00:00:00 2001 From: Samrudh Nelli <[email protected]> Date: Mon, 16 Feb 2026 20:00:01 +0530 Subject: [PATCH 02/14] implement approach 2 that falls back to approach 3 for long functions --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 24 +++++++++++++++++-- .../clang-doc/assets/clang-doc-mustache.css | 1 - .../assets/function-template.mustache | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index c3c14b9ee6f4e..ea1d26bb3d592 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -455,6 +455,24 @@ static void serializeArray(const Container &Records, Object &Obj, ItemObj["End"] = (Index == Records.size() - 1); RecordsArrayRef.push_back(ItemVal); } + if (Key == "Params") { + size_t TotalLength = 0; + for (const auto &Val : RecordsArrayRef) { + if (const auto *ItemObj = Val.getAsObject()) { + if (const auto *Type = ItemObj->get("Type")) + if(const auto *TypeObj = Type->getAsObject()) + if(auto Name = TypeObj->getString("QualName")) + TotalLength += Name->size(); + if (auto Name = ItemObj->getString("Name")) + TotalLength += Name->size(); + TotalLength += 2; // For ', ' + } + } + size_t ParamLen; + if(auto Length = Obj.getInteger("ParamLength")) + ParamLen = *Length; + Obj["IsLong"] = (TotalLength + ParamLen > 80); + } Obj[Key] = RecordsArray; } @@ -473,8 +491,7 @@ static void serializeInfo(const ArrayRef<TemplateParamInfo> &Params, Object &ParamObj = *ParamObjVal.getAsObject(); ParamObj["Param"] = Params[Idx].Contents; - if (Idx == Params.size() - 1) - ParamObj["End"] = true; + ParamObj["End"] = (Idx == Params.size() - 1); ParamsArrayRef.push_back(ParamObjVal); } Obj["Parameters"] = ParamsArray; @@ -547,6 +564,9 @@ static void serializeInfo(const FunctionInfo &F, json::Object &Obj, if (!F.Params.empty()) serializeArray(F.Params, Obj, "Params", SerializeInfoLambda); + if(ParamLen >= 40) + Obj["ParamLength"] = 35; + if (F.Template) serializeInfo(F.Template.value(), Obj); } 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 922166d8ee258..82f4f318ad578 100644 --- a/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css +++ b/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css @@ -531,7 +531,6 @@ a, a:visited, a:hover, a:active { .param { display: block; margin-right: 5px; - padding-left: 100px; } .format-text { diff --git a/clang-tools-extra/clang-doc/assets/function-template.mustache b/clang-tools-extra/clang-doc/assets/function-template.mustache index 64845bc2d89e6..fe49bb5fa421f 100644 --- a/clang-tools-extra/clang-doc/assets/function-template.mustache +++ b/clang-tools-extra/clang-doc/assets/function-template.mustache @@ -10,7 +10,7 @@ <pre><code class="language-cpp code-clang-doc">template <{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}></code></pre> {{/Template}} {{! Function Prototype }} - <pre><code class="nohighlight code-clang-doc"><span class="format-text">{{ReturnType.QualName}}</span> <span class="format-title">{{Name}}</span> (<span class="params-vertical" style="padding-left: {{ParamLength}}ch;">{{#Params}}<span class="param"><span class="format-text">{{Type.QualName}}</span> {{Name}}{{^End}}, {{/End}}</span>{{/Params}}</span><span class="params-vertical" style="padding-left: {{ParamLength}}ch;">)</span></code></pre> + <pre><code class="nohighlight code-clang-doc"><span class="format-text">{{ReturnType.QualName}}</span> <span class="format-title">{{Name}}</span> ({{#IsLong}}<span class="params-vertical" style="padding-left: {{ParamLength}}ch;">{{#Params}}<span class="param"><span class="format-text">{{Type.QualName}}</span> {{Name}}{{^End}}, {{/End}}</span>{{/Params}}</span><span class="param" style="padding-left: calc({{ParamLength}}ch - 1ch);">)</span>{{/IsLong}}{{^IsLong}}{{#Params}}{{Type.QualName}} {{Name}}{{^End}}, {{/End}}{{/Params}}){{/IsLong}}</code></pre> {{#Description}} <div class="doc-card"> {{>Comments}} >From 590fcdbe2e036590b78346af54517138406a312b Mon Sep 17 00:00:00 2001 From: Samrudh Nelli <[email protected]> Date: Mon, 16 Feb 2026 22:04:25 +0530 Subject: [PATCH 03/14] use JS to check for long functions instead of hardcoding the char limit --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 23 ++----------- .../clang-doc/assets/clang-doc-mustache.css | 2 -- .../assets/function-template.mustache | 2 +- .../clang-doc/assets/mustache-index.js | 32 +++++++++++++++++++ 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index ea1d26bb3d592..de7405662479b 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -455,24 +455,6 @@ static void serializeArray(const Container &Records, Object &Obj, ItemObj["End"] = (Index == Records.size() - 1); RecordsArrayRef.push_back(ItemVal); } - if (Key == "Params") { - size_t TotalLength = 0; - for (const auto &Val : RecordsArrayRef) { - if (const auto *ItemObj = Val.getAsObject()) { - if (const auto *Type = ItemObj->get("Type")) - if(const auto *TypeObj = Type->getAsObject()) - if(auto Name = TypeObj->getString("QualName")) - TotalLength += Name->size(); - if (auto Name = ItemObj->getString("Name")) - TotalLength += Name->size(); - TotalLength += 2; // For ', ' - } - } - size_t ParamLen; - if(auto Length = Obj.getInteger("ParamLength")) - ParamLen = *Length; - Obj["IsLong"] = (TotalLength + ParamLen > 80); - } Obj[Key] = RecordsArray; } @@ -560,13 +542,12 @@ static void serializeInfo(const FunctionInfo &F, json::Object &Obj, ParamLen += F.ReturnType.Type.Name.size(); ParamLen += 2; Obj["ParamLength"] = ParamLen; + if(ParamLen >= 40) + Obj["ParamLength"] = 35; if (!F.Params.empty()) serializeArray(F.Params, Obj, "Params", SerializeInfoLambda); - if(ParamLen >= 40) - Obj["ParamLength"] = 35; - if (F.Template) serializeInfo(F.Template.value(), Obj); } 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 82f4f318ad578..605d48c3b07cc 100644 --- a/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css +++ b/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css @@ -521,13 +521,11 @@ a, a:visited, a:hover, a:active { padding: 10px; } - .params-vertical { display: flex; flex-wrap: wrap; } - .param { display: block; margin-right: 5px; diff --git a/clang-tools-extra/clang-doc/assets/function-template.mustache b/clang-tools-extra/clang-doc/assets/function-template.mustache index fe49bb5fa421f..956a7c0ce6a94 100644 --- a/clang-tools-extra/clang-doc/assets/function-template.mustache +++ b/clang-tools-extra/clang-doc/assets/function-template.mustache @@ -10,7 +10,7 @@ <pre><code class="language-cpp code-clang-doc">template <{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}></code></pre> {{/Template}} {{! Function Prototype }} - <pre><code class="nohighlight code-clang-doc"><span class="format-text">{{ReturnType.QualName}}</span> <span class="format-title">{{Name}}</span> ({{#IsLong}}<span class="params-vertical" style="padding-left: {{ParamLength}}ch;">{{#Params}}<span class="param"><span class="format-text">{{Type.QualName}}</span> {{Name}}{{^End}}, {{/End}}</span>{{/Params}}</span><span class="param" style="padding-left: calc({{ParamLength}}ch - 1ch);">)</span>{{/IsLong}}{{^IsLong}}{{#Params}}{{Type.QualName}} {{Name}}{{^End}}, {{/End}}{{/Params}}){{/IsLong}}</code></pre> + <pre><code class="nohighlight code-clang-doc"><span class="format-text">{{ReturnType.QualName}}</span> <span class="format-title">{{Name}}</span> (<span class="params-vertical" style="padding-left: {{ParamLength}}ch;">{{#Params}}<span class="param"><span class="format-text">{{Type.QualName}}</span> {{Name}}{{^End}}, {{/End}}</span>{{/Params}}</span><span class="param" style="padding-left: calc({{ParamLength}}ch - 1ch);">)</span></code></pre> {{#Description}} <div class="doc-card"> {{>Comments}} diff --git a/clang-tools-extra/clang-doc/assets/mustache-index.js b/clang-tools-extra/clang-doc/assets/mustache-index.js index 0f05eb71f0bee..b26fd6e60543f 100644 --- a/clang-tools-extra/clang-doc/assets/mustache-index.js +++ b/clang-tools-extra/clang-doc/assets/mustache-index.js @@ -21,6 +21,38 @@ document.addEventListener("DOMContentLoaded", function() { el.classList.remove("hljs"); }); + function getCharSize() { + const testChar = document.createElement('span'); + testChar.className = "code-clang-doc" + testChar.style.visibility = 'hidden'; + testChar.innerText = 'a'; + document.body.appendChild(testChar); + const charWidth = testChar.getBoundingClientRect().width; + document.body.removeChild(testChar); + return charWidth; + } + + function revertToSingleLine(func) { + const paramsContainer = func.querySelectorAll('.params-vertical') + const params = func.querySelectorAll('.param') + paramsContainer.forEach(params => { + params.style.display = "inline"; + params.style.paddingLeft = "0px"; + }); + params.forEach(param => { + param.style.display = "inline"; + param.style.paddingLeft = "0px"; + }); + } + + const functions = document.querySelectorAll('.code-clang-doc'); + const content = document.querySelector('.content') + const charSize = getCharSize(); + functions.forEach(func => { + if(func.textContent.trim().length * charSize < content.clientWidth - 20) + revertToSingleLine(func) + }); + document.querySelectorAll('.sidebar-item-container').forEach(item => { item.addEventListener('click', function() { const anchor = item.getElementsByTagName("a"); >From 7aac0b3db1c4efef4bef69dedee1eb6477c9c88b Mon Sep 17 00:00:00 2001 From: Samrudh Nelli <[email protected]> Date: Sat, 21 Feb 2026 00:25:37 +0530 Subject: [PATCH 04/14] Revert "use JS to check for long functions instead of hardcoding the char limit" This reverts commit 651b7f9a0f5446915dacf3d721b1a99cdeee2250. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 23 +++++++++++-- .../clang-doc/assets/clang-doc-mustache.css | 2 ++ .../assets/function-template.mustache | 2 +- .../clang-doc/assets/mustache-index.js | 32 ------------------- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index de7405662479b..ea1d26bb3d592 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -455,6 +455,24 @@ static void serializeArray(const Container &Records, Object &Obj, ItemObj["End"] = (Index == Records.size() - 1); RecordsArrayRef.push_back(ItemVal); } + if (Key == "Params") { + size_t TotalLength = 0; + for (const auto &Val : RecordsArrayRef) { + if (const auto *ItemObj = Val.getAsObject()) { + if (const auto *Type = ItemObj->get("Type")) + if(const auto *TypeObj = Type->getAsObject()) + if(auto Name = TypeObj->getString("QualName")) + TotalLength += Name->size(); + if (auto Name = ItemObj->getString("Name")) + TotalLength += Name->size(); + TotalLength += 2; // For ', ' + } + } + size_t ParamLen; + if(auto Length = Obj.getInteger("ParamLength")) + ParamLen = *Length; + Obj["IsLong"] = (TotalLength + ParamLen > 80); + } Obj[Key] = RecordsArray; } @@ -542,12 +560,13 @@ static void serializeInfo(const FunctionInfo &F, json::Object &Obj, ParamLen += F.ReturnType.Type.Name.size(); ParamLen += 2; Obj["ParamLength"] = ParamLen; - if(ParamLen >= 40) - Obj["ParamLength"] = 35; if (!F.Params.empty()) serializeArray(F.Params, Obj, "Params", SerializeInfoLambda); + if(ParamLen >= 40) + Obj["ParamLength"] = 35; + if (F.Template) serializeInfo(F.Template.value(), Obj); } 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 605d48c3b07cc..82f4f318ad578 100644 --- a/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css +++ b/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css @@ -521,11 +521,13 @@ a, a:visited, a:hover, a:active { padding: 10px; } + .params-vertical { display: flex; flex-wrap: wrap; } + .param { display: block; margin-right: 5px; diff --git a/clang-tools-extra/clang-doc/assets/function-template.mustache b/clang-tools-extra/clang-doc/assets/function-template.mustache index 956a7c0ce6a94..fe49bb5fa421f 100644 --- a/clang-tools-extra/clang-doc/assets/function-template.mustache +++ b/clang-tools-extra/clang-doc/assets/function-template.mustache @@ -10,7 +10,7 @@ <pre><code class="language-cpp code-clang-doc">template <{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}></code></pre> {{/Template}} {{! Function Prototype }} - <pre><code class="nohighlight code-clang-doc"><span class="format-text">{{ReturnType.QualName}}</span> <span class="format-title">{{Name}}</span> (<span class="params-vertical" style="padding-left: {{ParamLength}}ch;">{{#Params}}<span class="param"><span class="format-text">{{Type.QualName}}</span> {{Name}}{{^End}}, {{/End}}</span>{{/Params}}</span><span class="param" style="padding-left: calc({{ParamLength}}ch - 1ch);">)</span></code></pre> + <pre><code class="nohighlight code-clang-doc"><span class="format-text">{{ReturnType.QualName}}</span> <span class="format-title">{{Name}}</span> ({{#IsLong}}<span class="params-vertical" style="padding-left: {{ParamLength}}ch;">{{#Params}}<span class="param"><span class="format-text">{{Type.QualName}}</span> {{Name}}{{^End}}, {{/End}}</span>{{/Params}}</span><span class="param" style="padding-left: calc({{ParamLength}}ch - 1ch);">)</span>{{/IsLong}}{{^IsLong}}{{#Params}}{{Type.QualName}} {{Name}}{{^End}}, {{/End}}{{/Params}}){{/IsLong}}</code></pre> {{#Description}} <div class="doc-card"> {{>Comments}} diff --git a/clang-tools-extra/clang-doc/assets/mustache-index.js b/clang-tools-extra/clang-doc/assets/mustache-index.js index b26fd6e60543f..0f05eb71f0bee 100644 --- a/clang-tools-extra/clang-doc/assets/mustache-index.js +++ b/clang-tools-extra/clang-doc/assets/mustache-index.js @@ -21,38 +21,6 @@ document.addEventListener("DOMContentLoaded", function() { el.classList.remove("hljs"); }); - function getCharSize() { - const testChar = document.createElement('span'); - testChar.className = "code-clang-doc" - testChar.style.visibility = 'hidden'; - testChar.innerText = 'a'; - document.body.appendChild(testChar); - const charWidth = testChar.getBoundingClientRect().width; - document.body.removeChild(testChar); - return charWidth; - } - - function revertToSingleLine(func) { - const paramsContainer = func.querySelectorAll('.params-vertical') - const params = func.querySelectorAll('.param') - paramsContainer.forEach(params => { - params.style.display = "inline"; - params.style.paddingLeft = "0px"; - }); - params.forEach(param => { - param.style.display = "inline"; - param.style.paddingLeft = "0px"; - }); - } - - const functions = document.querySelectorAll('.code-clang-doc'); - const content = document.querySelector('.content') - const charSize = getCharSize(); - functions.forEach(func => { - if(func.textContent.trim().length * charSize < content.clientWidth - 20) - revertToSingleLine(func) - }); - document.querySelectorAll('.sidebar-item-container').forEach(item => { item.addEventListener('click', function() { const anchor = item.getElementsByTagName("a"); >From a78eee3ab75b34bbe8bf08337b9296e4355c5097 Mon Sep 17 00:00:00 2001 From: Samrudh Nelli <[email protected]> Date: Sat, 21 Feb 2026 00:26:22 +0530 Subject: [PATCH 05/14] Revert "implement approach 2 that falls back to approach 3 for long functions" This reverts commit c8194948bc7935aee91faabb651d2e91253aefa4. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 24 ++----------------- .../clang-doc/assets/clang-doc-mustache.css | 1 + .../assets/function-template.mustache | 2 +- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index ea1d26bb3d592..c3c14b9ee6f4e 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -455,24 +455,6 @@ static void serializeArray(const Container &Records, Object &Obj, ItemObj["End"] = (Index == Records.size() - 1); RecordsArrayRef.push_back(ItemVal); } - if (Key == "Params") { - size_t TotalLength = 0; - for (const auto &Val : RecordsArrayRef) { - if (const auto *ItemObj = Val.getAsObject()) { - if (const auto *Type = ItemObj->get("Type")) - if(const auto *TypeObj = Type->getAsObject()) - if(auto Name = TypeObj->getString("QualName")) - TotalLength += Name->size(); - if (auto Name = ItemObj->getString("Name")) - TotalLength += Name->size(); - TotalLength += 2; // For ', ' - } - } - size_t ParamLen; - if(auto Length = Obj.getInteger("ParamLength")) - ParamLen = *Length; - Obj["IsLong"] = (TotalLength + ParamLen > 80); - } Obj[Key] = RecordsArray; } @@ -491,7 +473,8 @@ static void serializeInfo(const ArrayRef<TemplateParamInfo> &Params, Object &ParamObj = *ParamObjVal.getAsObject(); ParamObj["Param"] = Params[Idx].Contents; - ParamObj["End"] = (Idx == Params.size() - 1); + if (Idx == Params.size() - 1) + ParamObj["End"] = true; ParamsArrayRef.push_back(ParamObjVal); } Obj["Parameters"] = ParamsArray; @@ -564,9 +547,6 @@ static void serializeInfo(const FunctionInfo &F, json::Object &Obj, if (!F.Params.empty()) serializeArray(F.Params, Obj, "Params", SerializeInfoLambda); - if(ParamLen >= 40) - Obj["ParamLength"] = 35; - if (F.Template) serializeInfo(F.Template.value(), Obj); } 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 82f4f318ad578..922166d8ee258 100644 --- a/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css +++ b/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css @@ -531,6 +531,7 @@ a, a:visited, a:hover, a:active { .param { display: block; margin-right: 5px; + padding-left: 100px; } .format-text { diff --git a/clang-tools-extra/clang-doc/assets/function-template.mustache b/clang-tools-extra/clang-doc/assets/function-template.mustache index fe49bb5fa421f..64845bc2d89e6 100644 --- a/clang-tools-extra/clang-doc/assets/function-template.mustache +++ b/clang-tools-extra/clang-doc/assets/function-template.mustache @@ -10,7 +10,7 @@ <pre><code class="language-cpp code-clang-doc">template <{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}></code></pre> {{/Template}} {{! Function Prototype }} - <pre><code class="nohighlight code-clang-doc"><span class="format-text">{{ReturnType.QualName}}</span> <span class="format-title">{{Name}}</span> ({{#IsLong}}<span class="params-vertical" style="padding-left: {{ParamLength}}ch;">{{#Params}}<span class="param"><span class="format-text">{{Type.QualName}}</span> {{Name}}{{^End}}, {{/End}}</span>{{/Params}}</span><span class="param" style="padding-left: calc({{ParamLength}}ch - 1ch);">)</span>{{/IsLong}}{{^IsLong}}{{#Params}}{{Type.QualName}} {{Name}}{{^End}}, {{/End}}{{/Params}}){{/IsLong}}</code></pre> + <pre><code class="nohighlight code-clang-doc"><span class="format-text">{{ReturnType.QualName}}</span> <span class="format-title">{{Name}}</span> (<span class="params-vertical" style="padding-left: {{ParamLength}}ch;">{{#Params}}<span class="param"><span class="format-text">{{Type.QualName}}</span> {{Name}}{{^End}}, {{/End}}</span>{{/Params}}</span><span class="params-vertical" style="padding-left: {{ParamLength}}ch;">)</span></code></pre> {{#Description}} <div class="doc-card"> {{>Comments}} >From 1dbd608615067e4107f36a1e47a5db05f226da33 Mon Sep 17 00:00:00 2001 From: Samrudh Nelli <[email protected]> Date: Sat, 21 Feb 2026 00:36:19 +0530 Subject: [PATCH 06/14] Revert "fix: Enable horizontal wrapping on longer function definitions" This reverts commit 5137041232b96451cd140ff157c61498827ca0da. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 7 ++---- .../clang-doc/assets/clang-doc-mustache.css | 22 ------------------- .../assets/function-template.mustache | 3 ++- 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index c3c14b9ee6f4e..5051e7e6e690d 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -452,7 +452,8 @@ static void serializeArray(const Container &Records, Object &Obj, json::Value ItemVal = Object(); auto &ItemObj = *ItemVal.getAsObject(); SerializeInfo(Records[Index], ItemObj); - ItemObj["End"] = (Index == Records.size() - 1); + if (Index == Records.size() - 1) + ItemObj["End"] = true; RecordsArrayRef.push_back(ItemVal); } Obj[Key] = RecordsArray; @@ -535,14 +536,10 @@ static void serializeInfo(const FunctionInfo &F, json::Object &Obj, const std::optional<StringRef> RepositoryLine) { serializeCommonAttributes(F, Obj, RepositoryURL, RepositoryLine); Obj["IsStatic"] = F.IsStatic; - size_t ParamLen = F.Name.size() + 1; auto ReturnTypeObj = Object(); serializeInfo(F.ReturnType, ReturnTypeObj); Obj["ReturnType"] = std::move(ReturnTypeObj); - ParamLen += F.ReturnType.Type.Name.size(); - ParamLen += 2; - Obj["ParamLength"] = ParamLen; if (!F.Params.empty()) serializeArray(F.Params, Obj, "Params", SerializeInfoLambda); 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 922166d8ee258..19fba2f9eae76 100644 --- a/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css +++ b/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css @@ -520,25 +520,3 @@ a, a:visited, a:hover, a:active { overflow: hidden; padding: 10px; } - - -.params-vertical { - display: flex; - flex-wrap: wrap; -} - - -.param { - display: block; - margin-right: 5px; - padding-left: 100px; -} - -.format-text { - color: #800; -} - -.format-title { - color: #800; - 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 64845bc2d89e6..510219a63d379 100644 --- a/clang-tools-extra/clang-doc/assets/function-template.mustache +++ b/clang-tools-extra/clang-doc/assets/function-template.mustache @@ -10,7 +10,8 @@ <pre><code class="language-cpp code-clang-doc">template <{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}></code></pre> {{/Template}} {{! Function Prototype }} - <pre><code class="nohighlight code-clang-doc"><span class="format-text">{{ReturnType.QualName}}</span> <span class="format-title">{{Name}}</span> (<span class="params-vertical" style="padding-left: {{ParamLength}}ch;">{{#Params}}<span class="param"><span class="format-text">{{Type.QualName}}</span> {{Name}}{{^End}}, {{/End}}</span>{{/Params}}</span><span class="params-vertical" style="padding-left: {{ParamLength}}ch;">)</span></code></pre> + <pre><code class="language-cpp code-clang-doc">{{ReturnType.QualName}} {{Name}}{{#Template}}{{#Specialization}}<{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}>{{/Specialization}}{{/Template}} ({{#Params}}{{Type.QualName}} {{Name}}{{^End}}, {{/End}}{{/Params}})</code></pre> + {{! Function Comments }} {{#Description}} <div class="doc-card"> {{>Comments}} >From 6552abf836100081e03b8dc1c1f88804d3cf5256 Mon Sep 17 00:00:00 2001 From: Samrudh Nelli <[email protected]> Date: Mon, 23 Feb 2026 23:19:40 +0530 Subject: [PATCH 07/14] revert to ONE_PER_LINE if no. of parameters > 2 use EndKey to specify a different EndKey for Params --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 15 +++++++++------ .../clang-doc/assets/clang-doc-mustache.css | 9 +++++++++ .../clang-doc/assets/function-template.mustache | 4 ++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 5051e7e6e690d..a10e9d9a23606 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -36,7 +36,8 @@ static void serializeReference(const Reference &Ref, Object &ReferenceObj); template <typename Container, typename SerializationFunc> static void serializeArray(const Container &Records, Object &Obj, const std::string &Key, - SerializationFunc SerializeInfo); + SerializationFunc SerializeInfo, + const std::string &EndKey = "End"); // Convenience lambda to pass to serializeArray. // If a serializeInfo needs a RepositoryUrl, create a local lambda that captures @@ -442,9 +443,9 @@ serializeCommonChildren(const ScopeChildren &Children, json::Object &Obj, } template <typename Container, typename SerializationFunc> -static void serializeArray(const Container &Records, Object &Obj, - const std::string &Key, - SerializationFunc SerializeInfo) { +static void +serializeArray(const Container &Records, Object &Obj, const std::string &Key, + SerializationFunc SerializeInfo, const std::string &EndKey) { json::Value RecordsArray = Array(); auto &RecordsArrayRef = *RecordsArray.getAsArray(); RecordsArrayRef.reserve(Records.size()); @@ -453,10 +454,11 @@ static void serializeArray(const Container &Records, Object &Obj, auto &ItemObj = *ItemVal.getAsObject(); SerializeInfo(Records[Index], ItemObj); if (Index == Records.size() - 1) - ItemObj["End"] = true; + ItemObj[EndKey] = true; RecordsArrayRef.push_back(ItemVal); } Obj[Key] = RecordsArray; + Obj["VerticalDisplay"] = Records.size() > 2; } static void serializeInfo(const ConstraintInfo &I, Object &Obj) { @@ -479,6 +481,7 @@ static void serializeInfo(const ArrayRef<TemplateParamInfo> &Params, ParamsArrayRef.push_back(ParamObjVal); } Obj["Parameters"] = ParamsArray; + Obj["VerticalDisplay"] = Params.size() > 2; } static void serializeInfo(const TemplateInfo &Template, Object &Obj) { @@ -542,7 +545,7 @@ static void serializeInfo(const FunctionInfo &F, json::Object &Obj, Obj["ReturnType"] = std::move(ReturnTypeObj); if (!F.Params.empty()) - serializeArray(F.Params, Obj, "Params", SerializeInfoLambda); + serializeArray(F.Params, Obj, "Params", SerializeInfoLambda, "ParamEnd"); if (F.Template) serializeInfo(F.Template.value(), Obj); 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..3727981efddc5 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,12 @@ a, a:visited, a:hover, a:active { overflow: hidden; padding: 10px; } + +.param { + display: block; + padding-left: 4ch; +} + +.param-container { + display: block; +} \ 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..dc833cc70d635 100644 --- a/clang-tools-extra/clang-doc/assets/function-template.mustache +++ b/clang-tools-extra/clang-doc/assets/function-template.mustache @@ -7,10 +7,10 @@ }} <div id="{{USR}}" class="delimiter-container"> {{#Template}} - <pre><code class="language-cpp code-clang-doc">template <{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}></code></pre> + <pre><code class="language-cpp code-clang-doc">template <{{^VerticalDisplay}}{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}{{/VerticalDisplay}}</code>{{#VerticalDisplay}}<span class="param-container">{{#Parameters}}<span class="param"><code class="language-cpp code-clang-doc">{{Param}}{{^End}}, {{/End}}</code></span>{{/Parameters}}</span>{{/VerticalDisplay}}<code class="language-cpp code-clang-doc">></code></pre> {{/Template}} {{! Function Prototype }} - <pre><code class="language-cpp code-clang-doc">{{ReturnType.QualName}} {{Name}}{{#Template}}{{#Specialization}}<{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}>{{/Specialization}}{{/Template}} ({{#Params}}{{Type.QualName}} {{Name}}{{^End}}, {{/End}}{{/Params}})</code></pre> + <pre><code class="language-cpp code-clang-doc">{{ReturnType.QualName}} {{Name}}{{#Template}}{{#Specialization}}<{{#Parameters}}{{Param}}{{^End}}, {{/End}}{{/Parameters}}>{{/Specialization}}{{/Template}} ({{^VerticalDisplay}}{{#Params}}{{Type.QualName}} {{Name}}{{^ParamEnd}}, {{/ParamEnd}}{{/Params}}){{/VerticalDisplay}}</code>{{#VerticalDisplay}}<span class="param-container">{{#Params}}<span class="param"><code class="language-cpp code-clang-doc">{{Type.QualName}}</code> <code class="language-cpp code-clang-doc">{{Name}}{{^ParamEnd}}, {{/ParamEnd}}</code></span>{{/Params}}</span><code class="language-cpp code-clang-doc">)</code>{{/VerticalDisplay}}</pre> {{! Function Comments }} {{#Description}} <div class="doc-card"> >From 407ee291b546b73dd8beca53fbe1316ecbda3624 Mon Sep 17 00:00:00 2001 From: Samrudh Nelli <[email protected]> Date: Mon, 23 Feb 2026 23:54:13 +0530 Subject: [PATCH 08/14] add key VerticalDisplay only for functions and templates --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index a10e9d9a23606..4f5470bcb5737 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -458,7 +458,8 @@ serializeArray(const Container &Records, Object &Obj, const std::string &Key, RecordsArrayRef.push_back(ItemVal); } Obj[Key] = RecordsArray; - Obj["VerticalDisplay"] = Records.size() > 2; + if (Key == "Params") + Obj["VerticalDisplay"] = Records.size() > 2; } static void serializeInfo(const ConstraintInfo &I, Object &Obj) { >From 190c677e158e1a5864978322b2c015dd5c9864c7 Mon Sep 17 00:00:00 2001 From: Samrudh Nelli <[email protected]> Date: Tue, 24 Feb 2026 01:01:50 +0530 Subject: [PATCH 09/14] update tests --- .../test/clang-doc/json/class-requires.cpp | 3 ++- .../clang-doc/json/class-specialization.cpp | 6 +++-- .../test/clang-doc/json/class-template.cpp | 6 +++-- .../test/clang-doc/json/class.cpp | 11 +++++--- .../test/clang-doc/json/concept.cpp | 1 + .../test/clang-doc/json/function-requires.cpp | 16 ++++++----- .../test/clang-doc/json/method-template.cpp | 5 ++-- .../test/clang-doc/json/namespace.cpp | 5 ++-- .../test/clang-doc/templates.cpp | 27 ++++++++++--------- .../unittests/clang-doc/JSONGeneratorTest.cpp | 3 ++- 10 files changed, 51 insertions(+), 32 deletions(-) diff --git a/clang-tools-extra/test/clang-doc/json/class-requires.cpp b/clang-tools-extra/test/clang-doc/json/class-requires.cpp index 6c35f2303b6dd..5c2ef229ef006 100644 --- a/clang-tools-extra/test/clang-doc/json/class-requires.cpp +++ b/clang-tools-extra/test/clang-doc/json/class-requires.cpp @@ -32,6 +32,7 @@ struct MyClass; // CHECK-NEXT: "End": true, // CHECK-NEXT: "typename T" // CHECK-NEXT: } -// CHECK-NEXT: ] +// CHECK-NEXT: ], +// CHECK-NEXT: "VerticalDisplay": false // CHECK-NEXT: }, // CHECK-NEXT: "USR": "{{[0-9A-F]*}}" diff --git a/clang-tools-extra/test/clang-doc/json/class-specialization.cpp b/clang-tools-extra/test/clang-doc/json/class-specialization.cpp index 6fd2f81e49b46..3c7785a849949 100644 --- a/clang-tools-extra/test/clang-doc/json/class-specialization.cpp +++ b/clang-tools-extra/test/clang-doc/json/class-specialization.cpp @@ -20,7 +20,8 @@ template<> struct MyClass<int> {}; // BASE-NEXT: "End": true, // BASE-NEXT: "Param": "typename T" // BASE-NEXT: } -// BASE-NEXT: ] +// BASE-NEXT: ], +// BASE-NEXT: "VerticalDisplay": false // BASE-NEXT: }, // SPECIALIZATION: "MangledName": "_ZTV7MyClassIiE", @@ -38,6 +39,7 @@ template<> struct MyClass<int> {}; // SPECIALIZATION-NEXT: "Param": "int" // SPECIALIZATION-NEXT: } // SPECIALIZATION-NEXT: ], -// SPECIALIZATION-NEXT: "SpecializationOf": "{{[0-9A-F]*}}" +// SPECIALIZATION-NEXT: "SpecializationOf": "{{[0-9A-F]*}}", +// SPECIALIZATION-NEXT: "VerticalDisplay": false // SPECIALIZATION-NEXT: } // SPECIALIZATION-NEXT: }, diff --git a/clang-tools-extra/test/clang-doc/json/class-template.cpp b/clang-tools-extra/test/clang-doc/json/class-template.cpp index 67bf910a8e88d..0a880f9eb367d 100644 --- a/clang-tools-extra/test/clang-doc/json/class-template.cpp +++ b/clang-tools-extra/test/clang-doc/json/class-template.cpp @@ -18,8 +18,8 @@ template<typename T> struct MyClass { // CHECK: "Name": "method", // CHECK: "Params": [ // CHECK-NEXT: { -// CHECK-NEXT: "End": true, // CHECK-NEXT: "Name": "Param", +// CHECK-NEXT: "ParamEnd": true, // CHECK-NEXT: "Type": { // CHECK-NEXT: "Name": "T", // CHECK-NEXT: "QualName": "T", @@ -39,4 +39,6 @@ template<typename T> struct MyClass { // CHECK-NEXT: "End": true, // CHECK-NEXT: "Param": "typename T" // CHECK-NEXT: } -// CHECK-NEXT: ] +// CHECK-NEXT: ], +// CHECK-NEXT: "VerticalDisplay": false +// CHECK-NEXT: } diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp index d9ea023bf6827..0dafde6e50230 100644 --- a/clang-tools-extra/test/clang-doc/json/class.cpp +++ b/clang-tools-extra/test/clang-doc/json/class.cpp @@ -139,9 +139,11 @@ struct MyClass { // CHECK-NEXT: "End": true, // CHECK-NEXT: "Param": "typename T" // CHECK-NEXT: } -// CHECK-NEXT: ] +// CHECK-NEXT: ], +// CHECK-NEXT: "VerticalDisplay": false // CHECK-NEXT: } -// CHECK-NEXT: "USR": "0000000000000000000000000000000000000000" +// CHECK-NEXT: "USR": "0000000000000000000000000000000000000000", +// CHECK-NEXT: "VerticalDisplay": false // CHECK-NEXT: }, // CHECK-NEXT: { // CHECK-NEXT: "Description": { @@ -239,8 +241,8 @@ struct MyClass { // CHECK-NEXT: ], // CHECK-NEXT: "Params": [ // CHECK-NEXT: { -// CHECK-NEXT: "End": true, // CHECK-NEXT: "Name": "MyParam", +// CHECK-NEXT: "ParamEnd": true, // CHECK-NEXT: "Type": { // CHECK-NEXT: "Name": "int", // CHECK-NEXT: "QualName": "int", @@ -255,7 +257,8 @@ struct MyClass { // CHECK-NEXT: "QualName": "int", // CHECK-NEXT: "USR": "{{[0-9A-F]*}}" // CHECK-NEXT: }, -// CHECK-NEXT: "USR": "{{[0-9A-F]*}}" +// CHECK-NEXT: "USR": "{{[0-9A-F]*}}", +// CHECK-NEXT: "VerticalDisplay": false // CHECK-NEXT: }, // CHECK: "IsStatic": true, // CHECK: "Name": "getConst", diff --git a/clang-tools-extra/test/clang-doc/json/concept.cpp b/clang-tools-extra/test/clang-doc/json/concept.cpp index 2dc990363ac0b..70d20be1096e8 100644 --- a/clang-tools-extra/test/clang-doc/json/concept.cpp +++ b/clang-tools-extra/test/clang-doc/json/concept.cpp @@ -34,6 +34,7 @@ concept Incrementable = requires(T x) { // CHECK-NEXT: "Param": "typename T" // CHECK-NEXT: } // CHECK-NEXT: ] +// CHECK-NEXT: "VerticalDisplay": false // CHECK-NEXT: }, // CHECK-NEXT: "USR": "{{[0-9A-F]*}}" // CHECK-NEXT: } diff --git a/clang-tools-extra/test/clang-doc/json/function-requires.cpp b/clang-tools-extra/test/clang-doc/json/function-requires.cpp index 18604e0ddeac7..3e9d95a381cc7 100644 --- a/clang-tools-extra/test/clang-doc/json/function-requires.cpp +++ b/clang-tools-extra/test/clang-doc/json/function-requires.cpp @@ -19,8 +19,8 @@ template<Incrementable T> Incrementable auto incrementTwo(T t); // CHECK-NEXT: "Name": "increment", // CHECK-NEXT: "Params": [ // CHECK-NEXT: { -// CHECK-NEXT: "End": true, // CHECK-NEXT: "Name": "t", +// CHECK-NEXT: "ParamEnd": true // CHECK-NEXT: "Type": { // CHECK-NEXT: "Name": "T", // CHECK-NEXT: "QualName": "T", @@ -50,9 +50,11 @@ template<Incrementable T> Incrementable auto incrementTwo(T t); // CHECK-NEXT: "End": true, // CHECK-NEXT: "Param": "typename T" // CHECK-NEXT: } -// CHECK-NEXT: ] +// CHECK-NEXT: ], +// CHECK-NEXT: "VerticalDisplay": false // CHECK-NEXT: }, -// CHECK-NEXT: "USR": "{{[0-9A-F]*}}" +// CHECK-NEXT: "USR": "{{[0-9A-F]*}}", +// CHECK-NEXT: "VerticalDisplay": false // CHECK-NEXT: }, // CHECK-NEXT: { // CHECK-NEXT: "End": true, @@ -61,8 +63,8 @@ template<Incrementable T> Incrementable auto incrementTwo(T t); // CHECK-NEXT: "Name": "incrementTwo", // CHECK-NEXT: "Params": [ // CHECK-NEXT: { -// CHECK-NEXT: "End": true, // CHECK-NEXT: "Name": "t", +// CHECK-NEXT: "ParamEnd": true // CHECK-NEXT: "Type": { // CHECK-NEXT: "Name": "T", // CHECK-NEXT: "QualName": "T", @@ -92,7 +94,9 @@ template<Incrementable T> Incrementable auto incrementTwo(T t); // CHECK-NEXT: "End": true, // CHECK-NEXT: "Param": "Incrementable T" // CHECK-NEXT: } -// CHECK-NEXT: ] +// CHECK-NEXT: ], +// CHECK-NEXT: "VerticalDisplay": false // CHECK-NEXT: }, -// CHECK-NEXT: "USR": "{{[0-9A-F]*}}" +// CHECK-NEXT: "USR": "{{[0-9A-F]*}}", +// CHECK-NEXT: "VerticalDisplay": false // CHECK-NEXT: } diff --git a/clang-tools-extra/test/clang-doc/json/method-template.cpp b/clang-tools-extra/test/clang-doc/json/method-template.cpp index 189221512b674..793928d13d35b 100644 --- a/clang-tools-extra/test/clang-doc/json/method-template.cpp +++ b/clang-tools-extra/test/clang-doc/json/method-template.cpp @@ -22,8 +22,8 @@ struct MyClass { // CHECK-NEXT: ], // CHECK-NEXT: "Params": [ // CHECK-NEXT: { -// CHECK-NEXT: "End": true, // CHECK-NEXT: "Name": "param", +// CHECK-NEXT: "ParamEnd": true, // CHECK-NEXT: "Type": { // CHECK-NEXT: "Name": "T", // CHECK-NEXT: "QualName": "T", @@ -44,6 +44,7 @@ struct MyClass { // CHECK-NEXT: "End": true, // CHECK-NEXT: "Param": "class T" // CHECK-NEXT: } -// CHECK-NEXT: ] +// CHECK-NEXT: ], +// CHECK-NEXT: "VerticalDisplay": false // CHECK-NEXT: }, // CHECK-NEXT: "USR": "{{[0-9A-F]*}}" diff --git a/clang-tools-extra/test/clang-doc/json/namespace.cpp b/clang-tools-extra/test/clang-doc/json/namespace.cpp index 8681c15bf1048..59f6f5491cdc5 100644 --- a/clang-tools-extra/test/clang-doc/json/namespace.cpp +++ b/clang-tools-extra/test/clang-doc/json/namespace.cpp @@ -58,8 +58,8 @@ typedef int MyTypedef; // CHECK-NEXT: "Name": "myFunction", // CHECK-NEXT: "Params": [ // CHECK-NEXT: { -// CHECK-NEXT: "End": true, // CHECK-NEXT: "Name": "Param", +// CHECK-NEXT: "ParamEnd": true, // CHECK-NEXT: "Type": { // CHECK-NEXT: "Name": "int", // CHECK-NEXT: "QualName": "int", @@ -74,7 +74,8 @@ typedef int MyTypedef; // CHECK-NEXT: "QualName": "void", // CHECK-NEXT: "USR": "0000000000000000000000000000000000000000" // CHECK-NEXT: }, -// CHECK-NEXT: "USR": "{{[0-9A-F]*}}" +// CHECK-NEXT: "USR": "{{[0-9A-F]*}}", +// CHECK-NEXT: "VerticalDisplay": false // CHECK-NEXT: } // CHECK-NEXT: ], // CHECK-NEXT: "HasEnums": true, diff --git a/clang-tools-extra/test/clang-doc/templates.cpp b/clang-tools-extra/test/clang-doc/templates.cpp index 8c9b0b53a8b3d..a80007fe0baee 100644 --- a/clang-tools-extra/test/clang-doc/templates.cpp +++ b/clang-tools-extra/test/clang-doc/templates.cpp @@ -52,8 +52,8 @@ void ParamPackFunction(T... args); // JSON: "Name": "ParamPackFunction", // JSON-NEXT: "Params": [ // JSON-NEXT: { -// JSON-NEXT: "End": true, // JSON-NEXT: "Name": "args", +// JSON-NEXT: "ParamEnd": true, // JSON-NEXT: "Type": { // JSON-NEXT: "Name": "T...", // JSON-NEXT: "QualName": "T...", @@ -74,10 +74,11 @@ void ParamPackFunction(T... args); // JSON-NEXT: "End": true, // JSON-NEXT: "Param": "class... T" // JSON-NEXT: } -// JSON-NEXT: ] +// JSON-NEXT: ], +// JSON-NEXT: "VerticalDisplay": false // JSON-NEXT: }, -// HTML: <pre><code class="language-cpp code-clang-doc">template <class... T></code></pre> +// HTML: <pre><code class="language-cpp code-clang-doc">template <class... T</code><code class="language-cpp code-clang-doc">></code></pre> // HTML-NEXT: <pre><code class="language-cpp code-clang-doc">void ParamPackFunction (T... args)</code></pre> template <typename T, int U = 1> @@ -109,8 +110,8 @@ void function(T x) {} // JSON: "Name": "function", // JSON-NEXT: "Params": [ // JSON-NEXT: { -// JSON-NEXT: "End": true, // JSON-NEXT: "Name": "x", +// JSON-NEXT: "ParamEnd": true, // JSON-NEXT: "Type": { // JSON-NEXT: "Name": "T", // JSON-NEXT: "QualName": "T", @@ -134,12 +135,13 @@ void function(T x) {} // JSON-NEXT: "End": true, // JSON-NEXT: "Param": "int U = 1" // JSON-NEXT: } -// JSON-NEXT: ] +// JSON-NEXT: ], +// JSON-NEXT: "VerticalDisplay": false // JSON-NEXT: } -// HTML: <pre><code class="language-cpp code-clang-doc">template <typename T, int U = 1></code></pre> +// HTML: <pre><code class="language-cpp code-clang-doc">template <typename T, int U = 1</code><code class="language-cpp code-clang-doc">></code></pre> // HTML-NEXT: <pre><code class="language-cpp code-clang-doc">void function (T x)</code></pre> -// HTML-NEXT: <p>Defined at line [[# @LINE - 58]] of file {{.*}}templates.cpp</p> +// HTML-NEXT: <p>Defined at line [[# @LINE - 59]] of file {{.*}}templates.cpp</p> // HTML-NEXT: </div> @@ -174,8 +176,8 @@ void function<bool, 0>(bool x) {} // JSON: "Name": "function", // JSON-NEXT: "Params": [ // JSON-NEXT: { -// JSON-NEXT: "End": true, // JSON-NEXT: "Name": "x", +// JSON-NEXT: "ParamEnd": true, // JSON-NEXT: "Type": { // JSON-NEXT: "Name": "bool", // JSON-NEXT: "QualName": "bool", @@ -201,13 +203,14 @@ void function<bool, 0>(bool x) {} // JSON-NEXT: "Param": "0" // JSON-NEXT: } // JSON-NEXT: ], -// JSON-NEXT: "SpecializationOf": "{{([0-9A-F]{40})}}" +// JSON-NEXT: "SpecializationOf": "{{([0-9A-F]{40})}}", +// JSON-NEXT: "VerticalDisplay": false // JSON-NEXT: } // JSON-NEXT: }, -// HTML: <pre><code class="language-cpp code-clang-doc">template <></code></pre> +// HTML: <pre><code class="language-cpp code-clang-doc">template <</code><code class="language-cpp code-clang-doc">></code></pre> // HTML-NEXT: <pre><code class="language-cpp code-clang-doc">void function<bool, 0> (bool x)</code></pre> -// HTML-NEXT: <p>Defined at line [[# @LINE - 64]] of file {{.*}}templates.cpp</p> +// HTML-NEXT: <p>Defined at line [[# @LINE - 65]] of file {{.*}}templates.cpp</p> // HTML-NEXT: </div> /// A Tuple type @@ -286,8 +289,8 @@ tuple<int, int, bool> func_with_tuple_param(tuple<int, int, bool> t) { return t; // JSON: "Name": "func_with_tuple_param", // JSON-NEXT: "Params": [ // JSON-NEXT: { -// JSON-NEXT: "End": true, // JSON-NEXT: "Name": "t", +// JSON-NEXT: "ParamEnd": true, // JSON-NEXT: "Type": { // JSON-NEXT: "Name": "tuple", // JSON-NEXT: "Path": "GlobalNamespace", diff --git a/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp index 021748895b208..7e880aa93b635 100644 --- a/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp +++ b/clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp @@ -179,7 +179,8 @@ TEST_F(JSONGeneratorTest, emitRecordJSON) { "End": true, "Param": "class T" } - ] + ], + "VerticalDisplay": false }, "USR": "0000000000000000000000000000000000000000", "VirtualParents": [ >From 9fc96a4b0de806ddf856d9e1afb14808a5c7df0a Mon Sep 17 00:00:00 2001 From: Samrudh Nelli <[email protected]> Date: Tue, 24 Feb 2026 01:46:29 +0530 Subject: [PATCH 10/14] implement a Customize() function to set VerticalDisplay --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 27 +++++++++++-------- .../test/clang-doc/json/class.cpp | 3 +-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 4f5470bcb5737..7836196a24785 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -34,10 +34,10 @@ static void serializeInfo(const RecordInfo &I, Object &Obj, static void serializeReference(const Reference &Ref, Object &ReferenceObj); template <typename Container, typename SerializationFunc> -static void serializeArray(const Container &Records, Object &Obj, - const std::string &Key, - SerializationFunc SerializeInfo, - const std::string &EndKey = "End"); +static void +serializeArray(const Container &Records, Object &Obj, const StringRef Key, + SerializationFunc SerializeInfo, const StringRef EndKey = "End", + void (*Customizer)(Object &Obj, size_t Size) = nullptr); // Convenience lambda to pass to serializeArray. // If a serializeInfo needs a RepositoryUrl, create a local lambda that captures @@ -442,10 +442,14 @@ serializeCommonChildren(const ScopeChildren &Children, json::Object &Obj, } } +static void customize(Object &Obj, size_t Size) { + Obj["VerticalDisplay"] = Size > 2; +} + template <typename Container, typename SerializationFunc> -static void -serializeArray(const Container &Records, Object &Obj, const std::string &Key, - SerializationFunc SerializeInfo, const std::string &EndKey) { +static void serializeArray(const Container &Records, Object &Obj, StringRef Key, + SerializationFunc SerializeInfo, StringRef EndKey, + void (*Customize)(Object &Obj, size_t Size)) { json::Value RecordsArray = Array(); auto &RecordsArrayRef = *RecordsArray.getAsArray(); RecordsArrayRef.reserve(Records.size()); @@ -458,8 +462,8 @@ serializeArray(const Container &Records, Object &Obj, const std::string &Key, RecordsArrayRef.push_back(ItemVal); } Obj[Key] = RecordsArray; - if (Key == "Params") - Obj["VerticalDisplay"] = Records.size() > 2; + if (Customize) + Customize(Obj, Records.size()); } static void serializeInfo(const ConstraintInfo &I, Object &Obj) { @@ -482,7 +486,7 @@ static void serializeInfo(const ArrayRef<TemplateParamInfo> &Params, ParamsArrayRef.push_back(ParamObjVal); } Obj["Parameters"] = ParamsArray; - Obj["VerticalDisplay"] = Params.size() > 2; + customize(Obj, Params.size()); } static void serializeInfo(const TemplateInfo &Template, Object &Obj) { @@ -546,7 +550,8 @@ static void serializeInfo(const FunctionInfo &F, json::Object &Obj, Obj["ReturnType"] = std::move(ReturnTypeObj); if (!F.Params.empty()) - serializeArray(F.Params, Obj, "Params", SerializeInfoLambda, "ParamEnd"); + serializeArray(F.Params, Obj, "Params", SerializeInfoLambda, "ParamEnd", + customize); if (F.Template) serializeInfo(F.Template.value(), Obj); diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp index 0dafde6e50230..6783e71a201db 100644 --- a/clang-tools-extra/test/clang-doc/json/class.cpp +++ b/clang-tools-extra/test/clang-doc/json/class.cpp @@ -142,8 +142,7 @@ struct MyClass { // CHECK-NEXT: ], // CHECK-NEXT: "VerticalDisplay": false // CHECK-NEXT: } -// CHECK-NEXT: "USR": "0000000000000000000000000000000000000000", -// CHECK-NEXT: "VerticalDisplay": false +// CHECK-NEXT: "USR": "0000000000000000000000000000000000000000" // CHECK-NEXT: }, // CHECK-NEXT: { // CHECK-NEXT: "Description": { >From 508295484131e6287c9975afdc3427803ba14583 Mon Sep 17 00:00:00 2001 From: Samrudh Nelli <[email protected]> Date: Tue, 24 Feb 2026 03:50:30 +0530 Subject: [PATCH 11/14] use a lambda instead of a customize function remove redundant serializeinfo for templates --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 67 +++++++++---------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 7836196a24785..d6d768ee279d7 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -34,10 +34,10 @@ static void serializeInfo(const RecordInfo &I, Object &Obj, static void serializeReference(const Reference &Ref, Object &ReferenceObj); template <typename Container, typename SerializationFunc> -static void -serializeArray(const Container &Records, Object &Obj, const StringRef Key, - SerializationFunc SerializeInfo, const StringRef EndKey = "End", - void (*Customizer)(Object &Obj, size_t Size) = nullptr); +static void serializeArray( + const Container &Records, Object &Obj, const StringRef Key, + SerializationFunc SerializeInfo, const StringRef EndKey = "End", + function_ref<void(Object &)> UpdateJson = [](Object &Obj) {}); // Convenience lambda to pass to serializeArray. // If a serializeInfo needs a RepositoryUrl, create a local lambda that captures @@ -442,14 +442,10 @@ serializeCommonChildren(const ScopeChildren &Children, json::Object &Obj, } } -static void customize(Object &Obj, size_t Size) { - Obj["VerticalDisplay"] = Size > 2; -} - template <typename Container, typename SerializationFunc> static void serializeArray(const Container &Records, Object &Obj, StringRef Key, SerializationFunc SerializeInfo, StringRef EndKey, - void (*Customize)(Object &Obj, size_t Size)) { + function_ref<void(Object &)> UpdateJson) { json::Value RecordsArray = Array(); auto &RecordsArrayRef = *RecordsArray.getAsArray(); RecordsArrayRef.reserve(Records.size()); @@ -462,8 +458,7 @@ static void serializeArray(const Container &Records, Object &Obj, StringRef Key, RecordsArrayRef.push_back(ItemVal); } Obj[Key] = RecordsArray; - if (Customize) - Customize(Obj, Records.size()); + UpdateJson(Obj); } static void serializeInfo(const ConstraintInfo &I, Object &Obj) { @@ -471,40 +466,38 @@ static void serializeInfo(const ConstraintInfo &I, Object &Obj) { Obj["Expression"] = I.ConstraintExpr; } -static void serializeInfo(const ArrayRef<TemplateParamInfo> &Params, - Object &Obj) { - json::Value ParamsArray = Array(); - auto &ParamsArrayRef = *ParamsArray.getAsArray(); - ParamsArrayRef.reserve(Params.size()); - for (size_t Idx = 0; Idx < Params.size(); ++Idx) { - json::Value ParamObjVal = Object(); - Object &ParamObj = *ParamObjVal.getAsObject(); - - ParamObj["Param"] = Params[Idx].Contents; - if (Idx == Params.size() - 1) - ParamObj["End"] = true; - ParamsArrayRef.push_back(ParamObjVal); - } - Obj["Parameters"] = ParamsArray; - customize(Obj, Params.size()); -} - static void serializeInfo(const TemplateInfo &Template, Object &Obj) { json::Value TemplateVal = Object(); auto &TemplateObj = *TemplateVal.getAsObject(); + auto SerializeTemplateParam = [](const TemplateParamInfo &Param, + Object &JsonObj) { + JsonObj["Param"] = Param.Contents; + }; if (Template.Specialization) { json::Value TemplateSpecializationVal = Object(); auto &TemplateSpecializationObj = *TemplateSpecializationVal.getAsObject(); TemplateSpecializationObj["SpecializationOf"] = toHex(toStringRef(Template.Specialization->SpecializationOf)); - if (!Template.Specialization->Params.empty()) - serializeInfo(Template.Specialization->Params, TemplateSpecializationObj); + if (!Template.Specialization->Params.empty()) { + bool VerticalDisplay = Template.Specialization->Params.size() > 2; + serializeArray(Template.Specialization->Params, TemplateSpecializationObj, + "Parameters", SerializeTemplateParam, "End", + [VerticalDisplay](Object &JsonObj) { + JsonObj["VerticalDisplay"] = VerticalDisplay; + }); + } TemplateObj["Specialization"] = TemplateSpecializationVal; } - if (!Template.Params.empty()) - serializeInfo(Template.Params, TemplateObj); + if (!Template.Params.empty()) { + bool VerticalDisplay = Template.Params.size() > 2; + serializeArray(Template.Params, TemplateObj, "Parameters", + SerializeTemplateParam, "End", + [VerticalDisplay](Object &JsonObj) { + JsonObj["VerticalDisplay"] = VerticalDisplay; + }); + } if (!Template.Constraints.empty()) serializeArray(Template.Constraints, TemplateObj, "Constraints", @@ -549,9 +542,13 @@ static void serializeInfo(const FunctionInfo &F, json::Object &Obj, serializeInfo(F.ReturnType, ReturnTypeObj); Obj["ReturnType"] = std::move(ReturnTypeObj); - if (!F.Params.empty()) + if (!F.Params.empty()) { + const bool VerticalDisplay = F.Params.size() > 2; serializeArray(F.Params, Obj, "Params", SerializeInfoLambda, "ParamEnd", - customize); + [VerticalDisplay](Object &JsonObj) { + JsonObj["VerticalDisplay"] = VerticalDisplay; + }); + } if (F.Template) serializeInfo(F.Template.value(), Obj); >From 2cc4f427aebd5268f68e4a03372d0b469169233e Mon Sep 17 00:00:00 2001 From: Samrudh Nelli <[email protected]> Date: Tue, 24 Feb 2026 12:50:43 +0530 Subject: [PATCH 12/14] add a test for a long function, and use getMaxParamWrapLimit() --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 9 +- .../test/clang-doc/templates.cpp | 125 ++++++++++++++++++ 2 files changed, 131 insertions(+), 3 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index d6d768ee279d7..a6ea241817dc9 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -39,6 +39,8 @@ static void serializeArray( SerializationFunc SerializeInfo, const StringRef EndKey = "End", function_ref<void(Object &)> UpdateJson = [](Object &Obj) {}); +constexpr static unsigned getMaxParamWrapLimit() { return 2; } + // Convenience lambda to pass to serializeArray. // If a serializeInfo needs a RepositoryUrl, create a local lambda that captures // the optional. @@ -480,7 +482,8 @@ static void serializeInfo(const TemplateInfo &Template, Object &Obj) { TemplateSpecializationObj["SpecializationOf"] = toHex(toStringRef(Template.Specialization->SpecializationOf)); if (!Template.Specialization->Params.empty()) { - bool VerticalDisplay = Template.Specialization->Params.size() > 2; + bool VerticalDisplay = + Template.Specialization->Params.size() > getMaxParamWrapLimit(); serializeArray(Template.Specialization->Params, TemplateSpecializationObj, "Parameters", SerializeTemplateParam, "End", [VerticalDisplay](Object &JsonObj) { @@ -491,7 +494,7 @@ static void serializeInfo(const TemplateInfo &Template, Object &Obj) { } if (!Template.Params.empty()) { - bool VerticalDisplay = Template.Params.size() > 2; + bool VerticalDisplay = Template.Params.size() > getMaxParamWrapLimit(); serializeArray(Template.Params, TemplateObj, "Parameters", SerializeTemplateParam, "End", [VerticalDisplay](Object &JsonObj) { @@ -543,7 +546,7 @@ static void serializeInfo(const FunctionInfo &F, json::Object &Obj, Obj["ReturnType"] = std::move(ReturnTypeObj); if (!F.Params.empty()) { - const bool VerticalDisplay = F.Params.size() > 2; + const bool VerticalDisplay = F.Params.size() > getMaxParamWrapLimit(); serializeArray(F.Params, Obj, "Params", SerializeInfoLambda, "ParamEnd", [VerticalDisplay](Object &JsonObj) { JsonObj["VerticalDisplay"] = VerticalDisplay; diff --git a/clang-tools-extra/test/clang-doc/templates.cpp b/clang-tools-extra/test/clang-doc/templates.cpp index a80007fe0baee..88e1a522a8b0b 100644 --- a/clang-tools-extra/test/clang-doc/templates.cpp +++ b/clang-tools-extra/test/clang-doc/templates.cpp @@ -144,6 +144,131 @@ void function(T x) {} // HTML-NEXT: <p>Defined at line [[# @LINE - 59]] of file {{.*}}templates.cpp</p> // HTML-NEXT: </div> +template <typename A, typename B, typename C, typename D, typename E> +void longFunction(A a, B b, C c, D d, E e) {} + +// YAML-NEXT: - USR: '{{([0-9A-F]{40})}}' +// YAML-NEXT: Name: 'longFunction' +// YAML-NEXT: DefLocation: +// YAML-NEXT: LineNumber: [[# @LINE - 5]] +// YAML-NEXT: Filename: '{{.*}}' +// YAML-NEXT: Params: +// YAML-NEXT: - Type: +// YAML-NEXT: Name: 'A' +// YAML-NEXT: QualName: 'A' +// YAML-NEXT: Name: 'a' +// YAML-NEXT: - Type: +// YAML-NEXT: Name: 'B' +// YAML-NEXT: QualName: 'B' +// YAML-NEXT: Name: 'b' +// YAML-NEXT: - Type: +// YAML-NEXT: Name: 'C' +// YAML-NEXT: QualName: 'C' +// YAML-NEXT: Name: 'c' +// YAML-NEXT: - Type: +// YAML-NEXT: Name: 'D' +// YAML-NEXT: QualName: 'D' +// YAML-NEXT: Name: 'd' +// YAML-NEXT: - Type: +// YAML-NEXT: Name: 'E' +// YAML-NEXT: QualName: 'E' +// YAML-NEXT: Name: 'e' +// YAML-NEXT: ReturnType: +// YAML-NEXT: Type: +// YAML-NEXT: Name: 'void' +// YAML-NEXT: QualName: 'void' +// YAML-NEXT: Template: +// YAML-NEXT: Params: +// YAML-NEXT: - Contents: 'typename A' +// YAML-NEXT: - Contents: 'typename B' +// YAML-NEXT: - Contents: 'typename C' +// YAML-NEXT: - Contents: 'typename D' +// YAML-NEXT: - Contents: 'typename E' + +// MD: ### longFunction +// MD: *void longFunction(A a, B b, C c, D d, E e)* +// MD: *Defined at {{.*}}templates.cpp#[[# @LINE - 42]]* + +// JSON: "Name": "longFunction", +// JSON-NEXT: "Params": [ +// JSON-NEXT: { +// JSON-NEXT: "Name": "a", +// JSON-NEXT: "Type": { +// JSON-NEXT: "Name": "A", +// JSON-NEXT: "QualName": "A", +// JSON-NEXT: "USR": "0000000000000000000000000000000000000000" +// JSON-NEXT: } +// JSON-NEXT: }, +// JSON-NEXT: { +// JSON-NEXT: "Name": "b", +// JSON-NEXT: "Type": { +// JSON-NEXT: "Name": "B", +// JSON-NEXT: "QualName": "B", +// JSON-NEXT: "USR": "0000000000000000000000000000000000000000" +// JSON-NEXT: } +// JSON-NEXT: }, +// JSON-NEXT: { +// JSON-NEXT: "Name": "c", +// JSON-NEXT: "Type": { +// JSON-NEXT: "Name": "C", +// JSON-NEXT: "QualName": "C", +// JSON-NEXT: "USR": "0000000000000000000000000000000000000000" +// JSON-NEXT: } +// JSON-NEXT: }, +// JSON-NEXT: { +// JSON-NEXT: "Name": "d", +// JSON-NEXT: "Type": { +// JSON-NEXT: "Name": "D", +// JSON-NEXT: "QualName": "D", +// JSON-NEXT: "USR": "0000000000000000000000000000000000000000" +// JSON-NEXT: } +// JSON-NEXT: }, +// JSON-NEXT: { +// JSON-NEXT: "Name": "e", +// JSON-NEXT: "ParamEnd": true, +// JSON-NEXT: "Type": { +// JSON-NEXT: "Name": "E", +// JSON-NEXT: "QualName": "E", +// JSON-NEXT: "USR": "0000000000000000000000000000000000000000" +// JSON-NEXT: } +// JSON-NEXT: } +// JSON-NEXT: ], +// JSON-NEXT: "ReturnType": { +// JSON-NEXT: "IsBuiltIn": true, +// JSON-NEXT: "IsTemplate": false, +// JSON-NEXT: "Name": "void", +// JSON-NEXT: "QualName": "void", +// JSON-NEXT: "USR": "0000000000000000000000000000000000000000" +// JSON-NEXT: }, +// JSON-NEXT: "Template": { +// JSON-NEXT: "Parameters": [ +// JSON-NEXT: { +// JSON-NEXT: "Param": "typename A" +// JSON-NEXT: }, +// JSON-NEXT: { +// JSON-NEXT: "Param": "typename B" +// JSON-NEXT: }, +// JSON-NEXT: { +// JSON-NEXT: "Param": "typename C" +// JSON-NEXT: }, +// JSON-NEXT: { +// JSON-NEXT: "Param": "typename D" +// JSON-NEXT: }, +// JSON-NEXT: { +// JSON-NEXT: "End": true, +// JSON-NEXT: "Param": "typename E" +// JSON-NEXT: } +// JSON-NEXT: ], +// JSON-NEXT: "VerticalDisplay": true +// JSON-NEXT: }, +// JSON-NEXT: "USR": "{{([0-9A-F]{40})}}", +// JSON-NEXT: "VerticalDisplay": true +// JSON-NEXT: } + +// HTML: <pre><code class="language-cpp code-clang-doc">template <</code><span class="param-container"><span class="param"><code class="language-cpp code-clang-doc">typename A, </code></span><span class="param"><code class="language-cpp code-clang-doc">typename B, </code></span><span class="param"><code class="language-cpp code-clang-doc">typename C, </code></span><span class="param"><code class="language-cpp code-clang-doc">typename D, </code></span><span class="param"><code class="language-cpp code-clang-doc">typename E</code></span></span><code class="language-cpp code-clang-doc">></code></pre> +// HTML-NEXT: <pre><code class="language-cpp code-clang-doc">void longFunction (</code><span class="param-container"><span class="param"><code class="language-cpp code-clang-doc">A</code> <code class="language-cpp code-clang-doc">a, </code></span><span class="param"><code class="language-cpp code-clang-doc">B</code> <code class="language-cpp code-clang-doc">b, </code></span><span class="param"><code class="language-cpp code-clang-doc">C</code> <code class="language-cpp code-clang-doc">c, </code></span><span class="param"><code class="language-cpp code-clang-doc">D</code> <code class="language-cpp code-clang-doc">d, </code></span><span class="param"><code class="language-cpp code-clang-doc">E</code> <code class="language-cpp code-clang-doc">e</code></span></span><code class="language-cpp code-clang-doc">)</code></pre> +// HTML-NEXT: <p>Defined at line [[# @LINE - 122]] of file {{.*}}templates.cpp</p> +// HTML-NEXT: </div> template <> void function<bool, 0>(bool x) {} >From 481a9d64687ba1f14197028de7272dc347ee4b0c Mon Sep 17 00:00:00 2001 From: Samrudh Nelli <[email protected]> Date: Wed, 25 Feb 2026 01:08:22 +0530 Subject: [PATCH 13/14] chore: improve readability of the new HTML test --- .../test/clang-doc/templates.cpp | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/clang-tools-extra/test/clang-doc/templates.cpp b/clang-tools-extra/test/clang-doc/templates.cpp index 88e1a522a8b0b..870841e110dde 100644 --- a/clang-tools-extra/test/clang-doc/templates.cpp +++ b/clang-tools-extra/test/clang-doc/templates.cpp @@ -265,9 +265,29 @@ void longFunction(A a, B b, C c, D d, E e) {} // JSON-NEXT: "VerticalDisplay": true // JSON-NEXT: } -// HTML: <pre><code class="language-cpp code-clang-doc">template <</code><span class="param-container"><span class="param"><code class="language-cpp code-clang-doc">typename A, </code></span><span class="param"><code class="language-cpp code-clang-doc">typename B, </code></span><span class="param"><code class="language-cpp code-clang-doc">typename C, </code></span><span class="param"><code class="language-cpp code-clang-doc">typename D, </code></span><span class="param"><code class="language-cpp code-clang-doc">typename E</code></span></span><code class="language-cpp code-clang-doc">></code></pre> -// HTML-NEXT: <pre><code class="language-cpp code-clang-doc">void longFunction (</code><span class="param-container"><span class="param"><code class="language-cpp code-clang-doc">A</code> <code class="language-cpp code-clang-doc">a, </code></span><span class="param"><code class="language-cpp code-clang-doc">B</code> <code class="language-cpp code-clang-doc">b, </code></span><span class="param"><code class="language-cpp code-clang-doc">C</code> <code class="language-cpp code-clang-doc">c, </code></span><span class="param"><code class="language-cpp code-clang-doc">D</code> <code class="language-cpp code-clang-doc">d, </code></span><span class="param"><code class="language-cpp code-clang-doc">E</code> <code class="language-cpp code-clang-doc">e</code></span></span><code class="language-cpp code-clang-doc">)</code></pre> -// HTML-NEXT: <p>Defined at line [[# @LINE - 122]] of file {{.*}}templates.cpp</p> +// HTML: <pre> +// HTML-SAME: <code class="language-cpp code-clang-doc">template <</code> +// HTML-SAME: <span class="param-container"> +// HTML-SAME: <span class="param"><code class="language-cpp code-clang-doc">typename A, </code></span> +// HTML-SAME: <span class="param"><code class="language-cpp code-clang-doc">typename B, </code></span> +// HTML-SAME: <span class="param"><code class="language-cpp code-clang-doc">typename C, </code></span> +// HTML-SAME: <span class="param"><code class="language-cpp code-clang-doc">typename D, </code></span> +// HTML-SAME: <span class="param"><code class="language-cpp code-clang-doc">typename E</code></span> +// HTML-SAME: </span> +// HTML-SAME: <code class="language-cpp code-clang-doc">></code> +// HTML-SAME: </pre> +// HTML-NEXT: <pre> +// HTML-SAME: <code class="language-cpp code-clang-doc">void longFunction (</code> +// HTML-SAME: <span class="param-container"> +// HTML-SAME: <span class="param"><code class="language-cpp code-clang-doc">A</code> <code class="language-cpp code-clang-doc">a, </code></span> +// HTML-SAME: <span class="param"><code class="language-cpp code-clang-doc">B</code> <code class="language-cpp code-clang-doc">b, </code></span> +// HTML-SAME: <span class="param"><code class="language-cpp code-clang-doc">C</code> <code class="language-cpp code-clang-doc">c, </code></span> +// HTML-SAME: <span class="param"><code class="language-cpp code-clang-doc">D</code> <code class="language-cpp code-clang-doc">d, </code></span> +// HTML-SAME: <span class="param"><code class="language-cpp code-clang-doc">E</code> <code class="language-cpp code-clang-doc">e</code></span> +// HTML-SAME: </span> +// HTML-SAME: <code class="language-cpp code-clang-doc">)</code> +// HTML-SAME: </pre> +// HTML-NEXT: <p>Defined at line [[# @LINE - 142]] of file {{.*}}templates.cpp</p> // HTML-NEXT: </div> template <> >From c0046c9ef2f32523445ad00c249598c897d2466d Mon Sep 17 00:00:00 2001 From: Samrudh Nelli <[email protected]> Date: Wed, 25 Feb 2026 12:54:51 +0530 Subject: [PATCH 14/14] Update clang-tools-extra/clang-doc/JSONGenerator.cpp Co-authored-by: Paul Kirth <[email protected]> --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index a6ea241817dc9..be3778bc2c62e 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -39,6 +39,7 @@ static void serializeArray( SerializationFunc SerializeInfo, const StringRef EndKey = "End", function_ref<void(Object &)> UpdateJson = [](Object &Obj) {}); +// TODO(issue URL): Wrapping logic for HTML should probably use a more sophisticated heuristic than number of parameters. constexpr static unsigned getMaxParamWrapLimit() { return 2; } // Convenience lambda to pass to serializeArray. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
