From 46492a19b0d023683baf4154302ae15d25faebdb Mon Sep 17 00:00:00 2001 From: Naohiro Aota Date: Thu, 30 Jan 2014 21:21:40 +0900 Subject: [PATCH] Expose packages in sandbox with their ids This commit implement scaning a package db directory to collect package id If you installed a package both in a sandbox and globally, global package may be selected even if there's a package in a sandbox, which is different behavior from cabal sandbox. e.g. when you have fast-logger-2.0 globally and fast-logger-0.3.3 in a sandbox: (Without patch) $ ghc-mod check Foundation.hs Foundation.hs:12:31:Module `System.Log.FastLogger' does not export `Logger' (With patch) $ ghc-mod check Foundation.hs --- Language/Haskell/GhcMod/Cradle.hs | 38 +------------------------------ 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/Language/Haskell/GhcMod/Cradle.hs b/Language/Haskell/GhcMod/Cradle.hs index 780ff71..30b9a83 100644 --- a/Language/Haskell/GhcMod/Cradle.hs +++ b/Language/Haskell/GhcMod/Cradle.hs @@ -145,40 +145,4 @@ extractGhcVer dir = ver -- | Obtaining packages installed in a package db directory. getPackageDbPackages :: FilePath -> IO [Package] -getPackageDbPackages cdir = (getPkgDb >>= listDbPackages) `E.catch` handler - where - getPkgDb = getPackageDbDir (cdir configFile) - handler :: SomeException -> IO [Package] - handler _ = return [] - -listDbPackages :: FilePath -> IO [Package] -listDbPackages pkgdir = do - files <- filter (".conf" `isSuffixOf`) <$> getDirectoryContents pkgdir - mapM extractPackage $ map (pkgdir ) files - -extractPackage :: FilePath -> IO Package -extractPackage pconf = do - contents <- lines <$> readFile pconf - -- Be strict to ensure that an error can be caught. - let !name = extractName $ parseName contents - !pid = extractId $ parseId contents - return (name, Just pid) - where - parseName = parse nameKey - extractName = extract nameKeyLength - parseId = parse idKey - extractId = extract idKeyLength - parse key = head . filter (key `isPrefixOf`) - extract keylen = fst . break isSpace . dropWhile isSpace . drop keylen - -nameKey :: String -nameKey = "name:" - -idKey :: String -idKey = "id:" - -nameKeyLength :: Int -nameKeyLength = length nameKey - -idKeyLength :: Int -idKeyLength = length idKey +getPackageDbPackages _ = return []