Skip to content

Commit bfd7db1

Browse files
nadakoSimn
authored andcommitted
[macro] add haxe.macro.Expr.TypeDefinition.doc field and support printing it with haxe.macro.Printer (#6401)
1 parent 97edae2 commit bfd7db1

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/macro/macroApi.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,10 +1369,11 @@ let decode_type_def v =
13691369
let pos = decode_pos (field v "pos") in
13701370
let isExtern = decode_opt_bool (field v "isExtern") in
13711371
let fields = List.map decode_field (decode_array (field v "fields")) in
1372+
let doc = opt decode_string (field v "doc") in
13721373
let mk fl dl =
13731374
{
13741375
d_name = name;
1375-
d_doc = None;
1376+
d_doc = doc;
13761377
d_params = decode_tparams (field v "params");
13771378
d_meta = meta;
13781379
d_flags = fl;

std/haxe/macro/Expr.hx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,12 @@ typedef TypeDefinition = {
808808
**/
809809
var name : String;
810810

811+
/**
812+
The documentation of the type, if available. If the type has no
813+
documentation, the value is `null`.
814+
**/
815+
@:optional var doc : Null<String>;
816+
811817
/**
812818
The position to the type definition.
813819
**/

std/haxe/macro/Printer.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ class Printer {
251251

252252
var str = t == null ? "#NULL" :
253253
(printPackage && t.pack.length > 0 && t.pack[0] != "" ? "package " + t.pack.join(".") + ";\n" : "") +
254+
(t.doc != null && t.doc != "" ? "/**\n" + tabString + StringTools.replace(t.doc, "\n", "\n" + tabString) + "\n**/\n" : "") +
254255
(t.meta != null && t.meta.length > 0 ? t.meta.map(printMetadata).join(" ") + " " : "") + (t.isExtern ? "extern " : "") + switch (t.kind) {
255256
case TDEnum:
256257
"enum " + t.name + ((t.params != null && t.params.length > 0) ? "<" + t.params.map(printTypeParamDecl).join(", ") + ">" : "") + " {\n"

0 commit comments

Comments
 (0)