@@ -38,8 +38,9 @@ import Prelude hiding ((<$>))
3838
3939import Control.Arrow (first)
4040import Control.Monad.Trans.Except (ExceptT(ExceptT), runExceptT)
41−import Data.List (intersperse, nub, nubBy)
41+import Data.List (intersperse, nub)
4242import Data.Maybe (fromJust, fromMaybe, isJust, listToMaybe)
43+import qualified Data.Set as S
4344import System.Console.Haskeline.MonadException (MonadException(controlIO),
4445 RunIO(RunIO))
4546import System.FilePath (replaceExtension)
@@ -77,9 +78,12 @@ formatMessage w = do
7778 maybeSource <- case messageSource w of
7879 Just src -> pure (Just src)
7980 Nothing -> readSource fc
80− let maybeFormattedSource = maybeSource >>= layoutSource fc (idris_highlightedRegions i)
81+ let maybeFormattedSource = maybeSource >>= layoutSource fc (regions (idris_highlightedRegions i))
8182 return $ layoutMessage (layoutFC fc) maybeFormattedSource (messageText w)
8283 where
84+ regions :: S.Set (FC', OutputAnnotation) -> [(FC, OutputAnnotation)]
85+ regions rs = map (\(FC' a,b) -> (a, b)) $ S.toList rs
86+
8387 fc :: FC
8488 fc = messageExtent w
8589
@@ -359,23 +363,21 @@ prettyDocumentedIst ist (name, ty, docs) =
359363sendParserHighlighting :: Idris ()
360364sendParserHighlighting =
361365 do ist <- getIState
362− let hs = map unwrap . nub . map wrap $ idris_parserHighlights ist
366+ let hs = idris_parserHighlights ist
363367 sendHighlighting hs
364368 ist <- getIState
365− putIState ist {idris_parserHighlights = []}
366− where wrap (fc, a) = (FC' fc, a)
367− unwrap (fc', a) = (unwrapFC fc', a)
369+ putIState ist {idris_parserHighlights = S.empty}
368370
369−sendHighlighting :: [(FC, OutputAnnotation)] -> Idris ()
371+sendHighlighting :: S.Set (FC', OutputAnnotation) -> Idris ()
370372sendHighlighting highlights =
371373 do ist <- getIState
372374 case idris_outputmode ist of
373375 RawOutput _ -> updateIState $
374376 \ist -> ist { idris_highlightedRegions =
375− nubBy canNub $ highlights ++ idris_highlightedRegions ist }
377+ S.union highlights (idris_highlightedRegions ist) }
376378 IdeMode n h ->
377379 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
379381 ] in
380382 case fancier of
381383 [] -> return ()
@@ -386,14 +388,13 @@ sendHighlighting highlights =
386388
387389 where fullFC (FC _ _ _) = True
388390 fullFC _ = False
389− canNub (fA,x) (fB,y) = show fA == show fB && x == y
390391
391392-- | Write the highlighting information to a file, for use in external tools
392393-- or in editors that don't support the IDE protocol
393394writeHighlights :: FilePath -> Idris ()
394395writeHighlights f =
395396 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)
397398 let hfile = replaceExtension f "idh"
398399 let annots = toSExp [ (fc, fancifyAnnots ist False annot)
399400 | (fc@(FC _ _ _), annot) <- hs
@@ -401,7 +402,7 @@ writeHighlights f =
401402 runIO $ writeFile hfile $ sExpToString annots
402403
403404clearHighlights :: Idris ()
404−clearHighlights = updateIState $ \ist -> ist { idris_highlightedRegions = [] }
405+clearHighlights = updateIState $ \ist -> ist { idris_highlightedRegions = S.empty }
405406
406407renderExternal :: OutputFmt -> Int -> Doc OutputAnnotation -> Idris String
407408renderExternal fmt width doc