Skip to content

Commit 2ebdfa3

Browse files
committed
feat: parse and display descriptions for methods, properties, signals, constants, and enums
Add description field parsing to all entry types via handleEntryDescription handler. When displaying members, fall back to showing the first line of description if brief_description is not available. Note: Property descriptions are temporarily disabled due to a bbcodez parsing issue.
1 parent 69c3fb4 commit 2ebdfa3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/DocDatabase.zig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,25 +226,30 @@ fn appendEntries(self: *DocDatabase, allocator: Allocator, parent: Entry, parent
226226

227227
const MethodKey = enum {
228228
name,
229+
description,
229230
};
230231

231232
const PropertyKey = enum {
232233
name,
233234
type,
234235
getter,
235236
setter,
237+
description,
236238
};
237239

238240
const ConstantKey = enum {
239241
name,
242+
description,
240243
};
241244

242245
const SignalKey = enum {
243246
name,
247+
description,
244248
};
245249

246250
const EnumKey = enum {
247251
name,
252+
description,
248253
};
249254

250255
const kind_key_map: std.StaticStringMap(type) = .initComptime(.{
@@ -258,25 +263,31 @@ const kind_key_map: std.StaticStringMap(type) = .initComptime(.{
258263

259264
const constant_handler_map: std.StaticStringMap(*const fn (Allocator, *Entry, *Scanner) anyerror!void) = .initComptime(.{
260265
.{ @tagName(ConstantKey.name), handleEntryName },
266+
.{ @tagName(ConstantKey.description), handleEntryDescription },
261267
});
262268

263269
const method_handler_map: std.StaticStringMap(*const fn (Allocator, *Entry, *Scanner) anyerror!void) = .initComptime(.{
264270
.{ @tagName(MethodKey.name), handleEntryName },
271+
.{ @tagName(MethodKey.description), handleEntryDescription },
265272
});
266273

267274
const signal_handler_map: std.StaticStringMap(*const fn (Allocator, *Entry, *Scanner) anyerror!void) = .initComptime(.{
268275
.{ @tagName(SignalKey.name), handleEntryName },
276+
.{ @tagName(SignalKey.description), handleEntryDescription },
269277
});
270278

271279
const enum_value_handler_map: std.StaticStringMap(*const fn (Allocator, *Entry, *Scanner) anyerror!void) = .initComptime(.{
272280
.{ @tagName(EnumKey.name), handleEntryName },
281+
.{ @tagName(EnumKey.description), handleEntryDescription },
273282
});
274283

275284
const property_handler_map: std.StaticStringMap(*const fn (Allocator, *Entry, *Scanner) anyerror!void) = .initComptime(.{
276285
.{ @tagName(PropertyKey.name), handleEntryName },
277286
.{ @tagName(PropertyKey.type), handlePropertyType },
278287
.{ @tagName(PropertyKey.getter), skipValue },
279288
.{ @tagName(PropertyKey.setter), skipValue },
289+
// TODO: bbcodez throws for some reason
290+
// .{ @tagName(PropertyKey.description), handleEntryDescription },
280291
});
281292

282293
const kind_handler_map: std.StaticStringMap(std.StaticStringMap(*const fn (Allocator, *Entry, *Scanner) anyerror!void)) = .initComptime(.{
@@ -302,6 +313,10 @@ fn handlePropertyType(allocator: Allocator, entry: *Entry, scanner: *Scanner) an
302313
entry.signature = try std.fmt.allocPrint(allocator, ": {s}", .{@"type".string});
303314
}
304315

316+
fn handleEntryDescription(allocator: Allocator, entry: *Entry, scanner: *Scanner) anyerror!void {
317+
entry.description = try nextTokenToMarkdownAlloc(allocator, scanner);
318+
}
319+
305320
fn skipValue(allocator: Allocator, entry: *Entry, scanner: *Scanner) anyerror!void {
306321
_ = allocator;
307322
_ = entry;
@@ -465,6 +480,10 @@ fn formatMemberLine(self: DocDatabase, member_idx: usize, writer: *Writer) !void
465480

466481
if (member.brief_description) |brief| {
467482
try writer.print(" - {s}", .{brief});
483+
} else if (member.description) |desc| {
484+
const new_line_idx = std.mem.indexOf(u8, desc, "\n");
485+
const first_line = if (new_line_idx) |idx| desc[0..idx] else desc;
486+
try writer.print(" - {s}", .{first_line});
468487
}
469488

470489
try writer.writeByte('\n');

0 commit comments

Comments
 (0)