Skip to content

Keep documentation comments in structures with no other items (MPR#7701 cont.)#1693

Merged
gasche merged 4 commits intoocaml:trunkfrom
lpw25:fix-mpr7701
May 5, 2018
Merged

Keep documentation comments in structures with no other items (MPR#7701 cont.)#1693
gasche merged 4 commits intoocaml:trunkfrom
lpw25:fix-mpr7701

Conversation

@lpw25
Copy link
Copy Markdown
Contributor

@lpw25 lpw25 commented Apr 3, 2018

This stops us from dropping documentation comments in structures and signatures that have no other items in them. It also adds some more docstring tests and fixes some typos in the ocamldoc documentation.

This is a more complete fix than #1562, which only handled the case where the signature in question was an entire mli file.

(** The comment for variable x. *)
val mutable x : int

(** The commend for method m. *)
Copy link
Copy Markdown

@tarptaeya tarptaeya Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be comment, not commend

Copy link
Copy Markdown

@tarptaeya tarptaeya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo, please correct it

(** The comment for type my_record *)
type my_record = {
val foo : int ; (** Comment for field foo *)
val bar : string ; (** Comment for field bar *)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was grossly invalid. Is it possible that using one of the {caml_example} environments would have caught the mistake earlier? If applicable in this case, I would recommend using them as part of this PR -- if we fix, let's fix long-term. cc @Octachron who may be able to comment on applicability.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, the code example is a signature; this would require a small tweak to caml_tex2.ml to add an option to wrap code example inside a module type declaration.

module Manual :
sig
[@@@ocaml.text
" Special comments can be placed between elements and are kept\n by the OCamldoc tool, but are not associated to any element.\n @-tags in these comments are ignored."]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to use line breaks in the expect result here that is portable and correct, and increases readability of the test file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without changing how -dsource prints things, any such change would be undone when promoting the result of the test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, alternative question: is there a way for -dsource to print this in a nicer way? (This would be a separate PR.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that

"  foo
  bar"

is not portable due to \n vs. \r\n concerns,

"  foo\n\
  bar"

does not work as spaces at the beginning of the line are ignored, but that one could use

"  foo\n  \
   bar"

pushing indentation of a line on the previous line.

Copy link
Copy Markdown
Member

@Octachron Octachron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core changes implement the right fixes. I have some minor existential interrogations on the docstring test but nothing that really matters.


module M = struct

(** foo1 *)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to capture the warning 50 raised by those unattached documentation comments, but this would require patching expect_text.ml . However, it could be nice to explicit this point here
(** foo1: this comment is unattached*) .

" The comment for type my_record "]
class my_class =
object
inherit cl[@@ocaml.doc
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it makes sense to permute the definition of my_class and my_class_type and inherit my_class_type here? After fixing the type of the method m, it would avoid the unbound class error later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you can inherit from a class type there.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right of course, I was thinking of the signature part.

|}]

(***********************************************************************)
(* Empty doc comments (GPR#548) *)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By pure curiousity, is there a reason beyond personal preference for having a single file with multiple parts rather than multiple files? And with a single file, would it not be better to merge the docstrings folder with the parsetree one, in order to reduce the number of tests folder in the test suite?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing beyond personal preference. I tend to like single test files that act as a form of documentation for how a particular feature behaves. Since I wanted to switch the "empty" tests to use a -dsource expect test anyway, I figured I might as well put them with the others.

And with a single file, would it not be better to merge the docstrings folder with the parsetree one, in order to reduce the number of tests folder in the test suite?

Yeah, that's probably a good idea.


type s
(** bar1 *)
(** bar2 *)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above: (** bar2: this comment is unattached *)?

@lpw25
Copy link
Copy Markdown
Contributor Author

lpw25 commented Apr 6, 2018

Ok I moved the docstring tests into docstring.ml in tests/parsing -- which already existed and had yet another docstring test. I've also updated the comments as suggested. I haven't fixed the example code to type-check because it's not needed and I would prefer to keep the code close to the example in the ocamldoc manual.

@trefis
Copy link
Copy Markdown
Contributor

trefis commented Apr 26, 2018

@Octachron : assuming a Changes entry was added, are you now satisfied with the state of this PR and can it be merged?

Also, I'm wondering if this bugfix could/should be backport to the 4.07 branch. Any opinion?

@Octachron
Copy link
Copy Markdown
Member

Yes, I am totally satisfied with the current state. Sorry for not being explicit. Backporting seems fine but not urgent to me since there is a workaround for the issue.

@pmetzger
Copy link
Copy Markdown
Member

A pure side comment. It would be nice for people reading the pull requests if the title of something like this was:

Fix MPR#7701: "Doc comment dropped from empty .mli file"

which make it easy for a casual reader to remember if is was a Mantis issue they are following.

@dra27 dra27 changed the title Fix MPR#7701 Keep documentation comments in structures with no other items (MPR#7701 cont.) Apr 26, 2018
@gasche gasche merged commit eb62d2e into ocaml:trunk May 5, 2018
gasche added a commit that referenced this pull request May 5, 2018
Keep documentation comments in structures with no other items (MPR#7701 cont.)

(cherry picked from commit eb62d2e)
gasche added a commit that referenced this pull request May 5, 2018
gasche added a commit that referenced this pull request May 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants