Add fromInstalledPackageId

This commit is contained in:
Daniel Gröber 2014-05-01 01:48:49 +02:00
parent 6ad386d31e
commit 77605c6daf
2 changed files with 12 additions and 0 deletions

View File

@ -6,6 +6,7 @@ module Language.Haskell.GhcMod.GhcPkg (
, ghcPkgDbStackOpts
, ghcDbStackOpts
, ghcDbOpt
, fromInstalledPackageId
, getSandboxDb
, getPackageDbStack
) where
@ -16,7 +17,9 @@ import Control.Exception (SomeException(..))
import qualified Control.Exception as E
import Data.Char (isSpace,isAlphaNum)
import Data.List (isPrefixOf, intercalate)
import Data.List.Split (splitOn)
import Data.Maybe (listToMaybe, maybeToList)
import Distribution.Package (InstalledPackageId(..))
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.Utils
import System.Exit (ExitCode(..))
@ -92,6 +95,13 @@ packageLine l =
Just ((Hidden,p),_) -> Just p
_ -> Nothing
fromInstalledPackageId :: InstalledPackageId -> Maybe Package
fromInstalledPackageId pid = let
InstalledPackageId pkg = pid
in case reverse $ splitOn "-" pkg of
i:v:rest -> Just (intercalate "-" (reverse rest), v, i)
_ -> Nothing
data PackageState = Normal | Hidden | Broken deriving (Eq,Show)
packageLineP :: ReadP (PackageState, Package)

View File

@ -88,6 +88,7 @@ Library
, syb
, time
, transformers
, split
if impl(ghc < 7.7)
Build-Depends: convertible
, Cabal >= 1.10 && < 1.17
@ -159,6 +160,7 @@ Test-Suite spec
, time
, transformers
, hspec >= 1.8.2
, split
if impl(ghc < 7.7)
Build-Depends: convertible
, Cabal >= 1.10 && < 1.17