diagnose 2.0.1 → 2.1.0
raw patch · 7 files changed
+38/−15 lines, 7 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 [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 [msg] -> ParseErrorBundle s e -> Diagnostic msg
- Error.Diagnose.Compat.Megaparsec: hints :: HasHints e msg => e -> [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 [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 [msg] -> ParseError -> Diagnostic msg
- Error.Diagnose.Compat.Parsec: errorDiagnosticFromParseError :: forall msg. (IsString msg, HasHints Void msg) => Maybe msg -> msg -> Maybe [msg] -> ParseError -> Diagnostic msg
- Error.Diagnose.Compat.Parsec: hints :: HasHints e msg => e -> [msg]
- Error.Diagnose.Compat.Parsec: warningDiagnosticFromParseError :: forall msg. (IsString msg, HasHints Void msg) => Maybe msg -> msg -> Maybe [msg] -> ParseError -> Diagnostic msg
- Error.Diagnose.Diagnostic: diagnosticToJson :: ToJSON msg => Diagnostic msg -> ByteString
- Error.Diagnose.Position: instance Data.Aeson.Types.ToJSON.ToJSON Error.Diagnose.Position.Position
+ Error.Diagnose.Report: Hint :: msg -> Note msg
+ Error.Diagnose.Report: Note :: msg -> Note msg
+ Error.Diagnose.Report: data Note msg
- Error.Diagnose.Report: err :: Maybe msg -> msg -> [(Position, Marker msg)] -> [msg] -> Report msg
+ Error.Diagnose.Report: err :: Maybe msg -> msg -> [(Position, Marker msg)] -> [Note msg] -> Report msg
- Error.Diagnose.Report: warn :: Maybe msg -> msg -> [(Position, Marker msg)] -> [msg] -> Report msg
+ Error.Diagnose.Report: warn :: Maybe msg -> msg -> [(Position, Marker msg)] -> [Note msg] -> Report msg
Files
- README.md +2/−1
- diagnose.cabal +1/−1
- src/Error/Diagnose.hs +1/−1
- src/Error/Diagnose/Diagnostic/Internal.hs +1/−1
- src/Error/Diagnose/Report.hs +1/−1
- src/Error/Diagnose/Report/Internal.hs +29/−5
- test/rendering/Spec.hs +3/−5
README.md view
@@ -55,7 +55,7 @@ -- | A list of markers, along with the positions they span on [(Position, Marker msg)] -> -- | Some hints to be output at the bottom of the report-[msg] ->+[Note msg] -> -- | The created report Report msg ```@@ -96,6 +96,7 @@ (Position (1, 8) (1, 9) "somefile.zc", Where "type 'a' is bound here without constraints") ] ["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 let diagnostic = addFile def "somefile.zc" "let id<a>(x : a) : a := x\n + 1"
diagnose.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: diagnose-version: 2.0.1+version: 2.1.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
@@ -192,7 +192,7 @@ -- > } -- > , message: string -- > }[]--- > , hints: string[]+-- > , hints: ({ note: string } | { hint: string })[] -- > }[] -- > } --
src/Error/Diagnose/Diagnostic/Internal.hs view
@@ -150,7 +150,7 @@ -- > } -- > , message: T -- > }[]--- > , hints: T[]+-- > , hints: ({ note: T } | { hint: T })[] -- > }[] -- > } --
src/Error/Diagnose/Report.hs view
@@ -11,4 +11,4 @@ ) where -import Error.Diagnose.Report.Internal as Export (Marker (..), Report, err, warn)+import Error.Diagnose.Report.Internal as Export (Marker (..), Note (..), Report, err, warn)
src/Error/Diagnose/Report/Internal.hs view
@@ -37,6 +37,7 @@ import qualified Data.List as List import qualified Data.List.Safe as List import Data.Ord (Down (Down))+import Data.String (IsString (fromString)) import qualified Data.Text as Text import Error.Diagnose.Position import Error.Diagnose.Style (Annotation (..))@@ -54,8 +55,8 @@ -- ^ The message associated with the error. [(Position, Marker msg)] -- ^ A map associating positions with marker to show under the source code.- [msg]- -- ^ A list of hints to add at the end of the report.+ [Note msg]+ -- ^ A list of notes to add at the end of the report. instance Semigroup msg => Semigroup (Report msg) where Report isError1 code1 msg1 pos1 hints1 <> Report isError2 code2 msg2 pos2 hints2 =@@ -114,6 +115,23 @@ m1 <= m2 = m1 < m2 || m1 == m2 {-# INLINEABLE (<=) #-} +-- | A note is a piece of information that is found at the end of a report.+data Note msg+ = -- | A note, which is meant to give valuable information related to the encountered error.+ Note msg+ | -- | A hint, to propose potential fixes or help towards fixing the issue.+ Hint msg++#ifdef USE_AESON+instance ToJSON msg => ToJson (Note msg) where+ toJSON (Note msg) = object [ "note" .= msg ]+ toJSON (Hint msg) = object [ "hint" .= msg ]+#endif++-- | Constructs a 'Note' from the given message as a literal string.+instance IsString msg => IsString (Note msg) where+ fromString = Note . fromString+ -- | Constructs a warning or an error report. warn, err ::@@ -124,7 +142,7 @@ -- | A list associating positions with markers. [(Position, Marker msg)] -> -- | A possibly mempty list of hints to add at the end of the report.- [msg] ->+ [Note msg] -> Report msg warn = Report False {-# INLINE warn #-}@@ -605,7 +623,7 @@ {-# INLINE markerMessage #-} -- | Pretty prints all hints.-prettyAllHints :: Pretty msg => [msg] -> Int -> Bool -> Doc Annotation+prettyAllHints :: Pretty msg => [Note msg] -> Int -> Bool -> Doc Annotation prettyAllHints [] _ _ = mempty prettyAllHints (h : hs) leftLen withUnicode = {-@@ -613,5 +631,11 @@ (1) : Hint: <hint message> -} let prefix = hardline <+> pipePrefix leftLen withUnicode- in prefix <+> annotate HintColor ("Hint:" <+> replaceLinesWith (prefix <+> " ") (pretty h))+ in prefix <+> annotate HintColor (notePrefix h <+> replaceLinesWith (prefix <+> " ") (pretty $ noteMessage h)) <> prettyAllHints hs leftLen withUnicode+ where+ notePrefix (Note _) = "Note:"+ notePrefix (Hint _) = "Hint:"++ noteMessage (Note msg) = msg+ noteMessage (Hint msg) = msg
test/rendering/Spec.hs view
@@ -8,15 +8,13 @@ import qualified Data.HashMap.Lazy as HashMap import Error.Diagnose ( Marker (..),+ Note (Hint), Position (..), Report, addFile, addReport, def, defaultStyle,-#ifdef USE_AESON- diagnosticToJson,-#endif err, printDiagnostic, stdout,@@ -240,8 +238,8 @@ Nothing "Error with no markers and two hints" []- [ "First hint",- "Second hint"+ [ "First note",+ Hint "Second hint" ] errorSingleMultilineMarkerNoHints :: Report String