module Ide.Plugin.Cabal.Parse
( parseCabalFileContents
  -- * Re-exports
, FilePath
, NonEmpty(..)
, PWarning(..)
, Version
, PError(..)
, Position(..)
, GenericPackageDescription(..)
) where

import qualified Data.ByteString                              as BS
import           Data.List.NonEmpty                           (NonEmpty (..))
import           Distribution.Fields                          (PError (..),
                                                               PWarning (..))
import           Distribution.Fields.ParseResult              (runParseResult)
import           Distribution.PackageDescription.Parsec       (parseGenericPackageDescription)
import           Distribution.Parsec.Position                 (Position (..))
import           Distribution.Types.GenericPackageDescription (GenericPackageDescription (..))
import           Distribution.Types.Version                   (Version)

parseCabalFileContents
  :: BS.ByteString -- ^ UTF-8 encoded bytestring
  -> IO ([PWarning], Either (Maybe Version, NonEmpty PError) GenericPackageDescription)
parseCabalFileContents :: ByteString
-> IO
     ([PWarning],
      Either (Maybe Version, NonEmpty PError) GenericPackageDescription)
parseCabalFileContents ByteString
bs =
  ([PWarning],
 Either (Maybe Version, NonEmpty PError) GenericPackageDescription)
-> IO
     ([PWarning],
      Either (Maybe Version, NonEmpty PError) GenericPackageDescription)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (([PWarning],
  Either (Maybe Version, NonEmpty PError) GenericPackageDescription)
 -> IO
      ([PWarning],
       Either (Maybe Version, NonEmpty PError) GenericPackageDescription))
-> ([PWarning],
    Either (Maybe Version, NonEmpty PError) GenericPackageDescription)
-> IO
     ([PWarning],
      Either (Maybe Version, NonEmpty PError) GenericPackageDescription)
forall a b. (a -> b) -> a -> b
$ ParseResult GenericPackageDescription
-> ([PWarning],
    Either (Maybe Version, NonEmpty PError) GenericPackageDescription)
forall a.
ParseResult a
-> ([PWarning], Either (Maybe Version, NonEmpty PError) a)
runParseResult (ByteString -> ParseResult GenericPackageDescription
parseGenericPackageDescription ByteString
bs)