Skip to content
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

Preserve spacing of toplevel comments #1554

Merged
merged 3 commits into from
Jan 5, 2021

Conversation

gpetiot
Copy link
Collaborator

@gpetiot gpetiot commented Nov 27, 2020

Motivation:

let _ = assert (foo (bar + baz <= quux))
(* this comment should stay attached to the preceding item *)

let _ = foo

was formatted as:

let _ = assert (foo (bar + baz <= quux))

(* this comment should stay attached to the preceding item *)

let _ = foo

because the comment was wrongfully attached to the second item instead of the first one.

edit: no diff with test_branch.sh after the unnecessary commits were dropped.

@gpetiot
Copy link
Collaborator Author

gpetiot commented Dec 9, 2020

Waiting for #1549

@gpetiot gpetiot marked this pull request as draft December 21, 2020 11:21
@gpetiot gpetiot force-pushed the simplify-comments-spacing branch 2 times, most recently from 730bc58 to 7531340 Compare December 22, 2020 18:18
@gpetiot gpetiot marked this pull request as ready for review December 22, 2020 19:35
Copy link
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

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

Looks good.

@@ -180,6 +180,8 @@ module Location = struct

let compare_end_col x y = Position.compare_col x.loc_end y.loc_end

let line_difference fst snd = snd.loc_start.pos_lnum - fst.loc_end.pos_lnum
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function doesn't make sense if fst is after (both start and end positions) snd. I think we should at least test assert (fst.loc_start.pos_lnum <= snd.loc_start.pos_lnum).
Also I'm not sure what this function means if snd is inside fst, we should probably assert that the result is >= 0 too.
Could you add some documentation about that ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree on the principle, but I've just discovered that this invariant doesn't hold anymore when comments have been relocated, so for now I've just added a docstring for this function and I will investigate more deeply this relocation issue in another PR. It doesn't look blocking for this PR as this is what was already done in master (the difference computation) anyway.

test/passing/module_attributes.ml.ref Show resolved Hide resolved
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.

3 participants