ghc-mod find (#203).

This commit is contained in:
Kazu Yamamoto 2014-04-24 21:08:45 +09:00
parent e2369e6772
commit 6cca65b11e
3 changed files with 13 additions and 2 deletions

View File

@ -24,12 +24,14 @@ module Language.Haskell.GhcMod (
, debugInfo
, rootInfo
, packageDoc
, findSymbol
) where
import Language.Haskell.GhcMod.Browse
import Language.Haskell.GhcMod.Check
import Language.Haskell.GhcMod.Cradle
import Language.Haskell.GhcMod.Debug
import Language.Haskell.GhcMod.Find
import Language.Haskell.GhcMod.Flag
import Language.Haskell.GhcMod.Info
import Language.Haskell.GhcMod.Lang

View File

@ -2,14 +2,15 @@
module Language.Haskell.GhcMod.Find where
import Control.Monad (void)
import Data.Function (on)
import Data.List (groupBy, sort)
import Data.Maybe (fromMaybe)
import GHC (Ghc)
import qualified GHC as G
import Language.Haskell.GhcMod
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
#define MIN_VERSION_containers(x,y,z) 1
@ -23,12 +24,18 @@ import qualified Data.Map.Strict as M
import Data.Map (Map)
import qualified Data.Map as M
#endif
import Control.Applicative ((<$>))
-- | Type of key for `SymMdlDb`.
type Symbol = String
-- | Database from 'Symbol' to modules.
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'.
getSymMdlDb :: Ghc SymMdlDb
getSymMdlDb = do

View File

@ -35,6 +35,7 @@ usage = "ghc-mod version " ++ showVersion version ++ "\n"
++ "\t ghc-mod debug" ++ ghcOptHelp ++ "\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 find <symbol>\n"
++ "\t ghc-mod lint [-h opt] <HaskellFile>\n"
++ "\t ghc-mod root\n"
++ "\t ghc-mod doc <module>\n"
@ -114,6 +115,7 @@ main = flip E.catches handlers $ do
"debug" -> debugInfo opt cradle
"info" -> nArgs 3 infoExpr opt cradle cmdArg1 cmdArg3
"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
"root" -> rootInfo opt cradle
"doc" -> nArgs 1 $ packageDoc opt cradle cmdArg1