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
formatter margins and color handling: revert #244 #9197
Conversation
987a198
to
08e84ea
Compare
08e84ea
to
292b6cf
Compare
Could you perhaps say a bit more about the story behind the present PR? FWIW doing what you propose looks good to me, just by following local reviewing heuristics (indeed, updating only std_formatter, and doing that in the color handling code does seem fishy). However I have trouble seeing the bigger picture. |
Ah indeed, I told my exciting story in this message on #244. I must say that I also have a bit of trouble seeing the big picture, and I think we are not alone. The caml-list discussion is obscure and hard to follow, @c-cube did the change on suggestion, the PR discussion was inconclusive, a nicer implementation was proposed in the thread and appears to have been ignored. We did not do a very good job here and should probably not have merged this PR without understanding the context more. What I can tell for sure is:
|
(Rest assured that our standards are much higher these days, we organize weeks-long consultations to settle burning indentation questions.) |
Aha, I think I know why it works now. If you look at @brabalan's nicer patch, you can see that an error message used to go through an intermediate Now, after my refactoring of |
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.
Good cleanup.
If you agree with my analysis, then it would be worth editing your Changes/commit explanation to make clear that we can now simply remove the code because some cleanup has been done in the meantime, but that it was not the case originally. |
That makes a lot of sense, thanks for the explanation @Armael . Glad we can just throw this away now. |
Excellent call, I'll update the Changes entry. |
Note: even if we did re-adopt the approach of going through an intermediary formatter in the future, we should still try to setup this formatter correctly (temporarily setting the same geometry as the final/destination formatter) instead of changing geometries globally. |
292b6cf
to
e364548
Compare
@Armael I rephrased the (commit message and) Changes entry. Let me know what you think. |
@gasche your commit message seems to suggest that setting (I can't say whether that's a good or a bad thing...) |
e364548
to
8c36e79
Compare
I thought that warnings would go to I reformulated the commit and Changes messages again. |
The logic in this patch is wrong: - setting the margins is not the responsibility of the color-handling code - because setup_colors is called at inpredictable times (on the first error/warning), the logic makes it very difficult to correctly set margins for `{str,err}_formatter` The patch was originally proposed in the caml-list discussion https://sympa.inria.fr/sympa/arc/caml-list/2015-09/msg00164.html but it does not convincingly solve the problem: - there is no reason to use `std_formatter` rather than `err_formatter` as a reference, and - the user can set the both margins themselves anyway. In particular, since the 4.08 changes to error/warning representations, we don't use intermediary formatters anymore to produce error/warning messages, so setting `Formatter.std_formatter` directly works as expected *when* this formatter is used to print to the toplevel (the current default, which may change in the future). Note: We have an API in `Location` to access and configure error/warning formatters, but it is not accessible from the toplevel. Changing the margins without using this API is fragile. For example, utop and expect-tests change the formatter away from the default.
Perfect. (ready to merge whenever CI passes) |
Thanks! |
The logic in #244 is wrong:
the logic makes it very difficult to correctly set margins for
{str,err}_formatter
The patch was originally proposed in the caml-list discussion
https://sympa.inria.fr/sympa/arc/caml-list/2015-09/msg00164.html
but it does not convincingly solve the problem:
std_formatter
rather than
err_formatter
as a reference, andWe have an API in
Location
to access and configure error/warningformatters, but it is not accessible from the toplevel. Changing the
margins without using this API is fragile, for example, utop or
expect-tests change the formatter from the defaut of
err_formatter
.