Proposal: Struct field documentation

31 views
Skip to first unread message

Mitchell Hanberg

unread,
Oct 18, 2023, 9:58:02 PM10/18/23
to elixir-lang-core
Hi!

I have no idea if this is really even possible, or what the syntax could be, but I am curious to hear the reception to the proposal of having documentation for Struct fields.

You can already add an `@doc` attribute to `defstruct`.

This curiosity somewhat stems from being able to show docs for struct fields when providing completion candidates for intellisense programs like an LSP server.

The current struct syntax does not seem to lend itself well to something like this, but if this proposal sounds any bit interesting, I'm sure we could think of something.

Also, if you can already do this and I somehow missed it after 5 years of being in this community, please correct me 😅

- Mitch

PS. Having already typed this, it could be possible maybe if the `@doc` attribute could be shaped like

```elixir
@doc struct: "i'm a stuct",
            fields: [
              foo: "I'm the foo field!",
              bar: "I'm the bar field!"
           ]
defstruct foo: nil, bar: nil
```

Wojtek Mach

unread,
Oct 19, 2023, 1:59:19 AM10/19/23
to elixir-l...@googlegroups.com
> PS. Having already typed this, it could be possible maybe if the `@doc` attribute could be shaped like

`@doc x: 1, y: 2` already works and so does `@moduledoc …`. The data is written into metadata section of the docs chunk. If you support this in Next LS and tell users it’s possible, it will totally work today. However it would be best if this metadata name and shape is standardised, something I’m definitely in favour of, and used by ExDoc and similar tools too.

Similarly I’d love to see something like this:

    @doc options: [
      foo: “the foo option”,
      bar: “the bar option”,      
    ]
    def f(options)




--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/f5a7fc37-865c-4c92-b8c9-485f46183700n%40googlegroups.com.

José Valim

unread,
Oct 19, 2023, 4:09:02 AM10/19/23
to elixir-l...@googlegroups.com
Our goal is to revisit this relatively soon. If the type system work succeeds, we will introduce a new syntax for defining structs and we will make documentation a core part of field names.

Reply all
Reply to author
Forward
0 new messages