# Attach comments to ppx generated code?

**URL:** https://discuss.ocaml.org/t/attach-comments-to-ppx-generated-code/11264
**Category:** Learning
**Tags:** ppx
**Created:** [January 27, 2023, 3:01pm UTC](https://discuss.ocaml.org/t/attach-comments-to-ppx-generated-code/11264 "2023-01-27T15:01:09Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![enetsee](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/enetsee/32/1041_2.png) [@enetsee](https://discuss.ocaml.org/u/enetsee)
#### Post date: [January 27, 2023, 3:01pm UTC](https://discuss.ocaml.org/t/attach-comments-to-ppx-generated-code/11264/1 "2023-01-27T15:01:09Z")

</div>

Is it possible to attach comments to code generated by a ppx?

I’d like to include a comment on types produced by my preprocessor (which will show up when hovering in VSCode) directing users towards the ppx documentation . I realise that comments are not part of the AST but wondered if there was a workaround

Thanks,

Michael

---

<div class="post-metadata">

### Author: ![octachron](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@octachron](https://discuss.ocaml.org/u/octachron)
#### Post date: [January 27, 2023, 3:04pm UTC](https://discuss.ocaml.org/t/attach-comments-to-ppx-generated-code/11264/2 "2023-01-27T15:04:10Z")

</div>

You could attach documentation comments which are parts of the ASTs (and can be seen by documentation tools).

---

<div class="post-metadata">

### Author: ![enetsee](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/enetsee/32/1041_2.png) [@enetsee](https://discuss.ocaml.org/u/enetsee)
#### Post date: [January 27, 2023, 3:06pm UTC](https://discuss.ocaml.org/t/attach-comments-to-ppx-generated-code/11264/3 "2023-01-27T15:06:32Z")

</div>

Ah, is this `[@@ocaml.doc ...]`? I hadn’t realised comments were converted to attributes in this way

---

<div class="post-metadata">

### Author: ![emillon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/emillon/32/1206_2.png) [@emillon](https://discuss.ocaml.org/u/emillon)
#### Post date: [January 27, 2023, 4:10pm UTC](https://discuss.ocaml.org/t/attach-comments-to-ppx-generated-code/11264/4 "2023-01-27T16:10:15Z")

</div>

Yes, they’re attributes with a `ocaml.doc` name. This is the equivalent of doc-comments `(**... *)`. Normal comments `(* ... *)` are not part of the AST.
