on master help sign in
Rename to Message
74ddf72Jason Felice
src/Idris/Output.hs+21−21
@@ -14,7 +14,7 @@ module Idris.Output (clearHighlights, emit, idemodePutSExp, iPrintError, iPrintF
14 iRender, iRenderError, iRenderOutput, iRenderResult, iWarn,
14 iRender, iRenderError, iRenderOutput, iRenderResult, iWarn,
15 prettyDocumentedIst, printUndefinedNames, pshow, renderExternal,
15 prettyDocumentedIst, printUndefinedNames, pshow, renderExternal,
16 sendHighlighting, sendParserHighlighting, warnTotality,
16 sendHighlighting, sendParserHighlighting, warnTotality,
17− writeHighlights, OutputDoc(..), Warning(..)) where
17+ writeHighlights, OutputDoc(..), Message(..)) where
18
18
19import Idris.AbsSyntax
19import Idris.AbsSyntax
20import Idris.Colours (hEndColourise, hStartColourise)
20import Idris.Colours (hEndColourise, hStartColourise)
@@ -53,30 +53,30 @@ pshow ist err = displayDecorated (consoleDecorate ist) .
53
53
54type OutputDoc = Doc OutputAnnotation
54type OutputDoc = Doc OutputAnnotation
55
55
56−class Warning a where
56+class Message a where
57− warningExtent :: a -> FC
57+ messageExtent :: a -> FC
58− warningMessage :: a -> OutputDoc
58+ messageText :: a -> OutputDoc
59− warningSource :: a -> Maybe String
59+ messageSource :: a -> Maybe String
60
60
61data Ann = AText String | ATagged OutputAnnotation Ann | ASplit Ann Ann
61data Ann = AText String | ATagged OutputAnnotation Ann | ASplit Ann Ann
62
62
63data Hack = Hack FC OutputDoc
63data Hack = Hack FC OutputDoc
64−instance Warning Hack where
64+instance Message Hack where
65− warningExtent (Hack extent _) = extent
65+ messageExtent (Hack extent _) = extent
66− warningMessage (Hack _ msg) = msg
66+ messageText (Hack _ msg) = msg
67− warningSource _ = Nothing
67+ messageSource _ = Nothing
68
68
69−formatWarning :: Warning w => w -> Idris OutputDoc
69+formatMessage :: Message w => w -> Idris OutputDoc
70−formatWarning w = do
70+formatMessage w = do
71 i <- getIState
71 i <- getIState
72− maybeSource <- case warningSource w of
72+ maybeSource <- case messageSource w of
73 Just src -> pure (Just src)
73 Just src -> pure (Just src)
74 Nothing -> readSource fc
74 Nothing -> readSource fc
75 let maybeFormattedSource = maybeSource >>= layoutSource fc (idris_highlightedRegions i)
75 let maybeFormattedSource = maybeSource >>= layoutSource fc (idris_highlightedRegions i)
76− return $ layoutWarning (layoutFC fc) maybeFormattedSource (warningMessage w)
76+ return $ layoutMessage (layoutFC fc) maybeFormattedSource (messageText w)
77 where
77 where
78 fc :: FC
78 fc :: FC
79− fc = warningExtent w
79+ fc = messageExtent w
80
80
81 layoutFC :: FC -> OutputDoc
81 layoutFC :: FC -> OutputDoc
82 layoutFC fc@(FC fn _ _) | fn /= "" = text (show $ fc) <> colon
82 layoutFC fc@(FC fn _ _) | fn /= "" = text (show $ fc) <> colon
@@ -168,24 +168,24 @@ formatWarning w = do
168 source = line1 <$$> line2 <$$> line3
168 source = line1 <$$> line2 <$$> line3
169 layoutSource _ _ _ = Nothing
169 layoutSource _ _ _ = Nothing
170
170
171− layoutWarning :: OutputDoc -> Maybe OutputDoc -> OutputDoc -> OutputDoc
171+ layoutMessage :: OutputDoc -> Maybe OutputDoc -> OutputDoc -> OutputDoc
172− layoutWarning loc (Just src) err = loc <$$> src <$$> err <$$> empty
172+ layoutMessage loc (Just src) err = loc <$$> src <$$> err <$$> empty
173− layoutWarning loc Nothing err = loc </> err
173+ layoutMessage loc Nothing err = loc </> err
174
174
175iWarn :: FC -> OutputDoc -> Idris ()
175iWarn :: FC -> OutputDoc -> Idris ()
176iWarn fc err = emit $ Hack fc err
176iWarn fc err = emit $ Hack fc err
177
177
178−emit :: Warning w => w -> Idris ()
178+emit :: Message w => w -> Idris ()
179emit w =
179emit w =
180 do i <- getIState
180 do i <- getIState
181 case idris_outputmode i of
181 case idris_outputmode i of
182 RawOutput h ->
182 RawOutput h ->
183− do formattedErr <- formatWarning w
183+ do formattedErr <- formatMessage w
184 err' <- iRender . fmap (fancifyAnnots i True) $ formattedErr
184 err' <- iRender . fmap (fancifyAnnots i True) $ formattedErr
185 hWriteDoc h i err'
185 hWriteDoc h i err'
186 IdeMode n h ->
186 IdeMode n h ->
187− do err' <- iRender . fmap (fancifyAnnots i True) $ warningMessage w
187+ do err' <- iRender . fmap (fancifyAnnots i True) $ messageText w
188− let fc = warningExtent w
188+ let fc = messageExtent w
189 let (str, spans) = displaySpans err'
189 let (str, spans) = displaySpans err'
190 runIO . hPutStrLn h $
190 runIO . hPutStrLn h $
191 convSExp "warning" (fc_fname fc, fc_start fc, fc_end fc, str, spans) n
191 convSExp "warning" (fc_fname fc, fc_start fc, fc_end fc, str, spans) n
src/Idris/Parser.hs+1−1
@@ -1519,7 +1519,7 @@ parseProg syn fname input mrk
1519 case runparser mainProg i fname input of
1519 case runparser mainProg i fname input of
1520 Left err -> do emit err
1520 Left err -> do emit err
1521 i <- getIState
1521 i <- getIState
1522− putIState (i { errSpan = Just (warningExtent err) })
1522+ putIState (i { errSpan = Just (messageExtent err) })
1523 return []
1523 return []
1524 Right (x, i) -> do putIState i
1524 Right (x, i) -> do putIState i
1525 reportParserWarnings
1525 reportParserWarnings
src/Idris/Parser/Stack.hs+5−5
@@ -33,7 +33,7 @@ module Idris.Parser.Stack
33where
33where
34
34
35import Idris.Core.TT (FC(..))
35import Idris.Core.TT (FC(..))
36−import Idris.Output (Warning(..))
36+import Idris.Output (Message(..))
37
37
38import Control.Arrow (app)
38import Control.Arrow (app)
39import Control.Monad.State.Strict (StateT(..), evalStateT)
39import Control.Monad.State.Strict (StateT(..), evalStateT)
@@ -64,12 +64,12 @@ runparser p i inputname s =
64
64
65data ParseError = ParseError String (P.ParseError (P.Token String) Void)
65data ParseError = ParseError String (P.ParseError (P.Token String) Void)
66
66
67−instance Warning ParseError where
67+instance Message ParseError where
68− warningExtent (ParseError _ err) = sourcePositionFC pos
68+ messageExtent (ParseError _ err) = sourcePositionFC pos
69 where
69 where
70 (pos NonEmpty.:| _) = P.errorPos err
70 (pos NonEmpty.:| _) = P.errorPos err
71− warningMessage (ParseError _ err) = PP.text . init . P.parseErrorTextPretty $ err
71+ messageText (ParseError _ err) = PP.text . init . P.parseErrorTextPretty $ err
72− warningSource (ParseError src _) = Just src
72+ messageSource (ParseError src _) = Just src
73
73
74-- | A fully formatted parse error, with caret and bar, etc.
74-- | A fully formatted parse error, with caret and bar, etc.
75prettyError :: ParseError -> String
75prettyError :: ParseError -> String