ghc-mod find (#203).
This commit is contained in:
parent
e2369e6772
commit
6cca65b11e
@ -24,12 +24,14 @@ module Language.Haskell.GhcMod (
|
|||||||
, debugInfo
|
, debugInfo
|
||||||
, rootInfo
|
, rootInfo
|
||||||
, packageDoc
|
, packageDoc
|
||||||
|
, findSymbol
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Language.Haskell.GhcMod.Browse
|
import Language.Haskell.GhcMod.Browse
|
||||||
import Language.Haskell.GhcMod.Check
|
import Language.Haskell.GhcMod.Check
|
||||||
import Language.Haskell.GhcMod.Cradle
|
import Language.Haskell.GhcMod.Cradle
|
||||||
import Language.Haskell.GhcMod.Debug
|
import Language.Haskell.GhcMod.Debug
|
||||||
|
import Language.Haskell.GhcMod.Find
|
||||||
import Language.Haskell.GhcMod.Flag
|
import Language.Haskell.GhcMod.Flag
|
||||||
import Language.Haskell.GhcMod.Info
|
import Language.Haskell.GhcMod.Info
|
||||||
import Language.Haskell.GhcMod.Lang
|
import Language.Haskell.GhcMod.Lang
|
||||||
|
@ -2,14 +2,15 @@
|
|||||||
|
|
||||||
module Language.Haskell.GhcMod.Find where
|
module Language.Haskell.GhcMod.Find where
|
||||||
|
|
||||||
|
import Control.Monad (void)
|
||||||
import Data.Function (on)
|
import Data.Function (on)
|
||||||
import Data.List (groupBy, sort)
|
import Data.List (groupBy, sort)
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
import GHC (Ghc)
|
import GHC (Ghc)
|
||||||
import qualified GHC as G
|
import qualified GHC as G
|
||||||
import Language.Haskell.GhcMod
|
|
||||||
import Language.Haskell.GhcMod.Browse (browseAll)
|
import Language.Haskell.GhcMod.Browse (browseAll)
|
||||||
import Language.Haskell.GhcMod.Types (convert)
|
import Language.Haskell.GhcMod.GHCApi
|
||||||
|
import Language.Haskell.GhcMod.Types
|
||||||
|
|
||||||
#ifndef MIN_VERSION_containers
|
#ifndef MIN_VERSION_containers
|
||||||
#define MIN_VERSION_containers(x,y,z) 1
|
#define MIN_VERSION_containers(x,y,z) 1
|
||||||
@ -23,12 +24,18 @@ import qualified Data.Map.Strict as M
|
|||||||
import Data.Map (Map)
|
import Data.Map (Map)
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
#endif
|
#endif
|
||||||
|
import Control.Applicative ((<$>))
|
||||||
|
|
||||||
-- | Type of key for `SymMdlDb`.
|
-- | Type of key for `SymMdlDb`.
|
||||||
type Symbol = String
|
type Symbol = String
|
||||||
-- | Database from 'Symbol' to modules.
|
-- | Database from 'Symbol' to modules.
|
||||||
newtype SymMdlDb = SymMdlDb (Map Symbol [ModuleString])
|
newtype SymMdlDb = SymMdlDb (Map Symbol [ModuleString])
|
||||||
|
|
||||||
|
findSymbol :: Options -> Cradle -> Symbol -> IO String
|
||||||
|
findSymbol opt cradle sym = withGHC' $ do
|
||||||
|
void $ initializeFlagsWithCradle opt cradle [] False
|
||||||
|
lookupSym opt sym <$> getSymMdlDb
|
||||||
|
|
||||||
-- | Creating 'SymMdlDb'.
|
-- | Creating 'SymMdlDb'.
|
||||||
getSymMdlDb :: Ghc SymMdlDb
|
getSymMdlDb :: Ghc SymMdlDb
|
||||||
getSymMdlDb = do
|
getSymMdlDb = do
|
||||||
|
@ -35,6 +35,7 @@ usage = "ghc-mod version " ++ showVersion version ++ "\n"
|
|||||||
++ "\t ghc-mod debug" ++ ghcOptHelp ++ "\n"
|
++ "\t ghc-mod debug" ++ ghcOptHelp ++ "\n"
|
||||||
++ "\t ghc-mod info" ++ ghcOptHelp ++ "<HaskellFile> <module> <expression>\n"
|
++ "\t ghc-mod info" ++ ghcOptHelp ++ "<HaskellFile> <module> <expression>\n"
|
||||||
++ "\t ghc-mod type" ++ ghcOptHelp ++ "<HaskellFile> <module> <line-no> <column-no>\n"
|
++ "\t ghc-mod type" ++ ghcOptHelp ++ "<HaskellFile> <module> <line-no> <column-no>\n"
|
||||||
|
++ "\t ghc-mod find <symbol>\n"
|
||||||
++ "\t ghc-mod lint [-h opt] <HaskellFile>\n"
|
++ "\t ghc-mod lint [-h opt] <HaskellFile>\n"
|
||||||
++ "\t ghc-mod root\n"
|
++ "\t ghc-mod root\n"
|
||||||
++ "\t ghc-mod doc <module>\n"
|
++ "\t ghc-mod doc <module>\n"
|
||||||
@ -114,6 +115,7 @@ main = flip E.catches handlers $ do
|
|||||||
"debug" -> debugInfo opt cradle
|
"debug" -> debugInfo opt cradle
|
||||||
"info" -> nArgs 3 infoExpr opt cradle cmdArg1 cmdArg3
|
"info" -> nArgs 3 infoExpr opt cradle cmdArg1 cmdArg3
|
||||||
"type" -> nArgs 4 $ typeExpr opt cradle cmdArg1 (read cmdArg3) (read cmdArg4)
|
"type" -> nArgs 4 $ typeExpr opt cradle cmdArg1 (read cmdArg3) (read cmdArg4)
|
||||||
|
"find" -> nArgs 1 $ findSymbol opt cradle cmdArg1
|
||||||
"lint" -> nArgs 1 withFile (lintSyntax opt) cmdArg1
|
"lint" -> nArgs 1 withFile (lintSyntax opt) cmdArg1
|
||||||
"root" -> rootInfo opt cradle
|
"root" -> rootInfo opt cradle
|
||||||
"doc" -> nArgs 1 $ packageDoc opt cradle cmdArg1
|
"doc" -> nArgs 1 $ packageDoc opt cradle cmdArg1
|
||||||
|
Loading…
Reference in New Issue
Block a user