Skip to content

Commit

Permalink
Remove unwanted or duplicate doc in expansions
Browse files Browse the repository at this point in the history
A module's `doc` field was propagated through expansions by synthetizing
a comment at the top of the expanded signature. It's now propagated via
the `doc` field of the signature.

In the case where the module has a comment and the signature has a
top-comment, the module's comment is not propagated.

This fixes doc appearing multiple time when the signature is expanded
mutliple time (eg. due to an include-module-type-of) and doc appearing
when they shouldn't (eg. in a non-inline include).
This also moves the preambles into the right section in the generated
HTML.
  • Loading branch information
Julow committed May 23, 2024
1 parent f88bd64 commit 6c1d39d
Show file tree
Hide file tree
Showing 25 changed files with 81 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/xref2/tools.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ and expansion_of_module_path :
let sg' =
match m.doc with
| [] -> sg
| docs -> { sg with items = Comment (`Docs docs) :: sg.items }
| doc -> { sg with doc }
in
if strengthen then
Ok (Signature (Strengthen.signature (`Resolved p') sg'))
Expand Down
1 change: 0 additions & 1 deletion test/generators/html/Include2.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ <h1>Module <code><span>Include2</span></code></h1>
</span>
</code>
</summary>
<p>Comment about X that should not appear when including X below.</p>
<div class="odoc-spec">
<div class="spec type anchored" id="type-t">
<a href="#type-t" class="anchor"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
</nav>
<header class="odoc-preamble">
<h1>Parameter <code><span>FunctorTypeOf.Collection</span></code></h1>
<p>This comment is for <code>CollectionModule</code>.</p>
</header>
<div class="odoc-content">
<p>This comment is for <code>CollectionModule</code>.</p>
<div class="odoc-spec">
<div class="spec type anchored" id="type-collection">
<a href="#type-collection" class="anchor"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
</nav>
<header class="odoc-preamble">
<h1>Parameter <code><span>Recollection.C</span></code></h1>
<p>This comment is for <code>CollectionModule</code>.</p>
</header>
<div class="odoc-content">
<p>This comment is for <code>CollectionModule</code>.</p>
<div class="odoc-spec">
<div class="spec type anchored" id="type-collection">
<a href="#type-collection" class="anchor"></a>
Expand Down
2 changes: 1 addition & 1 deletion test/generators/html/Ocamlary-Recollection.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>Ocamlary.Recollection</span></code></h1>
<p>This comment is for <code>CollectionModule</code>.</p>
</header>
<nav class="odoc-toc">
<ul><li><a href="#parameters">Parameters</a></li>
Expand All @@ -33,7 +34,6 @@ <h2 id="parameters"><a href="#parameters" class="anchor"></a>Parameters
</div>
</div>
<h2 id="signature"><a href="#signature" class="anchor"></a>Signature</h2>
<p>This comment is for <code>CollectionModule</code>.</p>
<div class="odoc-spec">
<div class="spec type anchored" id="type-collection">
<a href="#type-collection" class="anchor"></a>
Expand Down
2 changes: 1 addition & 1 deletion test/generators/html/Ocamlary-module-type-A-Q.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<a href="Ocamlary-module-type-A.html">A</a> &#x00BB; Q
</nav>
<header class="odoc-preamble"><h1>Module <code><span>A.Q</span></code></h1>
<p>This comment is for <code>CollectionModule</code>.</p>
</header>
<div class="odoc-content">
<p>This comment is for <code>CollectionModule</code>.</p>
<div class="odoc-spec">
<div class="spec type anchored" id="type-collection">
<a href="#type-collection" class="anchor"></a>
Expand Down
3 changes: 3 additions & 0 deletions test/generators/html/Ocamlary-module-type-A.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ <h1>Module type <code><span>Ocamlary.A</span></code></h1>
</span>
</code>
</div>
<div class="spec-doc">
<p>This comment is for <code>CollectionModule</code>.</p>
</div>
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion test/generators/html/Ocamlary-module-type-B-Q.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<a href="Ocamlary-module-type-B.html">B</a> &#x00BB; Q
</nav>
<header class="odoc-preamble"><h1>Module <code><span>B.Q</span></code></h1>
<p>This comment is for <code>CollectionModule</code>.</p>
</header>
<div class="odoc-content">
<p>This comment is for <code>CollectionModule</code>.</p>
<div class="odoc-spec">
<div class="spec type anchored" id="type-collection">
<a href="#type-collection" class="anchor"></a>
Expand Down
3 changes: 3 additions & 0 deletions test/generators/html/Ocamlary-module-type-B.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ <h1>Module type <code><span>Ocamlary.B</span></code></h1>
</span>
</code>
</div>
<div class="spec-doc">
<p>This comment is for <code>CollectionModule</code>.</p>
</div>
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion test/generators/html/Ocamlary-module-type-C-Q.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<a href="Ocamlary-module-type-C.html">C</a> &#x00BB; Q
</nav>
<header class="odoc-preamble"><h1>Module <code><span>C.Q</span></code></h1>
<p>This comment is for <code>CollectionModule</code>.</p>
</header>
<div class="odoc-content">
<p>This comment is for <code>CollectionModule</code>.</p>
<div class="odoc-spec">
<div class="spec type anchored" id="type-collection">
<a href="#type-collection" class="anchor"></a>
Expand Down
3 changes: 3 additions & 0 deletions test/generators/html/Ocamlary-module-type-C.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ <h1>Module type <code><span>Ocamlary.C</span></code></h1>
</span>
</code>
</div>
<div class="spec-doc">
<p>This comment is for <code>CollectionModule</code>.</p>
</div>
</div>
</details>
</div>
Expand Down
2 changes: 1 addition & 1 deletion test/generators/html/Ocamlary-module-type-COLLECTION.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<header class="odoc-preamble">
<h1>Module type <code><span>Ocamlary.COLLECTION</span></code></h1>
<p>module type of</p>
<p>This comment is for <code>CollectionModule</code>.</p>
</header>
<div class="odoc-content">
<p>This comment is for <code>CollectionModule</code>.</p>
<div class="odoc-spec">
<div class="spec type anchored" id="type-collection">
<a href="#type-collection" class="anchor"></a>
Expand Down
2 changes: 1 addition & 1 deletion test/generators/html/Ocamlary-module-type-MMM-C.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
</nav>
<header class="odoc-preamble">
<h1>Module <code><span>MMM.C</span></code></h1>
<p>This comment is for <code>CollectionModule</code>.</p>
</header>
<div class="odoc-content">
<p>This comment is for <code>CollectionModule</code>.</p>
<div class="odoc-spec">
<div class="spec type anchored" id="type-collection">
<a href="#type-collection" class="anchor"></a>
Expand Down
3 changes: 3 additions & 0 deletions test/generators/html/Ocamlary-module-type-MMM.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ <h1>Module type <code><span>Ocamlary.MMM</span></code></h1>
</span>
</code>
</div>
<div class="spec-doc">
<p>This comment is for <code>CollectionModule</code>.</p>
</div>
</div>
</div>
</body>
Expand Down
3 changes: 3 additions & 0 deletions test/generators/html/Ocamlary.html
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,9 @@ <h4 id="advanced-module-stuff">
</span>
</code>
</div>
<div class="spec-doc">
<p>This comment is for <code>CollectionModule</code>.</p>
</div>
</div>
<div class="odoc-spec">
<div class="spec module-type anchored" id="module-type-MMM">
Expand Down
4 changes: 1 addition & 3 deletions test/generators/latex/Include2.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ \section{Module \ocamlinlinecode{Include2}}\label{module-Include2}%
\end{ocamlindent}%
\ocamlcodefragment{\ocamltag{keyword}{end}}\begin{ocamlindent}Comment about X that should not appear when including X below.\end{ocamlindent}%
\medbreak
\ocamltag{keyword}{include} \ocamltag{keyword}{module} \ocamltag{keyword}{type} \ocamltag{keyword}{of} \ocamltag{keyword}{struct} \ocamltag{keyword}{include} \hyperref[module-Include2-module-X]{\ocamlinlinecode{X}} \ocamltag{keyword}{end}Comment about X that should not appear when including X below.

