gjsify / ts-for-gir

TypeScript type definition generator for GObject introspection interfaces
https://gjsify.org/pages/projects
Apache License 2.0
233 stars 20 forks source link

Some fields are missing #180

Open JumpLink opened 1 month ago

JumpLink commented 1 month ago

@ewlsh for example on Gio.DBusNodeInfo, here are the GIR XML definitions:

<record name="DBusNodeInfo"
            c:type="GDBusNodeInfo"
            version="2.26"
            glib:type-name="GDBusNodeInfo"
            glib:get-type="g_dbus_node_info_get_type"
            c:symbol-prefix="dbus_node_info">
      <field name="ref_count" writable="1">
        <doc xml:space="preserve"
             filename="gio/gdbusintrospection.h"
             line="164">The reference count or -1 if statically allocated.</doc>
        <type name="gint" c:type="gint"/>
      </field>
      <field name="path" writable="1">
        <doc xml:space="preserve"
             filename="gio/gdbusintrospection.h"
             line="165">The path of the node or %NULL if omitted. Note that this may be a relative path. See the D-Bus specification for more details.</doc>
        <type name="utf8" c:type="gchar*"/>
      </field>
      <field name="interfaces" writable="1">
        <doc xml:space="preserve"
             filename="gio/gdbusintrospection.h"
             line="166">A pointer to a %NULL-terminated array of pointers to #GDBusInterfaceInfo structures or %NULL if there are no interfaces.</doc>
        <array c:type="GDBusInterfaceInfo**">
          <type name="DBusInterfaceInfo" c:type="GDBusInterfaceInfo*"/>
        </array>
      </field>
      <field name="nodes" writable="1">
        <doc xml:space="preserve"
             filename="gio/gdbusintrospection.h"
             line="167">A pointer to a %NULL-terminated array of pointers to #GDBusNodeInfo structures or %NULL if there are no nodes.</doc>
        <array c:type="GDBusNodeInfo**">
          <type name="DBusNodeInfo" c:type="GDBusNodeInfo*"/>
        </array>
      </field>
      <field name="annotations" writable="1">
        <doc xml:space="preserve"
             filename="gio/gdbusintrospection.h"
             line="168">A pointer to a %NULL-terminated array of pointers to #GDBusAnnotationInfo structures or %NULL if there are no annotations.</doc>
        <array c:type="GDBusAnnotationInfo**">
          <type name="DBusAnnotationInfo" c:type="GDBusAnnotationInfo*"/>
        </array>
      </field>
...

So the generated class fields should look like this:

export class DBusNodeInfo {
    ...
    ref_count: number;
    path: string;
    interfaces: DBusInterfaceInfo[];
    nodes: DBusNodeInfo[];
    annotations: DBusAnnotationInfo[];
...
}

But currently it is looking like this:

export class DBusNodeInfo {
    ...
    ref_count: number;
    path: string;
    annotations: DBusAnnotationInfo[];
...
}

The Structure members are also in the documentation.

JumpLink commented 1 month ago

@ewlsh Okay, looks like these fields will be removed by removeComplexFields because classNode.isSimple() is false, so its removed here:

            // Only allow fields pointing to simple structs.
            if (classNode && classNode instanceof IntrospectedRecord && !classNode.isSimple()) {
                return false;
            }

I have tried this https://github.com/gjsify/ts-for-gir/pull/184/commits/62f21741bb9cea8526aefb2ebd7940144af2598b this adds the missing fields but results in conflicts.

I don't understand why isSimple looks again in the target record to see if their fields are all simple:

const isSimple = this.fields.every(f => this.isSimpleType(f.type));`

Don't you remove the non-simple fields anyway?