diff options
author | Lukas Larsson <lukas@erlang.org> | 2020-03-26 08:18:02 +0100 |
---|---|---|
committer | Lukas Larsson <lukas@erlang.org> | 2020-04-17 10:28:27 +0200 |
commit | e95afef351f8bf2c49ea47c327bc7d0d8bbbba1f (patch) | |
tree | b0657e12332ef061cb0abcc8706e0059e828f72f /lib/erl_docgen | |
parent | 46a91942e042559607f71641f9a8cb1e8b1b85b1 (diff) | |
download | erlang-e95afef351f8bf2c49ea47c327bc7d0d8bbbba1f.tar.gz |
stdlib: Remove duplicate shell docs entries
Diffstat (limited to 'lib/erl_docgen')
-rw-r--r-- | lib/erl_docgen/src/docgen_xml_to_chunk.erl | 75 |
1 files changed, 56 insertions, 19 deletions
diff --git a/lib/erl_docgen/src/docgen_xml_to_chunk.erl b/lib/erl_docgen/src/docgen_xml_to_chunk.erl index c57ecac213..c895b3d522 100644 --- a/lib/erl_docgen/src/docgen_xml_to_chunk.erl +++ b/lib/erl_docgen/src/docgen_xml_to_chunk.erl @@ -525,30 +525,58 @@ func2func({func,Attr,Contents}) -> _ = VerifyNameList(NameList,fun([]) -> ok end), FAs = [TagsToFA(FAttr) || {name,FAttr,[]} <- NameList ], + SortedFAs = lists:usort(FAs), FAClauses = lists:usort([{TagsToFA(FAttr),proplists:get_value(clause_i,FAttr)} || {name,FAttr,[]} <- NameList ]), - Signature = [iolist_to_binary([F,"/",A]) || {F,A} <- FAs], - lists:map( - fun({F,A}) -> - Specs = [{func_to_atom(CF),list_to_integer(CA),C} - || {{CF,CA},C} <- FAClauses, - F =:= CF, A =:= CA], - {function,[{name,F},{arity,list_to_integer(A)}, - {signature,Signature}, - {meta,SinceMD#{ signature => Specs }}], - ContentsNoName} - end, lists:usort(FAs)); + + MakeFunc = fun({F,A}, MD, Doc) -> + Specs = [{func_to_atom(CF),list_to_integer(CA),C} + || {{CF,CA},C} <- FAClauses, + F =:= CF, A =:= CA], + {function,[{name,F},{arity,list_to_integer(A)}, + {signature,[iolist_to_binary([F,"/",A])]}, + {meta,MD#{ signature => Specs }}], + Doc} + end, + + Base = MakeFunc(hd(SortedFAs), SinceMD, ContentsNoName), + + {BaseF,BaseA} = hd(SortedFAs), + MD = SinceMD#{ equiv => {function,list_to_atom(BaseF),list_to_integer(BaseA)}}, + Equiv = lists:map( + fun(FA) -> + MakeFunc(FA, MD, []) + end, tl(SortedFAs)), + [Base | Equiv]; NameList -> %% Manual style function docs - FAs = lists:flatten([func_to_tuple(NameString) || {name, _Attr, NameString} <- NameList]), + FAs = lists:foldl( + fun({name,_,NameString}, Acc) -> + FAs = func_to_tuple(NameString), + lists:foldl( + fun(FA, FAAcc) -> + Slogan = maps:get(FA, FAAcc, []), + FAAcc#{ FA => [strip_tags(NameString)|Slogan] } + end, Acc, FAs) + end, #{}, NameList), _ = VerifyNameList(NameList,fun([_|_]) -> ok end), - Signature = [strip_tags(NameString) || {name, _Attr, NameString} <- NameList], - [{function,[{name,F},{arity,A}, - {signature,Signature}, - {meta,SinceMD}],ContentsNoName} - || {F,A} <- lists:usort(FAs)] + SortedFAs = lists:usort(maps:to_list(FAs)), + + {{BaseF, BaseA}, BaseSig} = hd(SortedFAs), + + Base = {function,[{name,BaseF},{arity,BaseA}, + {signature,BaseSig}, + {meta,SinceMD}], + ContentsNoName}, + + Equiv = [{function, + [{name,F},{arity,A}, + {signature,Signature}, + {meta,SinceMD#{ equiv => {function,list_to_atom(BaseF),BaseA}}}],[]} + || {{F,A},Signature} <- tl(SortedFAs)], + [Base | Equiv] end, transform(Functions,[]). @@ -691,6 +719,7 @@ docs_v1(DocContents, Anno, Metadata, Docs) -> docs = Docs }. docs_v1_entry(Kind, Anno, Name, Arity, Signature, Metadata, DocContents) -> + AnnoWLine = case Metadata of #{ signature := [Sig|_] } -> @@ -699,8 +728,16 @@ docs_v1_entry(Kind, Anno, Name, Arity, Signature, Metadata, DocContents) -> _NoSignature -> Anno end, - {{Kind, Name, Arity}, AnnoWLine, lists:flatten(Signature), - #{ <<"en">> => shell_docs:normalize(DocContents)}, Metadata}. + + Doc = + case DocContents of + [] -> + #{}; + DocContents -> + #{ <<"en">> => shell_docs:normalize(DocContents) } + end, + + {{Kind, Name, Arity}, AnnoWLine, lists:flatten(Signature), Doc, Metadata}. %% A special list_to_atom that handles %% 'and' |