@@ -18,6 +18,7 @@ import Control.Monad.Trans.Except (ExceptT (ExceptT), runExceptT)
18import System.Console.Haskeline.MonadException
18import System.Console.Haskeline.MonadException
19 (MonadException (controlIO), RunIO (RunIO))
19 (MonadException (controlIO), RunIO (RunIO))
20import System.IO (stdout, Handle, hPutStrLn)
20import System.IO (stdout, Handle, hPutStrLn)
21+import System.FilePath (replaceExtension)
22import Prelude hiding ((<$>))
23import Prelude hiding ((<$>))
@@ -198,7 +199,9 @@ sendHighlighting :: [(FC, OutputAnnotation)] -> Idris ()
198sendHighlighting highlights =
199sendHighlighting highlights =
199 do ist <- getIState
200 do ist <- getIState
200 case idris_outputmode ist of
201 case idris_outputmode ist of
201− RawOutput _ -> return ()
202+ RawOutput _ -> updateIState $
203+ \ist -> ist { idris_highlightedRegions =
204+ highlights ++ idris_highlightedRegions ist }
202 IdeMode n h ->
205 IdeMode n h ->
203 let fancier = [ toSExp (fc, fancifyAnnots ist False annot)
206 let fancier = [ toSExp (fc, fancifyAnnots ist False annot)
204 | (fc, annot) <- highlights, fullFC fc
207 | (fc, annot) <- highlights, fullFC fc
@@ -213,6 +216,20 @@ sendHighlighting highlights =
213 where fullFC (FC _ _ _) = True
216 where fullFC (FC _ _ _) = True
214 fullFC _ = False
217 fullFC _ = False
219+-- | Write the highlighting information to a file, for use in external tools
220+-- or in editors that don't support the IDE protocol
221+writeHighlights :: FilePath -> Idris ()
224+ let hs = reverse $ idris_highlightedRegions ist
225+ let hfile = replaceExtension f "idh"
226+ let annots = toSExp [ (fc, fancifyAnnots ist False annot)
227+ | (fc@(FC _ _ _), annot) <- hs
229+ runIO $ writeFile hfile $ sExpToString annots
231+clearHighlights :: Idris ()
232+clearHighlights = updateIState $ \ist -> ist { idris_highlightedRegions = [] }
217renderExternal :: OutputFmt -> Int -> Doc OutputAnnotation -> Idris String
234renderExternal :: OutputFmt -> Int -> Doc OutputAnnotation -> Idris String
218renderExternal fmt width doc
235renderExternal fmt width doc