module Language.PureScript.Ide.Error
( PscIdeError(..)
) where
import Protolude
import Data.Aeson
import Language.PureScript.Errors.JSON
import Language.PureScript.Ide.Types (ModuleIdent)
import qualified Text.Parsec.Error as P
data PscIdeError
= GeneralError Text
| NotFound Text
| ModuleNotFound ModuleIdent
| ModuleFileNotFound ModuleIdent
| ParseError P.ParseError Text
| RebuildError [JSONError]
instance ToJSON PscIdeError where
toJSON (RebuildError errs) = object
[ "resultType" .= ("error" :: Text)
, "result" .= errs
]
toJSON err = object
[ "resultType" .= ("error" :: Text)
, "result" .= textError err
]
textError :: PscIdeError -> Text
textError (GeneralError msg) = msg
textError (NotFound ident) = "Symbol '" <> ident <> "' not found."
textError (ModuleNotFound ident) = "Module '" <> ident <> "' not found."
textError (ModuleFileNotFound ident) = "Extern file for module " <> ident <>" could not be found"
textError (ParseError parseError msg) = let escape = show
in msg <> ": " <> escape parseError
textError (RebuildError err) = show err