clean up lookupSymbol.
This commit is contained in:
parent
6d42354a5b
commit
e1d9c3b881
@ -1,4 +1,4 @@
|
|||||||
{-# LANGUAGE CPP #-}
|
{-# LANGUAGE CPP, BangPatterns #-}
|
||||||
|
|
||||||
module Language.Haskell.GhcMod.Find
|
module Language.Haskell.GhcMod.Find
|
||||||
#ifndef SPEC
|
#ifndef SPEC
|
||||||
@ -9,6 +9,7 @@ module Language.Haskell.GhcMod.Find
|
|||||||
, lookupSymbol
|
, lookupSymbol
|
||||||
, dumpSymbol
|
, dumpSymbol
|
||||||
, findSymbol
|
, findSymbol
|
||||||
|
, lookupSym
|
||||||
)
|
)
|
||||||
#endif
|
#endif
|
||||||
where
|
where
|
||||||
@ -69,15 +70,15 @@ packageConfDir = "package.conf.d"
|
|||||||
|
|
||||||
-- | Finding modules to which the symbol belong.
|
-- | Finding modules to which the symbol belong.
|
||||||
findSymbol :: IOish m => Symbol -> GhcModT m String
|
findSymbol :: IOish m => Symbol -> GhcModT m String
|
||||||
findSymbol sym = convert' =<< lookupSymbol' sym <$> liftIO loadSymbolDb
|
findSymbol sym = liftIO loadSymbolDb >>= lookupSymbol sym
|
||||||
|
|
||||||
lookupSymbol' :: Symbol -> SymbolDb -> [ModuleString]
|
|
||||||
lookupSymbol' sym (SymbolDb db) = fromMaybe [] (M.lookup sym db)
|
|
||||||
|
|
||||||
-- | Looking up 'SymbolDb' with 'Symbol' to \['ModuleString'\]
|
-- | Looking up 'SymbolDb' with 'Symbol' to \['ModuleString'\]
|
||||||
-- which will be concatenated.
|
-- which will be concatenated.
|
||||||
lookupSymbol :: Options -> Symbol -> SymbolDb -> String
|
lookupSymbol :: IOish m => Symbol -> SymbolDb -> GhcModT m String
|
||||||
lookupSymbol opt sym db = convert opt $ lookupSymbol' sym db
|
lookupSymbol sym db = convert' $ lookupSym sym db
|
||||||
|
|
||||||
|
lookupSym :: Symbol -> SymbolDb -> [ModuleString]
|
||||||
|
lookupSym sym (SymbolDb db) = fromMaybe [] $ M.lookup sym db
|
||||||
|
|
||||||
---------------------------------------------------------------
|
---------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -190,8 +190,7 @@ findSym :: IOish m => Set FilePath -> String -> MVar SymbolDb
|
|||||||
-> GhcModT m (String, Bool, Set FilePath)
|
-> GhcModT m (String, Bool, Set FilePath)
|
||||||
findSym set sym mvar = do
|
findSym set sym mvar = do
|
||||||
db <- liftIO $ readMVar mvar
|
db <- liftIO $ readMVar mvar
|
||||||
opt <- options
|
ret <- lookupSymbol sym db
|
||||||
let ret = lookupSymbol opt sym db
|
|
||||||
return (ret, True, set)
|
return (ret, True, set)
|
||||||
|
|
||||||
lintStx :: IOish m => Set FilePath
|
lintStx :: IOish m => Set FilePath
|
||||||
|
@ -13,4 +13,4 @@ spec = do
|
|||||||
describe "db <- loadSymbolDb" $ do
|
describe "db <- loadSymbolDb" $ do
|
||||||
it "lookupSymbol' db \"head\" contains at least `Data.List'" $ do
|
it "lookupSymbol' db \"head\" contains at least `Data.List'" $ do
|
||||||
db <- loadSymbolDb
|
db <- loadSymbolDb
|
||||||
lookupSymbol' "head" db `shouldContain` ["Data.List"]
|
lookupSym "head" db `shouldContain` ["Data.List"]
|
||||||
|
Loading…
Reference in New Issue
Block a user