@@ -38,8 +38,9 @@ import Prelude hiding ((<$>))
39import Control.Arrow (first)
39import Control.Arrow (first)
40import Control.Monad.Trans.Except (ExceptT(ExceptT), runExceptT)
40import Control.Monad.Trans.Except (ExceptT(ExceptT), runExceptT)
41−import Data.List (intersperse, nub, nubBy)
41+import Data.List (intersperse, nub)
42import Data.Maybe (fromJust, fromMaybe, isJust, listToMaybe)
42import Data.Maybe (fromJust, fromMaybe, isJust, listToMaybe)
43+import qualified Data.Set as S
43import System.Console.Haskeline.MonadException (MonadException(controlIO),
44import System.Console.Haskeline.MonadException (MonadException(controlIO),
44 RunIO(RunIO))
45 RunIO(RunIO))
45import System.FilePath (replaceExtension)
46import System.FilePath (replaceExtension)
@@ -77,9 +78,12 @@ formatMessage w = do
77 maybeSource <- case messageSource w of
78 maybeSource <- case messageSource w of
78 Just src -> pure (Just src)
79 Just src -> pure (Just src)
79 Nothing -> readSource fc
80 Nothing -> readSource fc
80− let maybeFormattedSource = maybeSource >>= layoutSource fc (idris_highlightedRegions i)
81+ let maybeFormattedSource = maybeSource >>= layoutSource fc (regions (idris_highlightedRegions i))
81 return $ layoutMessage (layoutFC fc) maybeFormattedSource (messageText w)
82 return $ layoutMessage (layoutFC fc) maybeFormattedSource (messageText w)
84+ regions :: S.Set (FC', OutputAnnotation) -> [(FC, OutputAnnotation)]
85+ regions rs = map (\(FC' a,b) -> (a, b)) $ S.toList rs
84 fc = messageExtent w
88 fc = messageExtent w
@@ -359,23 +363,21 @@ prettyDocumentedIst ist (name, ty, docs) =
359sendParserHighlighting :: Idris ()
363sendParserHighlighting :: Idris ()
360sendParserHighlighting =
364sendParserHighlighting =
361 do ist <- getIState
365 do ist <- getIState
362− let hs = map unwrap . nub . map wrap $ idris_parserHighlights ist
366+ let hs = idris_parserHighlights ist
363 sendHighlighting hs
367 sendHighlighting hs
364 ist <- getIState
368 ist <- getIState
365− putIState ist {idris_parserHighlights = []}
369+ putIState ist {idris_parserHighlights = S.empty}
366− where wrap (fc, a) = (FC' fc, a)
367− unwrap (fc', a) = (unwrapFC fc', a)
369−sendHighlighting :: [(FC, OutputAnnotation)] -> Idris ()
371+sendHighlighting :: S.Set (FC', OutputAnnotation) -> Idris ()
370sendHighlighting highlights =
372sendHighlighting highlights =
371 do ist <- getIState
373 do ist <- getIState
372 case idris_outputmode ist of
374 case idris_outputmode ist of
373 RawOutput _ -> updateIState $
375 RawOutput _ -> updateIState $
374 \ist -> ist { idris_highlightedRegions =
376 \ist -> ist { idris_highlightedRegions =
375− nubBy canNub $ highlights ++ idris_highlightedRegions ist }
377+ S.union highlights (idris_highlightedRegions ist) }
376 IdeMode n h ->
378 IdeMode n h ->
377 let fancier = [ toSExp (fc, fancifyAnnots ist False annot)
379 let fancier = [ toSExp (fc, fancifyAnnots ist False annot)
378− | (fc, annot) <- nubBy canNub highlights, fullFC fc
380+ | (FC' fc, annot) <- S.toList highlights, fullFC fc
380 case fancier of
382 case fancier of
381 [] -> return ()
383 [] -> return ()
@@ -386,14 +388,13 @@ sendHighlighting highlights =
387 where fullFC (FC _ _ _) = True
389 where fullFC (FC _ _ _) = True
388 fullFC _ = False
390 fullFC _ = False
389− canNub (fA,x) (fB,y) = show fA == show fB && x == y
391-- | Write the highlighting information to a file, for use in external tools
392-- | Write the highlighting information to a file, for use in external tools
392-- or in editors that don't support the IDE protocol
393-- or in editors that don't support the IDE protocol
393writeHighlights :: FilePath -> Idris ()
394writeHighlights :: FilePath -> Idris ()
394writeHighlights f =
395writeHighlights f =
395 do ist <- getIState
396 do ist <- getIState
396− let hs = reverse $ idris_highlightedRegions ist
397+ let hs = reverse $ map (\(FC' a, b) -> (a,b)) $ S.toList (idris_highlightedRegions ist)
397 let hfile = replaceExtension f "idh"
398 let hfile = replaceExtension f "idh"
398 let annots = toSExp [ (fc, fancifyAnnots ist False annot)
399 let annots = toSExp [ (fc, fancifyAnnots ist False annot)
399 | (fc@(FC _ _ _), annot) <- hs
400 | (fc@(FC _ _ _), annot) <- hs
@@ -401,7 +402,7 @@ writeHighlights f =
401 runIO $ writeFile hfile $ sExpToString annots
402 runIO $ writeFile hfile $ sExpToString annots
403clearHighlights :: Idris ()
404clearHighlights :: Idris ()
404−clearHighlights = updateIState $ \ist -> ist { idris_highlightedRegions = [] }
405+clearHighlights = updateIState $ \ist -> ist { idris_highlightedRegions = S.empty }
406renderExternal :: OutputFmt -> Int -> Doc OutputAnnotation -> Idris String
407renderExternal :: OutputFmt -> Int -> Doc OutputAnnotation -> Idris String
407renderExternal fmt width doc
408renderExternal fmt width doc