wit-bindgen icon indicating copy to clipboard operation
wit-bindgen copied to clipboard

Attach doc-comments to a WIT file

Open Michael-F-Bryan opened this issue 3 years ago • 2 comments

At the moment, you can add doc-comments to any item in a WIT file and the text will appear in the generated code as doc-comments for your target language, however it doesn't look like you can document the WIT file itself.

The idea is that users could write the following guest.wit file:

//! Functionality exposed by the guest.

/// A function that is called when the WebAssembly module is loaded.
on-load: function()

(I'm borrowing the //! syntax from Rust but don't have any particular preference)

Generating import bindings with wit-bindgen wasmtime --import guest.wit might then look like this:

pub mod guest {
  //! Functionality exposed by the guest.

  pub struct Guest<T> { ... }

  impl<T> Guest<T> {
    /// A function that is called when the WebAssembly module is loaded.
    pub fn on_load(&self, ...)-> Result<(), wasmtime::Trap> { ... }
  }
}

Concretely, supporting doc-comments for the WIT file itself will probably involve:

  • Decide on a syntax (e.g. //! ... or /// ... with a newline separating it from the first item in the file)
  • Add a docs: Docs field to wit_parser::Interface and update the parser to populate it
  • Update each of the code generators to emit the appropriate doc-comments

Michael-F-Bryan avatar Apr 01 '22 21:04 Michael-F-Bryan