\label{module-Include2-type-t}\ocamlcodefragment{\ocamltag{keyword}{type} t = int}\\
\ocamltag{keyword}{include} \ocamltag{keyword}{module} \ocamltag{keyword}{type} \ocamltag{keyword}{of} \ocamltag{keyword}{struct} \ocamltag{keyword}{include} \hyperref[module-Include2-module-X]{\ocamlinlinecode{X}} \ocamltag{keyword}{end}\label{module-Include2-type-t}\ocamlcodefragment{\ocamltag{keyword}{type} t = int}\\
\label{module-Include2-module-Y}\ocamlcodefragment{\ocamltag{keyword}{module} \hyperref[module-Include2-module-Y]{\ocamlinlinecode{Y}}}\ocamlcodefragment{ : \ocamltag{keyword}{sig}}\begin{ocamlindent}\label{module-Include2-module-Y-type-t}\ocamlcodefragment{\ocamltag{keyword}{type} t}\\
\end{ocamlindent}%
\ocamlcodefragment{\ocamltag{keyword}{end}}\begin{ocamlindent}Top-comment of Y.\end{ocamlindent}%
Expand Down
4 changes: 1 addition & 3 deletions test/generators/latex/Ocamlary.FunctorTypeOf.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ \section{Module \ocamlinlinecode{Ocamlary.\allowbreak{}FunctorTypeOf}}\label{mod
This comment is for \ocamlinlinecode{FunctorTypeOf}.

\subsection{Parameters\label{parameters}}%
\label{module-Ocamlary-module-FunctorTypeOf-argument-1-Collection}\ocamlcodefragment{\ocamltag{keyword}{module} \hyperref[module-Ocamlary-module-FunctorTypeOf-argument-1-Collection]{\ocamlinlinecode{Collection}}}\ocamlcodefragment{ : \ocamltag{keyword}{sig}}\begin{ocamlindent}This comment is for \ocamlinlinecode{CollectionModule}.

\label{module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-type-collection}\ocamlcodefragment{\ocamltag{keyword}{type} collection}\begin{ocamlindent}This comment is for \ocamlinlinecode{collection}.\end{ocamlindent}%
\label{module-Ocamlary-module-FunctorTypeOf-argument-1-Collection}\ocamlcodefragment{\ocamltag{keyword}{module} \hyperref[module-Ocamlary-module-FunctorTypeOf-argument-1-Collection]{\ocamlinlinecode{Collection}}}\ocamlcodefragment{ : \ocamltag{keyword}{sig}}\begin{ocamlindent}\label{module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-type-collection}\ocamlcodefragment{\ocamltag{keyword}{type} collection}\begin{ocamlindent}This comment is for \ocamlinlinecode{collection}.\end{ocamlindent}%
\medbreak
\label{module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-type-element}\ocamlcodefragment{\ocamltag{keyword}{type} element}\\
\label{module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-module-InnerModuleA}\ocamlcodefragment{\ocamltag{keyword}{module} \hyperref[module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-module-InnerModuleA]{\ocamlinlinecode{InnerModuleA}}}\ocamlcodefragment{ : \ocamltag{keyword}{sig}}\begin{ocamlindent}\label{module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-module-InnerModuleA-type-t}\ocamlcodefragment{\ocamltag{keyword}{type} t = \hyperref[module-Ocamlary-module-FunctorTypeOf-argument-1-Collection-type-collection]{\ocamlinlinecode{collection}}}\begin{ocamlindent}This comment is for \ocamlinlinecode{t}.\end{ocamlindent}%
Expand Down
8 changes: 3 additions & 5 deletions test/generators/latex/Ocamlary.Recollection.tex
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
\section{Module \ocamlinlinecode{Ocamlary.\allowbreak{}Recollection}}\label{module-Ocamlary-module-Recollection}%
\subsection{Parameters\label{parameters}}%
\label{module-Ocamlary-module-Recollection-argument-1-C}\ocamlcodefragment{\ocamltag{keyword}{module} \hyperref[module-Ocamlary-module-Recollection-argument-1-C]{\ocamlinlinecode{C}}}\ocamlcodefragment{ : \ocamltag{keyword}{sig}}\begin{ocamlindent}This comment is for \ocamlinlinecode{CollectionModule}.
This comment is for \ocamlinlinecode{CollectionModule}.

\label{module-Ocamlary-module-Recollection-argument-1-C-type-collection}\ocamlcodefragment{\ocamltag{keyword}{type} collection}\begin{ocamlindent}This comment is for \ocamlinlinecode{collection}.\end{ocamlindent}%
\subsection{Parameters\label{parameters}}%
\label{module-Ocamlary-module-Recollection-argument-1-C}\ocamlcodefragment{\ocamltag{keyword}{module} \hyperref[module-Ocamlary-module-Recollection-argument-1-C]{\ocamlinlinecode{C}}}\ocamlcodefragment{ : \ocamltag{keyword}{sig}}\begin{ocamlindent}\label{module-Ocamlary-module-Recollection-argument-1-C-type-collection}\ocamlcodefragment{\ocamltag{keyword}{type} collection}\begin{ocamlindent}This comment is for \ocamlinlinecode{collection}.\end{ocamlindent}%
\medbreak
\label{module-Ocamlary-module-Recollection-argument-1-C-type-element}\ocamlcodefragment{\ocamltag{keyword}{type} element}\\
\label{module-Ocamlary-module-Recollection-argument-1-C-module-InnerModuleA}\ocamlcodefragment{\ocamltag{keyword}{module} \hyperref[module-Ocamlary-module-Recollection-argument-1-C-module-InnerModuleA]{\ocamlinlinecode{InnerModuleA}}}\ocamlcodefragment{ : \ocamltag{keyword}{sig}}\begin{ocamlindent}\label{module-Ocamlary-module-Recollection-argument-1-C-module-InnerModuleA-type-t}\ocamlcodefragment{\ocamltag{keyword}{type} t = \hyperref[module-Ocamlary-module-Recollection-argument-1-C-type-collection]{\ocamlinlinecode{collection}}}\begin{ocamlindent}This comment is for \ocamlinlinecode{t}.\end{ocamlindent}%
Expand All @@ -25,8 +25,6 @@ \subsection{Parameters\label{parameters}}%
\end{ocamlindent}%
\ocamlcodefragment{\ocamltag{keyword}{end}}\\
\subsection{Signature\label{signature}}%
This comment is for \ocamlinlinecode{CollectionModule}.

\label{module-Ocamlary-module-Recollection-type-collection}\ocamlcodefragment{\ocamltag{keyword}{type} collection = \hyperref[module-Ocamlary-module-Recollection-argument-1-C-type-element]{\ocamlinlinecode{C.\allowbreak{}element}} list}\begin{ocamlindent}This comment is for \ocamlinlinecode{collection}.\end{ocamlindent}%
\medbreak
\label{module-Ocamlary-module-Recollection-type-element}\ocamlcodefragment{\ocamltag{keyword}{type} element = \hyperref[module-Ocamlary-module-Recollection-argument-1-C-type-collection]{\ocamlinlinecode{C.\allowbreak{}collection}}}\\
Expand Down
Loading

0 comments on commit 6c1d39d

Please sign in to comment.