Skip to content

Commit 901c0a2

Browse files
committed
tweak: remove callouts from proto/json, we just parse these in the description
1 parent 5eb74f2 commit 901c0a2

7 files changed

Lines changed: 27 additions & 51 deletions

File tree

src/NativeCodeGen.Core/Export/DatabaseConverter.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,11 @@ private static ExportNative ConvertNative(NativeDefinition native)
9898
ReturnDescription = native.ReturnDescription,
9999
Aliases = native.Aliases.Count > 0 ? native.Aliases : null,
100100
RelatedExamples = native.RelatedExamples.Count > 0 ? native.RelatedExamples : null,
101-
Callouts = native.Callouts.Count > 0 ? native.Callouts.Select(ConvertCallout).ToList() : null,
102101
ApiSet = native.ApiSet,
103102
Parameters = native.Parameters.Select(ConvertParameter).ToList()
104103
};
105104
}
106105

107-
private static ExportCallout ConvertCallout(Callout callout)
108-
{
109-
return new ExportCallout
110-
{
111-
Type = callout.Type,
112-
Title = callout.Title,
113-
Description = callout.Description
114-
};
115-
}
116-
117106
private static ExportParameter ConvertParameter(NativeParameter param)
118107
{
119108
return new ExportParameter

src/NativeCodeGen.Core/Export/ExportModels.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ public partial class ExportNative
7777
[ProtoMember(11)]
7878
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
7979
public List<string>? RelatedExamples { get; set; }
80-
81-
[ProtoMember(12)]
82-
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
83-
public List<ExportCallout>? Callouts { get; set; }
8480
}
8581

8682
[ProtoContract]
@@ -204,17 +200,3 @@ public partial class ExportSharedExampleCode
204200
public string? Language { get; set; }
205201
}
206202

207-
[ProtoContract]
208-
public partial class ExportCallout
209-
{
210-
[ProtoMember(1)]
211-
[JsonConverter(typeof(JsonStringEnumConverter<CalloutType>))]
212-
public CalloutType Type { get; set; }
213-
214-
[ProtoMember(2)]
215-
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
216-
public string? Title { get; set; }
217-
218-
[ProtoMember(3)]
219-
public string Description { get; set; } = string.Empty;
220-
}

src/NativeCodeGen.Core/Export/JsonContext.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ namespace NativeCodeGen.Core.Export;
2323
[JsonSerializable(typeof(ExportSharedExample))]
2424
[JsonSerializable(typeof(ExportSharedExampleCode))]
2525
[JsonSerializable(typeof(List<ExportSharedExampleCode>))]
26-
[JsonSerializable(typeof(ExportCallout))]
27-
[JsonSerializable(typeof(List<ExportCallout>))]
28-
[JsonSerializable(typeof(CalloutType))]
2926
[JsonSerializable(typeof(ParamFlags))]
3027
[JsonSerializable(typeof(FieldFlags))]
3128
[JsonSerializable(typeof(List<ExportNative>))]

src/NativeCodeGen.Core/Export/natives.proto

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ message Native {
6767
repeated string used_enums = 9;
6868
string apiset = 10;
6969
repeated string related_examples = 11;
70-
repeated Callout callouts = 12;
7170
}
7271

7372
message Parameter {
@@ -117,16 +116,3 @@ message SharedExampleCode {
117116
string content = 1;
118117
optional string language = 2;
119118
}
120-
121-
enum CalloutType {
122-
NOTE = 0;
123-
WARNING = 1;
124-
INFO = 2;
125-
DANGER = 3;
126-
}
127-
128-
message Callout {
129-
CalloutType type = 1;
130-
optional string title = 2;
131-
string description = 3;
132-
}

src/NativeCodeGen.Core/Models/Callout.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using ProtoBuf;
2-
31
namespace NativeCodeGen.Core.Models;
42

5-
[ProtoContract]
63
public enum CalloutType
74
{
85
Note = 0,

src/NativeCodeGen.Core/Parsing/MdxComponentParser.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public string NormalizeDescription(string content)
7575
/// <summary>
7676
/// Converts description text for code generation output.
7777
/// Transforms [enum: Name] and [struct: Name] to {@link Name} for JSDoc.
78+
/// Formats [note:], [warning:], [info:], [danger:] as readable callouts.
7879
/// </summary>
7980
public static string FormatDescriptionForCodeGen(string? content)
8081
{
@@ -87,9 +88,33 @@ public static string FormatDescriptionForCodeGen(string? content)
8788
// Convert [struct: Name] to {@link Name}
8889
result = StructAttributeRegex().Replace(result, "{@link $1}");
8990

91+
// Format callouts as @remarks tags (JSDoc/TypeDoc compatible)
92+
result = NoteAttributeRegex().Replace(result, m => FormatCalloutAsRemarks(m.Groups[1].Value));
93+
result = WarningAttributeRegex().Replace(result, m => FormatCalloutAsRemarks(m.Groups[1].Value, "Warning"));
94+
result = InfoAttributeRegex().Replace(result, m => FormatCalloutAsRemarks(m.Groups[1].Value));
95+
result = DangerAttributeRegex().Replace(result, m => FormatCalloutAsRemarks(m.Groups[1].Value, "Danger"));
96+
9097
return result;
9198
}
9299

100+
private static string FormatCalloutAsRemarks(string content, string? prefix = null)
101+
{
102+
var trimmed = content.Trim();
103+
// Check for title | description format
104+
var pipeIndex = trimmed.IndexOf('|');
105+
if (pipeIndex >= 0)
106+
{
107+
var title = trimmed[..pipeIndex].Trim();
108+
var description = trimmed[(pipeIndex + 1)..].Trim();
109+
trimmed = $"{title}: {description}";
110+
}
111+
112+
// Add newlines before and after to separate from surrounding text
113+
return prefix != null
114+
? $"\n@remarks **{prefix}:** {trimmed}\n"
115+
: $"\n@remarks {trimmed}\n";
116+
}
117+
93118
public List<EmbeddedEnumRef> ParseEmbeddedEnums(string content)
94119
{
95120
var results = new List<EmbeddedEnumRef>();

tests/NativeCodeGen.Tests/Export/ProtobufSerializationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,12 +716,12 @@ public void ListAllProtoContractTypes()
716716
"ExportDatabase", "ExportNamespace", "ExportNative", "ExportParameter",
717717
"ExportEnum", "ExportEnumMember", "ExportStruct", "ExportStructField",
718718
"ExportSharedExample", "ExportSharedExampleCode",
719-
"ExportTypeInfo", "ExportTypeEntry", "ExportCallout"
719+
"ExportTypeInfo", "ExportTypeEntry"
720720
};
721721

722722
var expectedEnums = new[]
723723
{
724-
"ParamFlags", "FieldFlags", "ExportTypeCategory", "CalloutType"
724+
"ParamFlags", "FieldFlags", "ExportTypeCategory"
725725
};
726726

727727
foreach (var expected in expectedClasses)

0 commit comments

Comments
 (0)