diagnose 2.3.1 → 2.4.0
raw patch · 10 files changed
+74/−54 lines, 10 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Error.Diagnose.Compat.Megaparsec: class HasHints e msg
+ Error.Diagnose.Compat.Megaparsec: diagnosticFromBundle :: forall msg s e. (IsString msg, Stream s, HasHints e msg, ShowErrorComponent e, VisualStream s, TraversableStream s) => (ParseError s e -> Bool) -> Maybe msg -> msg -> Maybe [Note msg] -> ParseErrorBundle s e -> Diagnostic msg
+ Error.Diagnose.Compat.Megaparsec: errorDiagnosticFromBundle :: forall msg s e. (IsString msg, Stream s, HasHints e msg, ShowErrorComponent e, VisualStream s, TraversableStream s) => Maybe msg -> msg -> Maybe [Note msg] -> ParseErrorBundle s e -> Diagnostic msg
+ Error.Diagnose.Compat.Megaparsec: hints :: HasHints e msg => e -> [Note msg]
+ Error.Diagnose.Compat.Megaparsec: warningDiagnosticFromBundle :: forall msg s e. (IsString msg, Stream s, HasHints e msg, ShowErrorComponent e, VisualStream s, TraversableStream s) => Maybe msg -> msg -> Maybe [Note msg] -> ParseErrorBundle s e -> Diagnostic msg
+ Error.Diagnose.Compat.Parsec: class HasHints e msg
+ Error.Diagnose.Compat.Parsec: diagnosticFromParseError :: forall msg. (IsString msg, HasHints Void msg) => (ParseError -> Bool) -> Maybe msg -> msg -> Maybe [Note msg] -> ParseError -> Diagnostic msg
+ Error.Diagnose.Compat.Parsec: errorDiagnosticFromParseError :: forall msg. (IsString msg, HasHints Void msg) => Maybe msg -> msg -> Maybe [Note msg] -> ParseError -> Diagnostic msg
+ Error.Diagnose.Compat.Parsec: hints :: HasHints e msg => e -> [Note msg]
+ Error.Diagnose.Compat.Parsec: warningDiagnosticFromParseError :: forall msg. (IsString msg, HasHints Void msg) => Maybe msg -> msg -> Maybe [Note msg] -> ParseError -> Diagnostic msg
+ Error.Diagnose.Diagnostic: diagnosticToJson :: ToJSON msg => Diagnostic msg -> ByteString
+ Error.Diagnose.Diagnostic: reportsOf :: Diagnostic msg -> [Report msg]
+ Error.Diagnose.Position: instance Data.Aeson.Types.ToJSON.ToJSON Error.Diagnose.Position.Position
+ Error.Diagnose.Report: pattern Err :: Maybe msg -> msg -> [(Position, Marker msg)] -> [Note msg] -> Report msg
+ Error.Diagnose.Report: pattern Warn :: Maybe msg -> msg -> [(Position, Marker msg)] -> [Note msg] -> Report msg
Files
- README.md +3/−3
- diagnose.cabal +1/−1
- src/Error/Diagnose.hs +4/−4
- src/Error/Diagnose/Compat/Megaparsec.hs +1/−1
- src/Error/Diagnose/Compat/Parsec.hs +1/−1
- src/Error/Diagnose/Diagnostic.hs +1/−0
- src/Error/Diagnose/Diagnostic/Internal.hs +4/−0
- src/Error/Diagnose/Report.hs +1/−1
- src/Error/Diagnose/Report/Internal.hs +19/−2
- test/rendering/Spec.hs +39/−41
README.md view
@@ -43,8 +43,8 @@ The second step is to add some reports. There are two kinds of reports:-- Error reports, created through `err`-- Warning reports, created by using `warn`+- Error reports, created through `Err`+- Warning reports, created by using `Warn` Both of these fonctions have the following type: ```haskell@@ -98,7 +98,7 @@ ["Adding 'Num(a)' to the list of constraints may solve this problem."] -- ^^^^ This is a 'Note' not a 'Hint', as specified by its 'IsString' instance --- Create the diagnostic +-- Create the diagnostic let diagnostic = addFile def "somefile.zc" "let id<a>(x : a) : a := x\n + 1" let diagnostic' = addReport diagnostic beautifulExample
diagnose.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: diagnose-version: 2.3.1+version: 2.4.0 synopsis: Beautiful error reporting done easily description: This package provides a simple way of getting beautiful compiler/interpreter errors using a very simple interface for the programmer.
src/Error/Diagnose.hs view
@@ -71,9 +71,9 @@ -- -- This library allows defining two kinds of reports: ----- - Errors, using 'err'+-- - Errors, using 'Err' ----- - Warnings, using 'warn'+-- - Warnings, using 'Warn' -- -- Both take an optional error code, a message, a list of located markers and a list of hints. --@@ -81,7 +81,7 @@ -- -- > exampleReport :: Report String -- > exampleReport =--- > err+-- > Err -- > -- vv OPTIONAL ERROR CODE -- > Nothing -- > -- vv ERROR MESSAGE@@ -285,7 +285,7 @@ -- > in printDiagnostic stderr True True 4 diag' -- > Right res -> print res ----- This will output the following errr on @stderr@:+-- This will output the following error on @stderr@: -- -- > [error]: Parse error on input -- > ╭──▶ <interactive>@1:6-1:7
src/Error/Diagnose/Compat/Megaparsec.hs view
@@ -55,7 +55,7 @@ source = fromSourcePos (MP.pstateSourcePos pos) msgs = fromString @msg <$> lines (MP.parseErrorTextPretty error) in flip- (if isError error then err code msg else warn code msg)+ (if isError error then Err code msg else Warn code msg) (errorHints error) if | [m] <- msgs -> [(source, This m)]
src/Error/Diagnose/Compat/Parsec.hs view
@@ -47,7 +47,7 @@ diagnosticFromParseError isError code msg (fromMaybe [] -> defaultHints) error = let pos = fromSourcePos $ PE.errorPos error markers = toMarkers pos $ PE.errorMessages error- report = (if isError error then err code msg else warn code msg) markers (defaultHints <> hints (undefined :: Void))+ report = (if isError error then Err code msg else Warn code msg) markers (defaultHints <> hints (undefined :: Void)) in addReport def report where fromSourcePos :: PP.SourcePos -> Position
src/Error/Diagnose/Diagnostic.hs view
@@ -23,6 +23,7 @@ def, errorsToWarnings, hasReports,+ reportsOf, prettyDiagnostic, printDiagnostic, warningsToErrors,
src/Error/Diagnose/Diagnostic/Internal.hs view
@@ -72,6 +72,10 @@ hasReports (Diagnostic DL.Nil _) = False hasReports _ = True +-- | Retrieves the reports for this diagnostic.+reportsOf :: Diagnostic msg -> [Report msg]+reportsOf (Diagnostic reports _) = toList reports+ -- | Transforms every warning report in this diagnostic into an error report. warningsToErrors :: Diagnostic msg -> Diagnostic msg warningsToErrors (Diagnostic reports files) = Diagnostic (warningToError <$> reports) files
src/Error/Diagnose/Report.hs view
@@ -11,4 +11,4 @@ ) where -import Error.Diagnose.Report.Internal as Export (Marker (..), Note (..), Report, err, errorToWarning, warn, warningToError)+import Error.Diagnose.Report.Internal as Export (Marker (..), Note (..), Report(Warn, Err), err, errorToWarning, warn, warningToError)
src/Error/Diagnose/Report/Internal.hs view
@@ -4,8 +4,9 @@ {-# LANGUAGE MultiWayIf #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-}-{-# OPTIONS -Wno-name-shadowing #-} {-# LANGUAGE TypeApplications #-}+{-# LANGUAGE PatternSynonyms #-}+{-# OPTIONS -Wno-name-shadowing #-} -- | -- Module : Error.Diagnose.Report.Internal@@ -19,7 +20,10 @@ -- It is also highly undocumented. -- -- Please limit yourself to the "Error.Diagnose.Report" module, which exports some of the useful functions defined here.-module Error.Diagnose.Report.Internal where+module Error.Diagnose.Report.Internal+ ( module Error.Diagnose.Report.Internal+ , Report(.., Warn, Err)+ ) where #ifdef USE_AESON import Data.Aeson (ToJSON(..), object, (.=))@@ -64,6 +68,16 @@ [Note msg] -- ^ A list of notes to add at the end of the report. +-- | Pattern synonym for a warning report.+pattern Warn :: Maybe msg -> msg -> [(Position, Marker msg)] -> [Note msg] -> Report msg+pattern Warn errCode msg reports notes = Report False errCode msg reports notes++-- | Pattern synonym for an error report.+pattern Err :: Maybe msg -> msg -> [(Position, Marker msg)] -> [Note msg] -> Report msg+pattern Err errCode msg reports notes = Report True errCode msg reports notes++{-# COMPLETE Warn, Err #-}+ instance Semigroup msg => Semigroup (Report msg) where Report isError1 code1 msg1 pos1 hints1 <> Report isError2 code2 msg2 pos2 hints2 = Report (isError1 || isError2) (code1 <|> code2) (msg1 <> msg2) (pos1 <> pos2) (hints1 <> hints2)@@ -93,6 +107,7 @@ Maybe m -> [ "message" .= m , "kind" .= ("maybe" :: String) ]+ Blank -> [ "kind" .= ("blank" :: String) ] #endif -- | The type of markers with abstract message type, shown under code lines.@@ -157,8 +172,10 @@ Report msg warn = Report False {-# INLINE warn #-}+{-# DEPRECATED warn "'warn' is deprecated. Use 'Warn' instead." #-} err = Report True {-# INLINE err #-}+{-# DEPRECATED err "'err' is deprecated. Use 'Err' instead." #-} -- | Transforms a warning report into an error report. warningToError :: Report msg -> Report msg
test/rendering/Spec.hs view
@@ -10,15 +10,13 @@ ( Marker (..), Note (Hint), Position (..),- Report,+ Report(..), addFile, addReport, def, defaultStyle,- err, printDiagnostic, stdout,- warn, ) import System.IO (hPutStrLn) @@ -90,7 +88,7 @@ errorNoMarkersNoHints :: Report String errorNoMarkersNoHints =- err+ Err Nothing "Error with no marker" []@@ -98,7 +96,7 @@ errorSingleMarkerNoHints :: Report String errorSingleMarkerNoHints =- err+ Err Nothing "Error with one marker in bounds" [(Position (1, 25) (1, 30) "test.zc", This "Required here")]@@ -106,7 +104,7 @@ warningSingleMarkerNoHints :: Report String warningSingleMarkerNoHints =- warn+ Warn Nothing "Warning with one marker in bounds" [(Position (1, 25) (1, 30) "test.zc", This "Required here")]@@ -114,7 +112,7 @@ errorTwoMarkersSameLineNoOverlapNoHints :: Report String errorTwoMarkersSameLineNoOverlapNoHints =- err+ Err Nothing "Error with two markers in bounds (no overlap) on the same line" [ (Position (1, 5) (1, 10) "test.zc", This "First"),@@ -124,7 +122,7 @@ errorSingleMarkerOutOfBoundsNoHints :: Report String errorSingleMarkerOutOfBoundsNoHints =- err+ Err Nothing "Error with one marker out of bounds" [(Position (10, 5) (10, 15) "test2.zc", This "Out of bounds")]@@ -132,7 +130,7 @@ errorTwoMarkersSameLineOverlapNoHints :: Report String errorTwoMarkersSameLineOverlapNoHints =- err+ Err Nothing "Error with two overlapping markers in bounds" [ (Position (1, 6) (1, 13) "test.zc", This "First"),@@ -142,7 +140,7 @@ errorTwoMarkersSameLinePartialOverlapNoHints :: Report String errorTwoMarkersSameLinePartialOverlapNoHints =- err+ Err Nothing "Error with two partially overlapping markers in bounds" [ (Position (1, 5) (1, 25) "test.zc", This "First"),@@ -152,7 +150,7 @@ errorTwoMarkersTwoLinesNoHints :: Report String errorTwoMarkersTwoLinesNoHints =- err+ Err Nothing "Error with two markers on two lines in bounds" [ (Position (1, 5) (1, 12) "test.zc", This "First"),@@ -162,7 +160,7 @@ realWorldExample :: Report String realWorldExample =- err+ Err Nothing "Could not deduce constraint 'Num(a)' from the current context" [ (Position (1, 25) (1, 30) "test.zc", This "While applying function '+'"),@@ -173,7 +171,7 @@ errorTwoMarkersSamePositionNoHints :: Report String errorTwoMarkersSamePositionNoHints =- err+ Err Nothing "Error with two markers on the same exact position in bounds" [ (Position (1, 6) (1, 10) "test.zc", This "First"),@@ -183,7 +181,7 @@ errorThreeMarkersWithOverlapNoHints :: Report String errorThreeMarkersWithOverlapNoHints =- err+ Err Nothing "Error with three markers with overlapping in bounds" [ (Position (1, 9) (1, 15) "test.zc", This "First"),@@ -194,7 +192,7 @@ errorWithMultilineErrorNoMarkerNoHints :: Report String errorWithMultilineErrorNoMarkerNoHints =- err+ Err Nothing "Error with multi\nline message and no markers" []@@ -202,7 +200,7 @@ errorSingleMultilineMarkerMessageNoHints :: Report String errorSingleMultilineMarkerMessageNoHints =- err+ Err Nothing "Error with single marker with multiline message" [(Position (1, 9) (1, 15) "test.zc", This "First\nmultiline")]@@ -210,7 +208,7 @@ errorTwoMarkersSameOriginOverlapNoHints :: Report String errorTwoMarkersSameOriginOverlapNoHints =- err+ Err Nothing "Error with two markers with same origin but partial overlap in bounds" [ (Position (1, 9) (1, 15) "test.zc", This "First"),@@ -220,7 +218,7 @@ errorNoMarkersSingleHint :: Report String errorNoMarkersSingleHint =- err+ Err Nothing "Error with no marker and one hint" []@@ -228,7 +226,7 @@ errorNoMarkersSingleMultilineHint :: Report String errorNoMarkersSingleMultilineHint =- err+ Err Nothing "Error with no marker and one multiline hint" []@@ -236,7 +234,7 @@ errorNoMarkersTwoHints :: Report String errorNoMarkersTwoHints =- err+ Err Nothing "Error with no markers and two hints" []@@ -246,7 +244,7 @@ errorSingleMultilineMarkerNoHints :: Report String errorSingleMultilineMarkerNoHints =- err+ Err Nothing "Error with single marker spanning across multiple lines" [(Position (1, 15) (2, 6) "test.zc", This "First")]@@ -254,7 +252,7 @@ errorTwoMarkersWithMultilineNoHints :: Report String errorTwoMarkersWithMultilineNoHints =- err+ Err Nothing "Error with two markers, one single line and one multiline, in bounds" [ (Position (1, 9) (1, 13) "test.zc", This "First"),@@ -264,7 +262,7 @@ errorTwoMultilineMarkersNoHints :: Report String errorTwoMultilineMarkersNoHints =- err+ Err Nothing "Error with two multiline markers in bounds" [ (Position (1, 9) (2, 5) "test.zc", This "First"),@@ -274,7 +272,7 @@ errorSingleMultilineMarkerMultilineMessageNoHints :: Report String errorSingleMultilineMarkerMultilineMessageNoHints =- err+ Err Nothing "Error with one multiline marker with a multiline message in bounds" [(Position (1, 9) (2, 5) "test.zc", This "Multi\nline message")]@@ -282,7 +280,7 @@ errorTwoMultilineMarkersFirstMultilineMessageNoHints :: Report String errorTwoMultilineMarkersFirstMultilineMessageNoHints =- err+ Err Nothing "Error with two multiline markers with one multiline message in bounds" [ (Position (1, 9) (2, 5) "test.zc", This "First"),@@ -292,7 +290,7 @@ errorThreeMultilineMarkersTwoMultilineMessageNoHints :: Report String errorThreeMultilineMarkersTwoMultilineMessageNoHints =- err+ Err Nothing "Error with three multiline markers with two multiline messages in bounds" [ (Position (1, 9) (2, 5) "test.zc", This "First"),@@ -303,7 +301,7 @@ errorOrderSensitive :: Report String errorOrderSensitive =- err+ Err Nothing "Order-sensitive labels with crossing" [ (Position (1, 1) (1, 7) "somefile.zc", This "Leftmost label"),@@ -313,7 +311,7 @@ beautifulExample :: Report String beautifulExample =- err+ Err Nothing "Could not deduce constraint 'Num(a)' from the current context" [ (Position (1, 25) (2, 6) "somefile.zc", This "While applying function '+'"),@@ -324,7 +322,7 @@ errorMultilineAfterSingleLine :: Report String errorMultilineAfterSingleLine =- err+ Err Nothing "Multiline after single line" [ (Position (1, 17) (1, 18) "unsized.nst", Where "Kind is infered from here"),@@ -334,7 +332,7 @@ errorOnEmptyLine :: Report String errorOnEmptyLine =- err+ Err Nothing "Error on empty line" [(Position (1, 5) (3, 8) "err.nst", This "error on empty line")]@@ -342,7 +340,7 @@ errorMultipleFiles :: Report String errorMultipleFiles =- err+ Err Nothing "Error on multiple files" [ (Position (1, 5) (1, 7) "test.zc", Where "Function already declared here"),@@ -352,7 +350,7 @@ errorWithCode :: Report String errorWithCode =- err+ Err (Just "E0123") "Error with code and markers" [(Position (1, 5) (1, 7) "test.zc", This "is an error")]@@ -360,7 +358,7 @@ errorWithStrangeUnicodeInput :: Report String errorWithStrangeUnicodeInput =- err+ Err (Just "❎") "ⓈⓉⓇⒶⓃⒼⒺ ⓊⓃⒾⒸⓄⒹⒺ" [ (Position (1, 1) (1, 7) "unicode.txt", This "should work fine 🎉"),@@ -370,7 +368,7 @@ errorWithMultilineMarkerOn3Lines :: Report String errorWithMultilineMarkerOn3Lines =- err+ Err Nothing "Multiline marker on 3 lines" [(Position (1, 3) (3, 10) "test.zc", This "should color all 3 lines correctly")]@@ -378,7 +376,7 @@ errorMultilineMarkerNotAtEnd :: Report String errorMultilineMarkerNotAtEnd =- err+ Err Nothing "Multiline marker not at end of report" [ (Position (1, 10) (2, 3) "test.zc", This "is a multline marker"),@@ -388,7 +386,7 @@ errorWithLineGap :: Report String errorWithLineGap =- err+ Err Nothing "Error with line gaps between two markers" [ (Position (1, 1) (1, 3) "gaps.txt", Where "is a first marker"),@@ -398,7 +396,7 @@ errorWithMultilineMarkerMessage :: Report String errorWithMultilineMarkerMessage =- err+ Err Nothing "Error with multiline message in first marker" [ (Position (1, 5) (1, 10) "test.zc", This "First\nmarker"),@@ -408,7 +406,7 @@ errorWithMultilineMarkerMessage' :: Report String errorWithMultilineMarkerMessage' =- err+ Err Nothing "Error with multiline message in first marker" [ (Position (1, 5) (1, 10) "test.zc", This "First\nmarker"),@@ -419,7 +417,7 @@ repro3 :: Report String repro3 =- err+ Err (Just "WrongStaticLayerLength") "The length of the static layer does not match the length of the template it uses" [ (Position (3, 3) (5, 16) "repro3.file", Where "This template has 9 elements"),@@ -431,7 +429,7 @@ errorWithSingleBlankMarker :: Report String errorWithSingleBlankMarker =- err+ Err Nothing "Error with a single blank marker" [(Position (1, 5) (1, 10) "test.zc", Blank)]@@ -439,7 +437,7 @@ errorWithBlankAndNormalMarkerInLine :: Report String errorWithBlankAndNormalMarkerInLine =- err+ Err Nothing "Error with a single blank marker" [(Position (1, 5) (1, 10) "test.zc", Blank), (Position (1, 15) (1, 22) "test.zc", This "After a blank")]