defmodule MyAgent do
use Agent, restart: :transient
# Generated on: use Agent
# def child_spec(opts) do
# %{id: MyAgent, start: {__MODULE__, :start_link, [opts]}, restart: :transient}
# end
def start_link(opts) do
Agent.start_link(fn -> %{} end, opts)
end
...
end
Notice the commented portion starting with "# Generated on: use Agent". The code generated by macro "use Agent" is neatly present as comments. Anyone can inspect the code and understand what is happening behind the scene.
Some details:
1) Widely used and straightforward macros like if, def, defmodule etc. are excluded. The focus should be on documenting only those macros, which are application specific (like use Ecto.Schema)
2) Whenever the command is run (let's call it "mix annotate"), it goes through source code directory (lib folder primarily) and recreates annotated code files (mixed with commented macro code) in a separate folder. It should not modify the existing source files.
3) Since macros usually take options, there can be a new option like "use Agent, annotate: true". This way only those macros are expanded which are explicitly marked for annotation.
4) Similarly there can be a module attribute like "@annotate true" or "@annotate false". This way individual modules can be explicitly marked for annotation.
thanks
miwee