Add fromInstalledPackageId
This commit is contained in:
parent
6ad386d31e
commit
77605c6daf
@ -6,6 +6,7 @@ module Language.Haskell.GhcMod.GhcPkg (
|
|||||||
, ghcPkgDbStackOpts
|
, ghcPkgDbStackOpts
|
||||||
, ghcDbStackOpts
|
, ghcDbStackOpts
|
||||||
, ghcDbOpt
|
, ghcDbOpt
|
||||||
|
, fromInstalledPackageId
|
||||||
, getSandboxDb
|
, getSandboxDb
|
||||||
, getPackageDbStack
|
, getPackageDbStack
|
||||||
) where
|
) where
|
||||||
@ -16,7 +17,9 @@ import Control.Exception (SomeException(..))
|
|||||||
import qualified Control.Exception as E
|
import qualified Control.Exception as E
|
||||||
import Data.Char (isSpace,isAlphaNum)
|
import Data.Char (isSpace,isAlphaNum)
|
||||||
import Data.List (isPrefixOf, intercalate)
|
import Data.List (isPrefixOf, intercalate)
|
||||||
|
import Data.List.Split (splitOn)
|
||||||
import Data.Maybe (listToMaybe, maybeToList)
|
import Data.Maybe (listToMaybe, maybeToList)
|
||||||
|
import Distribution.Package (InstalledPackageId(..))
|
||||||
import Language.Haskell.GhcMod.Types
|
import Language.Haskell.GhcMod.Types
|
||||||
import Language.Haskell.GhcMod.Utils
|
import Language.Haskell.GhcMod.Utils
|
||||||
import System.Exit (ExitCode(..))
|
import System.Exit (ExitCode(..))
|
||||||
@ -92,6 +95,13 @@ packageLine l =
|
|||||||
Just ((Hidden,p),_) -> Just p
|
Just ((Hidden,p),_) -> Just p
|
||||||
_ -> Nothing
|
_ -> 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)
|
data PackageState = Normal | Hidden | Broken deriving (Eq,Show)
|
||||||
|
|
||||||
packageLineP :: ReadP (PackageState, Package)
|
packageLineP :: ReadP (PackageState, Package)
|
||||||
|
@ -88,6 +88,7 @@ Library
|
|||||||
, syb
|
, syb
|
||||||
, time
|
, time
|
||||||
, transformers
|
, transformers
|
||||||
|
, split
|
||||||
if impl(ghc < 7.7)
|
if impl(ghc < 7.7)
|
||||||
Build-Depends: convertible
|
Build-Depends: convertible
|
||||||
, Cabal >= 1.10 && < 1.17
|
, Cabal >= 1.10 && < 1.17
|
||||||
@ -159,6 +160,7 @@ Test-Suite spec
|
|||||||
, time
|
, time
|
||||||
, transformers
|
, transformers
|
||||||
, hspec >= 1.8.2
|
, hspec >= 1.8.2
|
||||||
|
, split
|
||||||
if impl(ghc < 7.7)
|
if impl(ghc < 7.7)
|
||||||
Build-Depends: convertible
|
Build-Depends: convertible
|
||||||
, Cabal >= 1.10 && < 1.17
|
, Cabal >= 1.10 && < 1.17
|
||||||
|
Loading…
Reference in New Issue
Block a user