Skip to content

Commit b84c397

Browse files
authored
impl(docfx): return descriptions go through markdown (#11612)
Finally found a way to convince docfx that we need the return type descriptions to go through markdown.
1 parent 98c5bee commit b84c397

3 files changed

Lines changed: 26 additions & 18 deletions

File tree

docfx/doxygen2syntax.cc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,22 @@ void AppendFunctionSyntax(YAML::Emitter& yaml, YamlContext const& ctx,
308308
<< YAML::BeginMap //
309309
<< YAML::Key << "contents" << YAML::Value << YAML::Literal //
310310
<< FunctionSyntaxContent(node);
311-
auto const rettype = HtmlEscape(LinkedTextType(node.child("type")));
311+
auto const rettype = LinkedTextType(node.child("type"));
312312
if (!rettype.empty()) {
313-
yaml << YAML::Key << "returns" << YAML::Value //
314-
<< YAML::BeginSeq << YAML::BeginMap //
315-
<< YAML::Key << "var_type" << YAML::Value //
316-
<< YAML::DoubleQuoted << rettype;
313+
// The `return` element accepts either a string for `type` or a sequence of
314+
// strings. If `type` is a string then it must be UID pointing to another
315+
// element in the documentation. That does not work in C++ where many
316+
// functions return primitive types and Doxygen does not create links for
317+
// the return type. So we create a sequence with a single element.
318+
yaml << YAML::Key << "return" << YAML::Value << YAML::BeginMap //
319+
<< YAML::Key << "type" << YAML::Value << YAML::BeginSeq //
320+
<< YAML::DoubleQuoted << rettype << YAML::EndSeq;
317321
auto description = ReturnDescription(ctx, node);
318322
if (!description.empty()) {
319323
yaml << YAML::Key << "description" << YAML::Value << YAML::Literal
320324
<< description;
321325
}
322-
yaml << YAML::EndMap << YAML::EndSeq;
326+
yaml << YAML::EndMap;
323327
}
324328
auto params = node.select_nodes("param");
325329
auto tparams = node.child("templateparamlist").children("param");

docfx/doxygen2syntax_test.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,11 @@ TEST(Doxygen2Syntax, Function) {
672672
google::cloud::CompletionQueue::MakeRelativeTimer (
673673
std::chrono::duration< Rep, Period > duration
674674
)
675-
returns:
676-
- var_type: "future&lt; StatusOr&lt; std::chrono::system_clock::time_point &gt; &gt;"
677-
description: |
678-
a future that becomes satisfied after `duration` time has elapsed. The result of the future is the time at which it expired, or an error [Status](xref:classgoogle_1_1cloud_1_1Status) if the timer did not run to expiration (e.g. it was cancelled).
675+
return:
676+
type:
677+
- "future< StatusOr< std::chrono::system_clock::time_point > >"
678+
description: |
679+
a future that becomes satisfied after `duration` time has elapsed. The result of the future is the time at which it expired, or an error [Status](xref:classgoogle_1_1cloud_1_1Status) if the timer did not run to expiration (e.g. it was cancelled).
679680
parameters:
680681
- id: duration
681682
var_type: "std::chrono::duration&lt; Rep, Period &gt;"

docfx/doxygen2yaml_test.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,11 @@ TEST(Doxygen2Yaml, Function) {
734734
google::cloud::CompletionQueue::MakeRelativeTimer (
735735
std::chrono::duration< Rep, Period > duration
736736
)
737-
returns:
738-
- var_type: "future&lt; StatusOr&lt; std::chrono::system_clock::time_point &gt; &gt;"
739-
description: |
740-
a future that becomes satisfied after `duration` time has elapsed. The result of the future is the time at which it expired, or an error [Status](xref:classgoogle_1_1cloud_1_1Status) if the timer did not run to expiration (e.g. it was cancelled).
737+
return:
738+
type:
739+
- "future< StatusOr< std::chrono::system_clock::time_point > >"
740+
description: |
741+
a future that becomes satisfied after `duration` time has elapsed. The result of the future is the time at which it expired, or an error [Status](xref:classgoogle_1_1cloud_1_1Status) if the timer did not run to expiration (e.g. it was cancelled).
741742
parameters:
742743
- id: duration
743744
var_type: "std::chrono::duration&lt; Rep, Period &gt;"
@@ -796,8 +797,9 @@ TEST(Doxygen2Yaml, MockedFunction) {
796797
google::cloud::kms_inventory_v1::KeyDashboardServiceConnection::ListCryptoKeys (
797798
google::cloud::kms::inventory::v1::ListCryptoKeysRequest request
798799
)
799-
returns:
800-
- var_type: "StreamRange&lt; google::cloud::kms::v1::CryptoKey &gt;"
800+
return:
801+
type:
802+
- "StreamRange< google::cloud::kms::v1::CryptoKey >"
801803
parameters:
802804
- id: request
803805
var_type: "google::cloud::kms::inventory::v1::ListCryptoKeysRequest"
@@ -985,8 +987,9 @@ TEST(Doxygen2Yaml, Class) {
985987
contents: |
986988
Status const &
987989
google::cloud::RuntimeStatusError::status ()
988-
returns:
989-
- var_type: "Status const &"
990+
return:
991+
type:
992+
- "Status const &"
990993
source:
991994
id: status
992995
path: google/cloud/status.h

0 commit comments

Comments
 (0)