@@ -1,11 +1,13 @@
1−module Metadata.LoadLibraries (docs) where
1+module Metadata.Load (interfaces) where
3−import Control.DeepSeq (force)
4import qualified Control.Exception as E
3import qualified Control.Exception as E
5import Paths_Elm
4import Paths_Elm
6import System.Directory
5import System.Directory
7import System.FilePath
7import System.FilePath
8import System.IO.Unsafe (unsafePerformIO)
8import System.IO.Unsafe (unsafePerformIO)
9+import SourceSyntax.Module
10-- See stackoverflow discussion for trade-off between using unsafeIO or TemplateHaskell:
12-- See stackoverflow discussion for trade-off between using unsafeIO or TemplateHaskell:
11-- http://stackoverflow.com/questions/12716215/load-pure-global-variable-from-file
13-- http://stackoverflow.com/questions/12716215/load-pure-global-variable-from-file
@@ -13,22 +15,23 @@ import System.IO.Unsafe (unsafePerformIO)
13-- Given the awkwardness of including a compile-time generated file
15-- Given the awkwardness of including a compile-time generated file
14-- vs loading static data, then the unsafeIO seems better.
16-- vs loading static data, then the unsafeIO seems better.
16−{-# NOINLINE docs #-}
18+{-# NOINLINE interfaces #-}
17−docs :: String
19+interfaces :: [ModuleInterface]
18−docs = force $ unsafePerformIO (safeReadDocs =<< getDataFileName "docs.json")
20+interfaces = unsafePerformIO (safeReadDocs =<< getDataFileName "interfaces.data")
20−safeReadDocs :: FilePath -> IO String
22+safeReadDocs :: FilePath -> IO [ModuleInterface]
21−safeReadDocs name = E.catch (readDocs name) (emitError name)
24+ E.catch (readDocs name) $ \err -> do
22−
25+ putStrLn $ unlines [ "Error reading types for standard library!"
26+ , " The file should be located here: " ++ name
27+ , " If you are using a stable version of Elm,"
28+ , " please report an issue at github.com/evancz/Elm"
29+ , " and specify your versions of Elm and your OS" ]
30+ print (err :: IOError)
23−readDocs :: FilePath -> IO String
33+readDocs :: FilePath -> IO [ModuleInterface]
24readDocs name = do
34readDocs name = do
25 exists <- doesFileExist name
35 exists <- doesFileExist name
26− if exists then readFile name
36+ if exists then decodeFile name
27 else ioError . userError $ "File Not Found"
37 else ioError . userError $ "File Not Found"
30−emitError :: FilePath -> IOError -> IO String
31−emitError name err = do
32− putStrLn $ "Error! Types for standard library not loaded properly!\n File should be here:" ++ name ++ "\n The file is created and copied by command: cabal install"
34− return "{\"modules\":[]}"