-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Take expansion's doc when computing a declaration's synopsis #643
Conversation
@@ -1533,7 +1537,7 @@ module Make (Syntax : SYNTAX) = struct | |||
let content = { Include.content; status; summary } in | |||
let attr = [ "include" ] in | |||
let anchor = None in | |||
let doc = Comment.first_to_ir sg_doc in | |||
let doc = Comment.synopsis ~decl_doc:[] ~expansion_doc:(Some sg_doc) in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR:
This ignores t.doc
and takes only the first paragraph of the expansion doc, the rest is removed. I think we should at least show t.doc
in its entirety.
I'll propose something is an other PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue: #645
Could you please spell them out ? Because I'm not sure what you mean by skipping. More precisely, nothing should be skipped. You simply take the first paragraph of the comment attached to module. If there is no such thing there is no synopsis. Do not try to peek past headings this will create a lot of bogus synopses. For example here there should be no synopsis:
|
Here are examples of bogus synopses. |
If we agree on the current state of discussion between me and @lpw25 in #640 I would suggest the following definitions:
This not exactly what |
The temporary rule is: The synopsis is the first paragraph, from top to bottom, ignoring headings and tags but considering list items. I agree it is surprising and produces bogus synopses. That's why I warned about it.
I think you actually suggest: the first element of the preamble, if it is a paragraph. (I guess also if it is a list and the first item has a paragraph as first element) I suggest adding to this rule: Heading's text if the first element is a heading. |
I don't think it's a good idea.
Yes. Note that the simple new rule I propose will not produce bogus synopses (except for those that relied on the ill-defined sentence extract). It will however suppress some, namely those who relied on synopses being extracted from headings, like those I suspect.
I'd rather not because then it all becomes confusing. The heading is not part of the preamble so we loose the simple and obvious definitions. Besides it also makes the purpose of headings shady. Headings are here to chunk the module contents. I do not like to overload or change their functionality when they happen to appear at the beginning of a module. Finally a synopsis is supposed to be a small sentence terminated by a dot. Headings are not supposed to be terminated by a dot.
I'm not sure it's common. In any case in general you should rather start with a preamble. There's already a heading starting the page which is The pattern supported by the rules I propose has been well-established by the stdlib for as long as I have been programming in OCaml and as I mentioned here corresponds to what you'll find most of the time out there. |
One thing I forgot to mention is that by having less ways on how synopses are defined we enforce more page structure regularity across APIs which overall improves the OCaml documentation user experience. |
I changed the rule according to our discussion. |
I'm not sure why you made that exception, is there any documentation pattern you have in mind ? Lists are usually cohesive blocks, extracting out the first paragraph of their first element seems a bit weird. |
Lists contain paragraphs. I don't have a strong reason, that's how I'd expect it to work. Ocamldoc was taking the first sentence of anything (heading, paragraph, verbatim block), taking more seems more consistent than otherwise. |
Ah ! I don't :-) Especially from a writing perspective I don't see the first paragraph of the first element of a list as being a particularly self-contained and self-identified unit. I'd rather see that as a bug. Beyond that writing the documentation features, i.e. explaining features for humans, is always useful to judge them (if you can't explain it simply, iterate…) – I did my best to write something for what you propose, maybe you can make it simpler but I still prefer the first definition.
|
Rebase needed please! |
Also this still implements definition 2. the docs of #644 use definition 1. |
Does anyone have an opinion on this? (whether we should use the first item of a list if it is the first element) |
I think I'm with @dbuenzli on this one, I wouldn't have expected to pick out the first item in a list. |
Allow sharing this function with the generator.
Before this patch, no synopsis was attached to declarations like this: ``` module M : sig (** Expansion doc. *) end ```
The synopsis is now the first element of the preamble, if it is a paragraph. An exception is made if it is a list, the first element of the first list item is considered. The preamble is the comment attached to the definition followed by the first comment of the expansion, up to the first heading.
The previous code was using the expansion doc even if the decl doc wasn't empty and didn't contain a synopsis. This doesn't work with the definition of synopsis in term of preamble.
9cab356
to
0292ffe
Compare
I've removed the exception on lists. I've also fixed a bug where the synopsis could be computed for the expansion doc even if the decl doc was present but didn't contain a synopsis. |
AIUI this is now ready to merge, correct? |
I believe it is. |
Fixes #632
Before this patch, no synopsis was attached to declarations like this: (also work on classes, class types and module types)
This is consistent with what ocamldoc does.
The first commit refactors the function generating the synopsis for
{!modules:}
lists so it can be shared with the generator. Before that, a simpler rule was used that didn't skip headings and other elements:(** - This is the synopsis. *)
These are rules I made up in #597, it's still time to change them and to document them too.