mirror of
https://github.com/Mesabloo/diagnose.git
synced 2024-11-22 01:32:56 +03:00
Fix nested user strings and add test
This commit is contained in:
parent
7838253a7a
commit
e62d09c599
@ -53,7 +53,7 @@ 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, (<+>), reAnnotate)
|
||||
import Prettyprinter.Internal (Doc (..))
|
||||
import Prettyprinter.Internal (Doc (..), textSpaces)
|
||||
import Data.Bool (bool)
|
||||
|
||||
type FileMap = HashMap FilePath (Array Int String)
|
||||
@ -653,7 +653,8 @@ replaceLinesWith repl (Text _ s) =
|
||||
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)
|
||||
-- We need to push the nesting past our line prefix
|
||||
replaceLinesWith repl (Nest n d) = replaceLinesWith (repl <> pretty (textSpaces n)) d
|
||||
replaceLinesWith repl (Union c d) = Union (replaceLinesWith repl c) (replaceLinesWith repl d)
|
||||
replaceLinesWith repl (Column f) = Column (replaceLinesWith repl . f)
|
||||
replaceLinesWith repl (Nesting f) = Nesting (replaceLinesWith repl . f)
|
||||
|
@ -5,12 +5,13 @@
|
||||
|
||||
#ifdef USE_AESON
|
||||
import qualified Data.ByteString.Lazy as BS
|
||||
import Error.Diagnose(diagnosticToJson)
|
||||
#endif
|
||||
import Data.HashMap.Lazy (HashMap)
|
||||
import qualified Data.HashMap.Lazy as HashMap
|
||||
import Error.Diagnose
|
||||
( Marker (..),
|
||||
Note (Hint),
|
||||
Note (..),
|
||||
Position (..),
|
||||
Report(..),
|
||||
addFile,
|
||||
@ -20,12 +21,11 @@ import Error.Diagnose
|
||||
printDiagnostic,
|
||||
printDiagnostic',
|
||||
stdout,
|
||||
diagnosticToJson,
|
||||
WithUnicode (..),
|
||||
TabSize (..),
|
||||
)
|
||||
import System.IO (hPutStrLn)
|
||||
import Prettyprinter (Doc, annotate, pretty, hsep, indent, vsep)
|
||||
import Prettyprinter (Doc, annotate, pretty, hsep, indent, vsep, nest)
|
||||
import Prettyprinter.Render.Terminal (AnsiStyle, Color (..), color, bold, italicized, underlined)
|
||||
import Data.Traversable (mapAccumL)
|
||||
import Data.Functor.Compose (Compose(..))
|
||||
@ -85,7 +85,8 @@ main = do
|
||||
]
|
||||
customAnnReports =
|
||||
[ colorfulReport,
|
||||
indentedReport
|
||||
indentedReport,
|
||||
nestingReport
|
||||
]
|
||||
|
||||
let diag = HashMap.foldlWithKey' addFile (foldl addReport def reports) files
|
||||
@ -125,11 +126,10 @@ indentedReport =
|
||||
Err
|
||||
Nothing
|
||||
("Indent..." <> indent 3 (vsep ["foo", "bar", "baz"]))
|
||||
[(Position (1, 15) (1, 16) "test.zc", Maybe a)
|
||||
,(Position (1, 11) (1, 12) "test.zc", This b)
|
||||
,(Position (1, 5) (1, 10) "test.zc", Where c)
|
||||
[ (Position (1, 15) (1, 16) "test.zc", Maybe a)
|
||||
, (Position (1, 11) (1, 12) "test.zc", This b)
|
||||
]
|
||||
[]
|
||||
[Note c]
|
||||
where
|
||||
a =
|
||||
vsep
|
||||
@ -145,7 +145,8 @@ indentedReport =
|
||||
, "A man in hue, all “hues” in his controlling,"
|
||||
, "Which steals men’s eyes and women’s souls amazeth."
|
||||
]
|
||||
c = vsep
|
||||
c =
|
||||
vsep
|
||||
[ "And for a woman wert thou first created;"
|
||||
, "Till Nature, as she wrought thee, fell a-doting,"
|
||||
, "And by addition me of thee defeated,"
|
||||
@ -154,6 +155,30 @@ indentedReport =
|
||||
, indent 4 "Mine be thy love and thy love’s use their treasure."
|
||||
]
|
||||
|
||||
nestingReport :: Report (Doc AnsiStyle)
|
||||
nestingReport =
|
||||
Err
|
||||
Nothing
|
||||
(nest 4 $ vsep ["Nest...", "foo", "bar", "baz"])
|
||||
[ (Position (1, 15) (1, 16) "test.zc", Maybe a)
|
||||
]
|
||||
[Note b]
|
||||
where
|
||||
a =
|
||||
nest 3 $
|
||||
vsep
|
||||
[ "'What day is it?' asked Pooh."
|
||||
, "'It's today,' squeaked Piglet."
|
||||
, "'My favourite day,' said Pooh."
|
||||
]
|
||||
b =
|
||||
foldr1 (\p q -> nest 2 (vsep [p, q]))
|
||||
[ "It's a very funny thought that, if Bears were Bees,"
|
||||
, "They'd build their nests at the bottom of trees."
|
||||
, "And that being so (if the Bees were Bears),"
|
||||
, "We shouldn't have to climb up all these stairs."
|
||||
]
|
||||
|
||||
errorNoMarkersNoHints :: Report String
|
||||
errorNoMarkersNoHints =
|
||||
Err
|
||||
|
Loading…
Reference in New Issue
Block a user