Code Monkey home page Code Monkey logo

Comments (8)

Mesabloo avatar Mesabloo commented on June 1, 2024 2

This was included in the version 1.9.0!

from diagnose.

Mesabloo avatar Mesabloo commented on June 1, 2024 1

Thanks for looking into it!
All the above issues should be fixed now. Some of them were details I completely missed when changing the pretty-printing library used internally (I used to use ansi-wl-pprint but switch to prettyprinter as the former got deprecated).

I'm already enjoying reading errors (sad, but true).

That is quite funny to read actually! This may be one of the downsides of this library. 😂

from diagnose.

Mesabloo avatar Mesabloo commented on June 1, 2024

Ideally, there would be no such function.
However, as the Pretty instance cannot convey colors, this cannot be done that way.
Also, since we require some parameters (e.g. for unicode characters), this is not possible.

There are 3 options:

  1. Create a Pretty instance, which gets rid of the colors and adds default parameters (basically pretty = unAnnotate . prettyDiagnostic True True).
    This is not a great solution in my opinion;
  2. Expose the function prettyDiagnostic and let the user remove colors if needed (using unAnnotate).
    This just needs a small pass on documentation, which is not actually up to date;
  3. Expose the function and add a parameter to remove colors conditionnaly (similarly to printDiagnostic).
    This needs a little bit of refactoring but should be fine.

Among all those options, I prefer the 2nd one, as it is the simpler one.

from diagnose.

kquick avatar kquick commented on June 1, 2024

I'd also like to suggest that instead of annotating the PP.Doc directly with AnsiStyle, you could defined your own annotation type that identified the significant portions of the doc (e.g. data DiagnoseAnn = ErrorAnn | WarningAnn | ThisAnn | WhereAnn | HintAnn | ...). Then in the printDiagnostic it could reAnnotate to convert the DiagnoseAnn into the AnsiStyle annotations you provide, but this would allow the prettyDiagnostic results to be easily reAnnotated into whatever styling is desired by the client code. The DiagnoseAnn is more easily matched than AnsiStyle, and is also more informative (e.g. currently Color Red is used for both the header "error" text and for the This portion) for reannotation.

from diagnose.

Mesabloo avatar Mesabloo commented on June 1, 2024

That is a great idea I actually did not think about.
This allows for more customization (the basic style will still be an option in a specific package) on how stuff is rendered.

This will take a bit of work to introduce into the library, but I think it is completely worth it.
Thanks for the suggestion!

from diagnose.

Mesabloo avatar Mesabloo commented on June 1, 2024

I have added in da0ccd5 a way of handling style simply via a maping Annotation -> AnsiStyle, similar to this

defaultStyle :: Style
defaultStyle = reAnnotate style
where
style = \case
ThisColor isError -> color if isError then Red else Yellow
MaybeColor -> color Magenta
WhereColor -> colorDull Blue
HintColor -> color Cyan
FileColor -> bold <> colorDull Green
RuleColor -> bold <> color Black
KindColor isError -> bold <> style (ThisColor isError)
NoLineColor -> bold <> colorDull Magenta
MarkerStyle st -> bold <> style st

That way, people can create their own styles (or themes, whatever you want to call it) and can feed them to printDiagnostic.
prettyDiagnostic, on the other hand, must have the style applied to it (e.g. myCustomStyle $ prettyDiagnostic ...).

This seems to implement your suggestion, which I quite like.
I will be closing this issue for the next release.

from diagnose.

kquick avatar kquick commented on June 1, 2024

Excellent! I'm glad I was able to help improve this library: I'm already enjoying reading errors (sad, but true).

Looking over the changes, I noticed a couple of spots where you might want to update the documentation:

And all the module copyright dates.

from diagnose.

Mesabloo avatar Mesabloo commented on June 1, 2024

Sorry for the delay.
All these new changes have been incorporated in the new version 2.0.0. 🎉 (see the module Error.Diagnose.Style)

from diagnose.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.