================
@@ -0,0 +1,106 @@
+import argparse
+from typing import TypedDict, Union, Optional, TextIO, NotRequired
+from dataclasses import dataclass
+import json
+
+
+class Property(TypedDict):
+    name: str
+    type: str
+    default: NotRequired[str]
+    description: NotRequired[str]
+
+
+class PropertyGroup(TypedDict):
+    path: str
+    """The full path to this group separated by dots"""
+    properties: list[Property]
+
+
+@dataclass
+class PropertyTree:
+    items: dict[str, Union["PropertyTree", Property]]
+
+
+def append_group(tree: PropertyTree, group: PropertyGroup):
+    segments = group["path"].split(".") if group["path"] else []
+
+    subtree = tree
+    for segment in segments:
+        if segment not in subtree.items:
+            subtree.items[segment] = PropertyTree(items={})
+        subtree = subtree.items[segment]
+        assert isinstance(subtree, PropertyTree)
+
+    for property in group["properties"]:
+        subtree.items[property["name"]] = property
+
+
+def print_property(f: TextIO, path: str, property: Property):
+    f.write(f"```{{lldbsetting}} {path}\n")
+    f.write(f":type: \"{property['type']}\"\n\n")
+    f.write(property.get("description", "").strip())
+    f.write("\n\n")
+    if "default" in property and property["default"]:
+        f.write(f":default: {property['default']}\n")
+    # FIXME: add enumerations (":enum {name}: {description}")
+    f.write("```\n")
+
+
+def print_tree(f: TextIO, level: int, prefix: str, name: str, tree: 
PropertyTree):
+    if level > 0:
+        f.write(f"{'#' * (level + 2)} {name}\n\n")
+
+    leafs = sorted(
+        filter(lambda it: isinstance(it[1], dict), tree.items.items()),
+        key=lambda it: it[0],
+    )
+    for key, prop in leafs:
+        assert isinstance(prop, dict)  # only needed for typing
+        path = f"{prefix}.{key}" if prefix else key
+        print_property(f, path, prop)
+
+    groups = sorted(
+        filter(lambda it: isinstance(it[1], PropertyTree), tree.items.items()),
+        key=lambda it: it[0],
+    )
+    for key, subtree in groups:
+        assert isinstance(subtree, PropertyTree)  # only needed for typing
+        prefix = f"{name}.{key}" if name else key
+        print_tree(f, level + 1, prefix, key, subtree)
+
+
+HEADER = """
+# Settings
+
+This page lists all available settings in LLDB.
----------------
DavidSpickett wrote:

I think it's right that we display all possible settings. We could add a bit of 
a disclaimer for potential confusion.

How about:
This page lists all possible settings in LLDB. Some settings only exist for 
particular LLDB build configurations and so will not be present in all copies 
of LLDB.

You could make the second part a note box if it's convenient to do so. Maybe we 
can add some "requires X" but don't this is such a massive improvement as is so 
don't think about that now.

https://github.com/llvm/llvm-project/pull/168245
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to