@@ -15,6 +15,8 @@ import qualified Text.Parser.Token as Tok
1515import qualified Text.Parser.Char as Chr
1616import qualified Text.Parser.Token.Highlight as Hi
1717
18+import Text.PrettyPrint.ANSI.Leijen (Doc, plain)
19+
1820import Idris.AbsSyntax
1921import Idris.DSL
2022import Idris.Imports
@@ -911,6 +913,13 @@ parseImports fname input
911913 i <- get
912914 return ((mname, ps, mrk'), i)
913915
916+-- | There should be a better way of doing this...
917+findFC :: Doc -> (FC, String)
918+findFC x = let s = show (plain x) in
919+ case span (/= ':') s of
920+ (failname, ':':rest) -> case span isDigit rest of
921+ (line, ':':rest') -> (FC failname (read line) 0, drop 2 (dropWhile (/= ':') rest'))
922+
914923-- | A program is a list of declarations, possibly with associated
915924-- documentation strings.
916925parseProg :: SyntaxInfo -> FilePath -> String -> Maybe Delta ->
@@ -919,10 +928,13 @@ parseProg syn fname input mrk
919928 = do i <- getIState
920929 case runparser mainProg i fname input of
921930 Failure doc -> do -- FIXME: Get error location from trifecta
922− --let errl = sourceLine (errorPos err)
931+ -- this can't be the solution!
932+ let (fc, msg) = findFC doc
923933 i <- getIState
924− ihputStrLn (idris_outh i) (show doc)
925− putIState (i { errLine = Just 0 }) -- Just errl })
934+ case idris_outputmode i of
935+ RawOutput -> ihputStrLn (idris_outh i) (show doc)
936+ IdeSlave n -> ihWarn (idris_outh i) fc msg
937+ putIState (i { errLine = Just (fc_line fc) }) -- Just errl })
926938 return []
927939 Success (x, i) -> do putIState i
928940 return $ collect x
@@ -935,34 +947,40 @@ parseProg syn fname input mrk
935947 i' <- get
936948 return (ds, i')
937949
938−{- | Load idris module -}
950+{- | Load idris module and show error if something wrong happens -}
939951loadModule :: Handle -> FilePath -> Idris String
940952loadModule outh f
941− = idrisCatch (do i <- getIState
942− let file = takeWhile (/= ' ') f
943− ibcsd <- valIBCSubDir i
944− ids <- allImportDirs
945− fp <- liftIO $ findImport ids ibcsd file
946− if file `elem` imported i
947− then iLOG $ "Already read " ++ file
948− else do putIState (i { imported = file : imported i })
949− case fp of
950− IDR fn -> loadSource outh False fn
951− LIDR fn -> loadSource outh True fn
952− IBC fn src ->
953− idrisCatch (loadIBC fn)
954− (\c -> do iLOG $ fn ++ " failed " ++ show c
955− case src of
956− IDR sfn -> loadSource outh False sfn
957− LIDR sfn -> loadSource outh True sfn)
958− let (dir, fh) = splitFileName file
959− return (dropExtension fh))
953+ = idrisCatch (loadModule' outh f)
960954 (\e -> do setErrLine (getErrLine e)
961955 ist <- getIState
962956 msg <- showErr e
963957 ihputStrLn outh msg
964958 return "")
965959
960+{- | Load idris module -}
961+loadModule' :: Handle -> FilePath -> Idris String
962+loadModule' outh f
963+ = do i <- getIState
964+ let file = takeWhile (/= ' ') f
965+ ibcsd <- valIBCSubDir i
966+ ids <- allImportDirs
967+ fp <- liftIO $ findImport ids ibcsd file
968+ if file `elem` imported i
969+ then iLOG $ "Already read " ++ file
970+ else do putIState (i { imported = file : imported i })
971+ case fp of
972+ IDR fn -> loadSource outh False fn
973+ LIDR fn -> loadSource outh True fn
974+ IBC fn src ->
975+ idrisCatch (loadIBC fn)
976+ (\c -> do iLOG $ fn ++ " failed " ++ show c
977+ case src of
978+ IDR sfn -> loadSource outh False sfn
979+ LIDR sfn -> loadSource outh True sfn)
980+ let (dir, fh) = splitFileName file
981+ return (dropExtension fh)
982+
983+
966984{- | Load idris code from file -}
967985loadFromIFile :: Handle -> IFileType -> Idris ()
968986loadFromIFile h i@(IBC fn src)