chapelure: A diagnostics library for Haskell

[ library, mit, pretty-printer ] [ Propose Tags ] [ Report a vulnerability ]

Chapelure is a diagnostics library for Haskell.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.1.0
Change log CHANGELOG.md
Dependencies ansi-terminal (>=0.11 && <0.12), base (>=4.14 && <4.18), colour (>=2.3 && <2.4), containers (>=0.6 && <0.7), hsluv-haskell (>=0.1 && <0.2), nonempty-vector (>=0.2 && <0.3), optics-core (>=0.4 && <0.5), prettyprinter (>=1.7 && <1.8), text (>=1.2 && <1.3), text-display (>=0.0 && <0.1), vector (>=0.12 && <0.13) [details]
License MIT
Author Hécate Moonlight
Maintainer Hécate Moonlight
Category Pretty Printer
Home page https://github.com/haskell-chapelure/chapelure#readme
Bug tracker https://github.com/haskell-chapelure/chapelure/issues
Source repo head: git clone https://github.com/haskell-chapelure/chapelure
Uploaded by hecate at 2022-03-31T22:15:48Z
Distributions
Downloads 115 total (4 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for chapelure-0.0.1.0

[back to package description]

Chapelure CI-badge simple-haskell

⚠ The 0.0.* series is experimental.

Description

chapelure is a diagnostic library for Haskell, based on the miette library by Kat Marchán

Build

$ cabal build 

Examples

You can provide snippets to be annotated and highlighted:

[L342]: Error: 
 ╭[Code.hs:3:1] 
 │ 
3│ add :: Int
 │        ╰┬╯
 │         ╰ Return type is an “Int”
4│ add = 1 + True
 │           ╰┬─╯
 │            ╰ You tried to pass a “Bool”
 │ Did you check all the types of your arguments?
 │ https://localhost:8888/help/code/L342
 ╯ 

And you can even put multiple highlights per line:

[L342]: Error: 
 ╭[Code.hs:3:1] 
 │ 
3│ add :: Int
 │        ╰┬╯
 │         ╰ Return type is “Int”
4│ add = 1 + True
 │         ┬
 │         ╰ This takes an “Int”
 │           ╰┬─╯
 │            ╰ But you passed a “Bool”
 │ Did you check all the types of your arguments?
 │ https://localhost:8888/help/code/L342
 ╯ 

To generate such a diagnostic, build the appropriate structures and pass it to the renderer:

import Data.Vector.NonEmpty as NEVec
import Chapelure.Types


let helpMessage = "Did you check all the types of your arguments?"
let highlights = NEVec.fromList [
           Source{ label = Just "Return type is “Int”"
                 , line = Line 3
                 , startColumn = Column 8
                 , endColumn = Column 10
                 }
         , Source{ label = Just "This takes an “Int”"
                 , line = Line 4
                 , startColumn = Column 9
                 , endColumn = Column 9
                 }
         , Source{ label = Just "But you passed a “Bool”"
                 , line = Line 4
                 , startColumn = Column 11
                 , endColumn = Column 14
                 }
        ]
let snip = Snippet { location = ("Code.hs", Line 3, Column 1)
                   , highlights = highlights
                   , content = Vec.fromList $ T.lines $ T.pack "add :: Int\nadd = 1 + True"
                   }
let diagnostic = Diagnostic { code = Just "L342"
                            , severity = Error
                            , link = Just "https://localhost:8888/help/code/L342"
                            , help = Just helpMessage
                            , snippets = Just . NEVec.singleton $ snip
                            }

It even outputs in colour!

Colourful terminal output

Acknowledgements

  • Kat Marchán
  • Geoffroy Couprie