on master help sign in
Position is no longer reported twice
18c98cbJorge Acereda
src/Idris/Output.hs+4−3
@@ -75,9 +75,10 @@ instance Message SimpleWarning where
75formatMessage :: Message w => w -> Idris OutputDoc
75formatMessage :: Message w => w -> Idris OutputDoc
76formatMessage w = do
76formatMessage w = do
77 i <- getIState
77 i <- getIState
78− maybeSource <- case messageSource w of
78+ rs <- readSource fc
79+ let maybeSource = case rs of
79− Just src -> pure (Just src)
80+ Just src -> Just src
80− Nothing -> readSource fc
81+ Nothing -> messageSource w
81 let maybeFormattedSource = maybeSource >>= layoutSource fc (regions (idris_highlightedRegions i))
82 let maybeFormattedSource = maybeSource >>= layoutSource fc (regions (idris_highlightedRegions i))
82 return $ layoutMessage (layoutFC fc) maybeFormattedSource (messageText w)
83 return $ layoutMessage (layoutFC fc) maybeFormattedSource (messageText w)
83 where
84 where
src/Idris/Parser/Stack.hs+18−8
@@ -62,19 +62,29 @@ runparser p i inputname s =
62
62
63{- * Parse errors -}
63{- * Parse errors -}
64
64
65−newtype ParseError = ParseError (P.ParseErrorBundle String Void)
65+newtype ParseError = ParseError { unParseError :: P.ParseErrorBundle String Void }
66+
67+parseError :: ParseError -> P.ParseError String Void
68+parseError = NonEmpty.head . P.bundleErrors . unParseError
69+
70+parseErrorPosState :: ParseError -> P.PosState String
71+parseErrorPosState = P.bundlePosState . unParseError
72+
73+parseErrorOffset :: ParseError -> Int
74+parseErrorOffset = P.errorOffset . parseError
66
75
67instance Message ParseError where
76instance Message ParseError where
68− messageExtent (ParseError err) = sourcePositionFC pos
77+ messageExtent err = sourcePositionFC pos
78+ where
79+ (pos, _) = P.reachOffsetNoLine (parseErrorOffset err) (parseErrorPosState err)
80+ messageText = PP.text . init . P.parseErrorTextPretty . parseError
81+ messageSource err = Just sline
69 where
82 where
70− (pos, _) = P.reachOffsetNoLine (P.errorOffset err') (P.bundlePosState err)
83+ (_, sline, _) = P.reachOffset (parseErrorOffset err) (parseErrorPosState err)
71− err' = NonEmpty.head . P.bundleErrors $ err
72− messageText (ParseError err) = PP.text . init . P.errorBundlePretty $ err
73− messageSource (ParseError err) = Just . P.sourceName . P.pstateSourcePos . P.bundlePosState $ err
74
84
75-- | A fully formatted parse error, with caret and bar, etc.
85-- | A fully formatted parse error, with caret and bar, etc.
76−prettyError :: ParseError -> String
86+prettyError :: ParseError -> String
77−prettyError (ParseError err) = P.errorBundlePretty err
87+prettyError = P.errorBundlePretty . unParseError
78
88
79{- * Mark and restore -}
89{- * Mark and restore -}
80
90