Skip to content

Conversation

@chenglou
Copy link
Member

@chenglou chenglou commented Aug 5, 2017

This makes it so that turning on -bs-better-error shows errors inline, a big request from the community.

It gracefully degrades to the normal reporting.
screenshot 2017-08-05 13 57 48
screenshot 2017-08-05 13 57 57


(** Input is the tag for example `@{<warning>@}` return escape code *)
val ansi_of_tag : string -> string
val ansi_of_tag : ?style_of_tag:(string -> style list) -> string -> string
Copy link
Member

Choose a reason for hiding this comment

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

any reason for this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

looks like the ability to inject a style rather than relying or extending https://github.com/chenglou/bucklescript/blob/944d705c6d7faff3fceffae0aef4728036817b52/jscomp/ext/ext_color.ml#L80?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah see Super_misc.colorize_tagged_string

Copy link
Member

Choose a reason for hiding this comment

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

do we really need that flexibility?

open Printtyp

open Location

Copy link
Member

Choose a reason for hiding this comment

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

can you add a .mli as well, in general, the less open, the better


done;
fprintf ppf "@]" (* v *)

Copy link
Member

Choose a reason for hiding this comment

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

an .mli would be great


if current_line_strictly_between_start_and_end_line then fprintf ppf "@}";

fprintf ppf "@]"; (* hov *)
Copy link
Member

Choose a reason for hiding this comment

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

are you aware of %a, in general, people use pp_open_box explicitly or [@%a@]

Copy link
Member Author

Choose a reason for hiding this comment

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

Did do that. Then lost track of boxes in the same function. I can refactor that later if needed

@bobzhang
Copy link
Member

bobzhang commented Aug 6, 2017

Anyone interested in reviewing this PR?
@chenglou these changes are mostly non-intrusive, let me know if you want to iterate/merge it quickly which is good to me.
One suggestion: there are two components of your better error proposal, one is better error message interpretation which is generally useful on all settings, the other is file/number/highlight , this is only useful in command line, since if you use vscode with problem matcher, it will be underlined by the IDE, would you make these two components separate in the future

Copy link
Member Author

@chenglou chenglou left a comment

Choose a reason for hiding this comment

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

Adding mli. Yeah this can be merged I think. I'll also provide another mode for editors, but I need to check into reason's outcome printer first.


(** Input is the tag for example `@{<warning>@}` return escape code *)
val ansi_of_tag : string -> string
val ansi_of_tag : ?style_of_tag:(string -> style list) -> string -> string
Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah see Super_misc.colorize_tagged_string


if current_line_strictly_between_start_and_end_line then fprintf ppf "@}";

fprintf ppf "@]"; (* hov *)
Copy link
Member Author

Choose a reason for hiding this comment

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

Did do that. Then lost track of boxes in the same function. I can refactor that later if needed

@chenglou
Copy link
Member Author

chenglou commented Aug 6, 2017

Done!

val print_file: range:(int * int) * (int * int) -> lines:string array -> Format.formatter -> unit -> unit

(** This will be called in super_main. This is how you override the default error and warning printers *)
val colorize_tagged_string: Format.formatter -> (string -> Ext_color.style list) -> unit
Copy link
Member

Choose a reason for hiding this comment

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

why do we need different tags? I would like to keep its simplicity as it is now

Copy link
Member Author

Choose a reason for hiding this comment

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

I do already use different tags, one set for warnings, one set for errors and one for that reporter; each reporter would probably get a different set too, and if not, they can be shared among them.

Copy link
Member

Choose a reason for hiding this comment

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

can we keep it simple? we can add more tags if info, warn, error is not enough. But I don't think the benefit of having such flexibility justify its complexity. After all, people can only tell 3 or 4 colors

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not using it for warn/error etc. I'm using it like so: https://github.com/BuckleScript/bucklescript/pull/1857/files#diff-98efb70d9d6c67e672eaf4a1a529e112R44

This way these printing functions don't need to know whether they're emitting a warning, an error, or a themed color in the future (some colors don't work well at all on the white terminal theme or windows blue).

If you want a single one then I can gather these (including maybe a few dozens of https://github.com/BuckleScript/bucklescript/pull/1857/files#diff-4b8762e0b86bfe6187fbc1eca3f9d139R237) under a single switch?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've tried just adding tags to ext_colors but then I realized it's not actually called. The existing colors are called by bsb_main's Bsb_log.setup (), and maybe at that point it's already too late, the ninja command has exited (correct me if I'm wrong).

So I'll end up with a Super_misc.setup, or the current colorize_tagged_string anyway, and call it at the appropriate time. But if you'd like to avoid the complexity of adding the option arg in ext_colors, I can copy it over to a super_* file?

Copy link
Member

Choose a reason for hiding this comment

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

Note that both bsb and bsc produce colorful error message but with different setup. (Bsb_log.setup and https://github.com/bucklescript/bucklescript/blob/master/vendor/ocaml/utils/misc.ml#L463 for the compiler)
I have a feeling that semantic tags is the wrong abstraction,(it is neither type safe nor scalable) can we hold on not over-using it for a while(just use existing provided tag defined in the compiler)?

Copy link
Member

@bobzhang bobzhang Aug 7, 2017

Choose a reason for hiding this comment

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

@chenglou
Copy link
Member Author

chenglou commented Aug 7, 2017

Ok, I've killed the custom semantic tags (only added two needed ones to ext_color now, no extra anywhere else).

@bobzhang bobzhang merged commit 47c39ea into rescript-lang:master Aug 8, 2017
@bobzhang
Copy link
Member

bobzhang commented Aug 8, 2017

thanks!

@chenglou chenglou deleted the asd branch August 8, 2017 00:25
chenglou added a commit to chenglou/rescript-compiler that referenced this pull request Aug 8, 2017
Gonna be testing the recent commits internally!
chenglou added a commit that referenced this pull request Aug 8, 2017
Gonna be testing the recent commits internally!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants