https://toitlang.org/ logo
IDE hinting enums, documentation etc
# help
a
As far as I can see, there is not enum support in toit. I have a function like this, there for example the
sound-type
field is actually an enum Whats the best way to document that fact? And or is there already IDE integreation and hinting for such as thing?
Copy code
/**
  Creates a protocol.Data object with all available fields for this message type.
  
  This is a comprehensive helper that accepts all possible fields.
  For method-specific usage, consider using the dedicated request/response methods.
  
  Returns: A protocol.Data object with the specified field values
  */
  static data --duration/int?=null --sound-type/int?=null --intensity/int?=null --run-count/int?=null --frequency/float?=null --base-data/protocol.Data?=protocol.Data -> protocol.Data:
    data := base-data
    if duration != null: data.add-data-uint DURATION duration
    if sound-type != null: data.add-data-uint SOUND-TYPE sound-type
    if intensity != null: data.add-data-uint INTENSITY intensity
    if run-count != null: data.add-data-uint RUN-COUNT run-count
    if frequency != null: data.add-data-float FREQUENCY frequency
    return data
f
At the moment the best you can do is point to the constants in the documentation. See, for example, https://libs.toit.io/esp32/espnow/class-Service#station(3%2C0%2C0%2Cchannel%2Ckey%2Crate) or https://libs.toit.io/esp32/espnow/class-Service#add-peer(4%2C0%2C0%2Ckey%2Cmode%2Crate) Eventually, we would like to add proper enum support.
Nitpicking:
Returns:
should be
Returns ...
(without any ":"), and it doesn't finish with a dot. The
protocol.Data
should probably just be
an object
since the actual type is given in the return type, or, if you keep the type it should be
$protocol.Data
. Same for the
Creates ...
.
a
real enums at some point would be nice 🙂