diff --git a/Language/Haskell/GhcMod/Find.hs b/Language/Haskell/GhcMod/Find.hs index a8e466d..7b38ae9 100644 --- a/Language/Haskell/GhcMod/Find.hs +++ b/Language/Haskell/GhcMod/Find.hs @@ -24,8 +24,8 @@ import Control.Exception import Control.Concurrent import Data.List import Data.Binary -import Data.ByteString (ByteString) import Data.IORef +import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as LBS import qualified GHC as G import FastString @@ -51,19 +51,19 @@ import System.Directory import System.Directory.ModTime import System.FilePath (()) import System.IO -import System.IO.Unsafe (unsafeInterleaveIO) +import System.IO.Unsafe (unsafeInterleaveIO, unsafePerformIO) import Prelude -import Data.Map.Strict (Map) -import qualified Data.Map.Strict as M +import Data.Map (Map) +import qualified Data.Map as M import Data.Set (Set) import qualified Data.Set as S ---------------------------------------------------------------- -- | Type of function and operation names. -type Symbol = ByteString -type ModuleNameBS = ByteString +type Symbol = BS.ByteString +type ModuleNameBS = BS.ByteString -- | Database from 'Symbol' to \['ModuleString'\]. data SymbolDb = SymbolDb @@ -90,7 +90,7 @@ lookupSymbol :: IOish m => String -> SymbolDb -> GhcModT m String lookupSymbol sym db = convert' $ lookupSym (fastStringToByteString $ mkFastString sym) db lookupSym :: Symbol -> SymbolDb -> [ModuleString] -lookupSym sym db = map (ModuleString . unpackFS . mkFastStringByteString) $ M.findWithDefault [] sym $ table db +lookupSym sym db = map (ModuleString . unpackFS . mkFastStringByteString') $ M.findWithDefault [] sym $ table db --------------------------------------------------------------- @@ -173,6 +173,18 @@ extractBindings (Just inf) mdl = M.fromList $ do mdls = S.singleton $ fastStringToByteString $ moduleNameFS $ moduleName mdl return (sym, mdls) +mkFastStringByteString' :: BS.ByteString -> FastString +#if !MIN_VERSION_ghc(7,8,0) +fastStringToByteString :: FastString -> BS.ByteString +fastStringToByteString = BS.pack . bytesFS + +mkFastStringByteString' = mkFastStringByteList . BS.unpack +#elif __GLASGOW_HASKELL__ == 708 +mkFastStringByteString' = unsafePerformIO . mkFastStringByteString +#else +mkFastStringByteString' = mkFastStringByteString +#endif + ---------------------------------------------------------------- data AsyncSymbolDb = AsyncSymbolDb FilePath (MVar (Either SomeException SymbolDb)) diff --git a/test/FindSpec.hs b/test/FindSpec.hs index 99fe3aa..74f3b85 100644 --- a/test/FindSpec.hs +++ b/test/FindSpec.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE OverloadedStrings #-} module FindSpec where import Language.Haskell.GhcMod.Find