For example:
-module(foo).
-export([foo/0, bar/0]).
%% @doc I'm attached to a function :)
foo() -> foo.
%% @doc I'm not because of the line break :(
bar() -> bar.
Running:
1> {source, File} = proplists:lookup(source, foo:module_info(compile)).
{source,"/home/williamthome/Projects/williamthome/doctest/src/foo.erl"}
2> {ok, Forms} = epp:parse_file(File, [], []).
{ok,[{attribute,1,file,
{"/home/williamthome/Projects/williamthome/doctest/src/foo.erl",
1}},
{attribute,1,module,foo},
{attribute,2,export,[{foo,0},{bar,0}]},
{function,5,foo,0,[{clause,5,[],[],[{atom,5,foo}]}]},
{function,9,bar,0,[{clause,9,[],[],[{atom,9,bar}]}]},
{eof,10}]}
3> Comments = erl_comment_scan:file(File).
[{4,1,0,["% @doc I'm attached to a function :)"]},
{7,1,0,["% @doc I'm not because of the line break :("]}]
4> erl_syntax:form_list_elements(erl_syntax:flatten_form_list(
.. erl_recomment:recomment_forms(Forms, Comments))).
%% suppressed for clarify
{tree,function,
{attr,5,[],
{com,
[{tree,comment, % <- The comment is attached to the function
{attr,4,[],none},
{comment,0,["% @doc I'm attached to a function :)"]}}],
[]}},
{func,
{tree,atom,{attr,5,[],none},foo},
[{tree,clause,
{attr,5,[],none},
{clause,[],none,[{atom,5,foo}]}}]}},
{tree,comment, % <- The comment is not attached to the function
{attr,7,[],none},
{comment,0,["% @doc I'm not because of the line break :("]}},
{tree,function,
{attr,9,[],none},
{func,
{tree,atom,{attr,9,[],none},bar},
[{tree,clause,
{attr,9,[],none},
{clause,[],none,[{atom,9,bar}]}}]}},
{eof,10}]
As you can see, only the first @doc
is attached to the function.
Is there a function to attach comments to functions even if separated by line breaks? Or do I need to do it manually? Iβm not finding where EDoc resolves something like this (or if it does).
CC @garazdawi