clean up lookupSymbol.

This commit is contained in:
Kazu Yamamoto 2014-07-18 15:13:30 +09:00
parent 6d42354a5b
commit e1d9c3b881
3 changed files with 10 additions and 10 deletions

View File

@ -1,4 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE CPP, BangPatterns #-}
module Language.Haskell.GhcMod.Find
#ifndef SPEC
@ -9,6 +9,7 @@ module Language.Haskell.GhcMod.Find
, lookupSymbol
, dumpSymbol
, findSymbol
, lookupSym
)
#endif
where
@ -69,15 +70,15 @@ packageConfDir = "package.conf.d"
-- | Finding modules to which the symbol belong.
findSymbol :: IOish m => Symbol -> GhcModT m String
findSymbol sym = convert' =<< lookupSymbol' sym <$> liftIO loadSymbolDb
lookupSymbol' :: Symbol -> SymbolDb -> [ModuleString]
lookupSymbol' sym (SymbolDb db) = fromMaybe [] (M.lookup sym db)
findSymbol sym = liftIO loadSymbolDb >>= lookupSymbol sym
-- | Looking up 'SymbolDb' with 'Symbol' to \['ModuleString'\]
-- which will be concatenated.
lookupSymbol :: Options -> Symbol -> SymbolDb -> String
lookupSymbol opt sym db = convert opt $ lookupSymbol' sym db
lookupSymbol :: IOish m => Symbol -> SymbolDb -> GhcModT m String
lookupSymbol sym db = convert' $ lookupSym sym db
lookupSym :: Symbol -> SymbolDb -> [ModuleString]
lookupSym sym (SymbolDb db) = fromMaybe [] $ M.lookup sym db
---------------------------------------------------------------

View File

@ -190,8 +190,7 @@ findSym :: IOish m => Set FilePath -> String -> MVar SymbolDb
-> GhcModT m (String, Bool, Set FilePath)
findSym set sym mvar = do
db <- liftIO $ readMVar mvar
opt <- options
let ret = lookupSymbol opt sym db
ret <- lookupSymbol sym db
return (ret, True, set)
lintStx :: IOish m => Set FilePath

View File

@ -13,4 +13,4 @@ spec = do
describe "db <- loadSymbolDb" $ do
it "lookupSymbol' db \"head\" contains at least `Data.List'" $ do
db <- loadSymbolDb
lookupSymbol' "head" db `shouldContain` ["Data.List"]
lookupSym "head" db `shouldContain` ["Data.List"]