diff --git a/Language/Haskell/GhcMod/GhcPkg.hs b/Language/Haskell/GhcMod/GhcPkg.hs index fa915f6..178afd9 100644 --- a/Language/Haskell/GhcMod/GhcPkg.hs +++ b/Language/Haskell/GhcMod/GhcPkg.hs @@ -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) diff --git a/ghc-mod.cabal b/ghc-mod.cabal index 293e365..7141c4b 100644 --- a/ghc-mod.cabal +++ b/ghc-mod.cabal @@ -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