packages feed

diagnose 2.0.0 → 2.0.1

raw patch · 5 files changed

+45/−9 lines, 5 filesdep ~textPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: text

API changes (from Hackage documentation)

Files

diagnose.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           diagnose-version:        2.0.0+version:        2.0.1 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.@@ -70,6 +70,7 @@     , hashable >=1.3 && <2     , prettyprinter >=1.7.0 && <2     , prettyprinter-ansi-terminal >=1.1.0 && <2+    , text >=1.0.0.0 && <=2.0     , unordered-containers ==0.2.*     , wcwidth >=0.0.1 && <1   if flag(json)@@ -190,6 +191,7 @@     , hashable >=1.3 && <2     , prettyprinter >=1.7.0 && <2     , prettyprinter-ansi-terminal >=1.1.0 && <2+    , text >=1.0.0.0 && <=2.0     , unordered-containers ==0.2.*     , wcwidth >=0.0.1 && <1   if flag(json)
src/Error/Diagnose.hs view
@@ -105,7 +105,7 @@ -- --         This marker is output in red in an error report, and yellow in a warning report. -----   - A 'Error.Diagnose.Report.Where' marker contains additional information/provides context to the error/warning report.+--   - A 'Error.Diagnose.Report.Where' marker contains additional information\/provides context to the error\/warning report. --     For example, it may underline where a given variable @x@ is bound to emphasize it. -- --         This marker is output in blue.
src/Error/Diagnose/Diagnostic/Internal.hs view
@@ -113,7 +113,7 @@   Diagnostic msg ->   -- | The path to the file.   FilePath ->-  -- | The content of the file as a single string, where lines are ended by @\n@.+  -- | The content of the file as a single string, where lines are ended by @\\n@.   String ->   Diagnostic msg addFile (Diagnostic reports files) path content =
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 qualified Data.Text as Text import Error.Diagnose.Position import Error.Diagnose.Style (Annotation (..)) import Prettyprinter (Doc, Pretty (..), align, annotate, colon, hardline, lbracket, rbracket, space, width, (<+>))@@ -427,7 +428,7 @@      showMultiline _ [] = mempty     showMultiline isLastMultiline multiline =-      let colorOfLastMultilineMarker = markerColor isError . snd <$> List.safeLast multiline+      let colorOfFirstMultilineMarker = markerColor isError . snd <$> List.safeHead multiline           -- take the color of the last multiline marker in case we need to add additional bars            prefix = hardline <+> dotPrefix leftLen withUnicode <> space@@ -445,7 +446,7 @@           showMultilineMarkerMessages [] = []           showMultilineMarkerMessages [m] = [showMultilineMarkerMessage m True]           showMultilineMarkerMessages (m : ms) = showMultilineMarkerMessage m False : showMultilineMarkerMessages ms-       in prefixWithBar colorOfLastMultilineMarker <> prefix <> fold (List.intersperse prefix $ showMultilineMarkerMessages $ reverse multiline)+       in prefixWithBar colorOfFirstMultilineMarker <> prefix <> fold (List.intersperse prefix $ showMultilineMarkerMessages multiline)  -- | getLine_ :: HashMap FilePath [String] -> [(Position, Marker msg)] -> Int -> Int -> Bool -> (IntMap.HashMap Int Int, Doc Annotation)@@ -532,7 +533,7 @@                   pipesBeforeRendered = pipesBefore <&> second \marker -> annotate (markerColor isError marker) (if withUnicode then "│" else "|")                   -- pre-render pipes which are before because they will be shown -                  lastBeginPosition = snd . begin . fst <$> List.safeHead (List.sortOn (snd . begin . fst) pipesAfter)+                  lastBeginPosition = snd . begin . fst <$> List.safeLast (List.sortOn (snd . begin . fst) pipesAfter)                    lineLen = case lastBeginPosition of                     Nothing -> 0@@ -547,9 +548,17 @@                    lineChar = if withUnicode then '─' else '-'                   pointChar = if withUnicode then "╸" else "-"-               in lineStart pipesBeforeRendered++                  bc' = bc + lineLen + 2+                  pipesBeforeMessageStart = List.filter ((< bc') . snd . begin . fst) pipesAfter+                  -- consider pipes before, as well as pipes which came before the text rectangle bounds+                  pipesBeforeMessageRendered = (pipesBefore <> pipesBeforeMessageStart) <&> second \marker -> annotate (markerColor isError marker) (if withUnicode then "│" else "|")+               in -- also pre-render pipes which are before the message text bounds, because they will be shown if the message is on+                  -- multiple lines++                  lineStart pipesBeforeRendered                     <> annotate (markerColor isError msg) (currentPipe <> pretty (replicate lineLen lineChar) <> pointChar)-                    <+> annotate (markerColor isError msg) (replaceLinesWith (hardline <+> lineStart pipesBeforeRendered <+> "  ") $ pretty $ markerMessage msg)+                    <+> annotate (markerColor isError msg) (replaceLinesWith (hardline <+> lineStart pipesBeforeMessageRendered <+> if List.null pipesBeforeMessageStart then "  " else " ") $ pretty $ markerMessage msg)          in hardline <+> prefix <> showMessages specialPrefix pipes lineLen  -- WARN: uses the internal of the library@@ -562,7 +571,9 @@ replaceLinesWith _ Fail = Fail replaceLinesWith _ Empty = Empty replaceLinesWith _ (Char c) = Char c-replaceLinesWith _ (Text n s) = Text n s+replaceLinesWith repl (Text _ s) =+  let lines = Text.split (== '\n') s <&> \txt -> Text (Text.length txt) txt+   in mconcat (List.intersperse repl lines) replaceLinesWith repl (FlatAlt f d) = FlatAlt (replaceLinesWith repl f) (replaceLinesWith repl d) replaceLinesWith repl (Cat c d) = Cat (replaceLinesWith repl c) (replaceLinesWith repl d) replaceLinesWith repl (Nest n d) = Nest n (replaceLinesWith repl d)
test/rendering/Spec.hs view
@@ -71,6 +71,8 @@           errorMultilineMarkerNotAtEnd,           errorWithLineGap,           repro3,+          errorWithMultilineMarkerMessage,+          errorWithMultilineMarkerMessage',           beautifulExample         ] @@ -391,6 +393,27 @@     "Error with line gaps between two markers"     [ (Position (1, 1) (1, 3) "gaps.txt", Where "is a first marker"),       (Position (5, 2) (5, 4) "gaps.txt", This "is the main marker")+    ]+    []++errorWithMultilineMarkerMessage :: Report String+errorWithMultilineMarkerMessage =+  err+    Nothing+    "Error with multiline message in first marker"+    [ (Position (1, 5) (1, 10) "test.zc", This "First\nmarker"),+      (Position (1, 15) (1, 22) "test.zc", Where "Second")+    ]+    []++errorWithMultilineMarkerMessage' :: Report String+errorWithMultilineMarkerMessage' =+  err+    Nothing+    "Error with multiline message in first marker"+    [ (Position (1, 5) (1, 10) "test.zc", This "First\nmarker"),+      (Position (1, 15) (1, 22) "test.zc", Where "Second"),+      (Position (1, 10) (1, 15) "test.zc", Maybe "Third")     ]     []