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
This commit is contained in:
parent
04022ab0ac
commit
46492a19b0
@ -145,40 +145,4 @@ extractGhcVer dir = ver
|
|||||||
|
|
||||||
-- | Obtaining packages installed in a package db directory.
|
-- | Obtaining packages installed in a package db directory.
|
||||||
getPackageDbPackages :: FilePath -> IO [Package]
|
getPackageDbPackages :: FilePath -> IO [Package]
|
||||||
getPackageDbPackages cdir = (getPkgDb >>= listDbPackages) `E.catch` handler
|
getPackageDbPackages _ = return []
|
||||||
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
|
|
||||||
|
Loading…
Reference in New Issue
Block a user