Proposal: __traits(getComment, symbol)

Manu turkeyman at gmail.com
Wed Aug 28 17:35:56 UTC 2019


On Wed, Aug 28, 2019 at 1:55 AM FeepingCreature via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> I propose a way to get the comment on a symbol at compile time. I
> believe this was already rejected, though I don't know why; I'd
> expect it to be something like "code should not change behavior
> due to a comment." I think that now that we have user-defined
> annotations there is a much lower risk of that.
>
> Why do I want this? Generating special documentation/annotated
> interfaces from D code is a *lot* easier if you can get the
> compiler to do your introspection work for you. I want to
> generate Swagger files documenting our REST services, and I want
> to use D comments to document them. Right now, I will have to do
> a weird hybrid dance where I generate the D type graph on the D
> side with compiletime introspection, output it to a file,
> simultaneously generate the Ddoc JSON file with -D -X to fish out
> the comments, then fuse the two together. There is no need for
> this, but for the absence of __traits(getComment).

I was really interested in this feature back when it was rejected the
first time.
My use is in video games, we create high-level gameplay code which
plugs itself into the editor environment.
This code publishes properties and the things that it can do from an
editor perspective, and in the editor, it is very nice to be able to
hover over values in property tables, and see the documentation for
the values in tooltips, which explains what the values are and how
they work.
We can do this with UDA's, but it's more natural to write documenting
comments with documenting comments.
In most cases, values have a UDA with this text, which contains a
string which is a cut&paste from the comment immediately above, and
it's very easy to amend one and forget to amend the other, and they
fall out of sync.

As a development workflow feature, having compiler access to symbol
comments would be very useful in many cases.


More information about the Digitalmars-d mailing list