ghc-mod 1.11.4 → 1.11.5
raw patch · 7 files changed
+103/−10 lines, 7 files
Files
- Browse.hs +63/−4
- CabalDev.hs +1/−2
- ChangeLog +23/−0
- GHCMod.hs +6/−2
- Types.hs +2/−0
- ghc-mod.cabal +3/−2
- test/BrowseSpec.hs +5/−0
Browse.hs view
@@ -3,10 +3,16 @@ import Control.Applicative import Data.Char import Data.List+import Data.Maybe (fromMaybe) import GHC import GHCApi+import Gap import Name+import Outputable+import TyCon+import Type import Types+import Var ---------------------------------------------------------------- @@ -20,13 +26,66 @@ formatOps = sort . map formatOps' formatOps' x@(s:_) | isAlpha s = x- | otherwise = '(' : x ++ ")"+ | otherwise = "(" ++ name ++ ")" ++ tail_+ where+ (name, tail_) = break isSpace x formatOps' [] = error "formatOps'" browse :: Options -> String -> IO [String] browse opt mdlName = withGHC $ do _ <- initSession0 opt- maybeNamesToStrings <$> lookupModuleInfo+ getModule >>= getModuleInfo >>= listExports where- lookupModuleInfo = findModule (mkModuleName mdlName) Nothing >>= getModuleInfo- maybeNamesToStrings = maybe [] (map getOccString . modInfoExports)+ getModule = findModule (mkModuleName mdlName) Nothing+ listExports Nothing = return []+ listExports (Just mdinfo)+ | detailed opt = processModule mdinfo+ | otherwise = return (processExports mdinfo)++processExports :: ModuleInfo -> [String]+processExports = map getOccString . modInfoExports++processModule :: ModuleInfo -> Ghc [String]+processModule minfo = mapM processName names+ where+ names = modInfoExports minfo+ processName :: Name -> Ghc String+ processName nm = do+ tyInfo <- modInfoLookupName minfo nm+ -- If nothing found, load dependent module and lookup global+ tyResult <- maybe (inOtherModule nm) (return . Just) tyInfo+ return $ fromMaybe (getOccString nm) (tyResult >>= showThing)+ inOtherModule :: Name -> Ghc (Maybe TyThing)+ inOtherModule nm = getModuleInfo (nameModule nm) >> lookupGlobalName nm++showThing :: TyThing -> Maybe String+showThing (AnId i) = Just $ getOccString i ++ " :: " ++ showOutputable (removeForAlls $ varType i)+showThing (ATyCon t) = unwords . toList <$> tyType t+ where+ toList t' = t' : getOccString t : map getOccString (tyConTyVars t)+showThing _ = Nothing++tyType :: TyCon -> Maybe String+tyType typ+ | isAlgTyCon typ+ && not (isNewTyCon typ)+ && not (isClassTyCon typ) = Just "data"+ | isNewTyCon typ = Just "newtype"+ | isClassTyCon typ = Just "class"+ | isSynTyCon typ = Just "type"+ | otherwise = Nothing++removeForAlls :: Type -> Type+removeForAlls ty = removeForAlls' ty' tty'+ where+ ty' = dropForAlls ty+ tty' = splitFunTy_maybe ty'++removeForAlls' :: Type -> Maybe (Type, Type) -> Type+removeForAlls' ty Nothing = ty+removeForAlls' ty (Just (pre, ftype))+ | isPredTy pre = mkFunTy pre (dropForAlls ftype)+ | otherwise = ty++showOutputable :: Outputable a => a -> String+showOutputable = unwords . lines . showDocForUser neverQualify . ppr
CabalDev.hs view
@@ -44,8 +44,7 @@ else searchIt $ init path where- cabalDir = mpath path- mpath a = joinPath a </> "cabal-dev/"+ cabalDir = joinPath path </> "cabal-dev/" findConf :: FilePath -> IO FilePath findConf path = do
+ ChangeLog view
@@ -0,0 +1,23 @@+2013-03-01 v1.11.5++ * New option "-d" for "ghc-mod brouse" to show symbols with type+ info (@moidex)++2013-02-15 v1.11.4++ * Adding Hspec test suite+ * Better way to show Extension (@eagletmt)+ * Removing the library itself from Cabal dependencies++2012-12-11 v1.11.3++ * Display a filname instead of "Dummy" if an error occur++2012-10-30 v1.11.2++ * Extract dependencies from a Cabal file if exists and specify+ them to "ghc-mod check" (@khibino)++2012-10-19 v1.11.1++ * Supporting GHC 7.6.x (@cartazio, @dysinger, @ihameed)
GHCMod.hs view
@@ -33,7 +33,7 @@ ++ "\t ghc-mod list" ++ ghcOptHelp ++ "[-l]\n" ++ "\t ghc-mod lang [-l]\n" ++ "\t ghc-mod flag [-l]\n"- ++ "\t ghc-mod browse" ++ ghcOptHelp ++ "[-l] [-o] <module> [<module> ...]\n"+ ++ "\t ghc-mod browse" ++ ghcOptHelp ++ "[-l] [-o] [-d] <module> [<module> ...]\n" ++ "\t ghc-mod check" ++ ghcOptHelp ++ "<HaskellFile>\n" ++ "\t ghc-mod expand" ++ ghcOptHelp ++ "<HaskellFile>\n" ++ "\t ghc-mod info" ++ ghcOptHelp ++ "<HaskellFile> <module> <expression>\n"@@ -57,6 +57,9 @@ , Option "o" ["operators"] (NoArg (\opts -> opts { operators = True })) "print operators, too"+ , Option "d" ["detailed"]+ (NoArg (\opts -> opts { detailed = True }))+ "print detailed info" , Option "s" ["sandbox"] (ReqArg (\s opts -> opts { sandbox = Just s }) "path") "specify cabal-dev sandbox (default 'cabal-dev`)"@@ -83,7 +86,8 @@ main = flip catches handlers $ do args <- getArgs let (opt',cmdArg) = parseArgs argspec args- res <- modifyOptions opt' >>= \opt -> case safelist cmdArg 0 of+ opt <- modifyOptions opt'+ res <- case safelist cmdArg 0 of "browse" -> concat <$> mapM (browseModule opt) (tail cmdArg) "list" -> listModules opt "check" -> withFile (checkSyntax opt) (safelist cmdArg 1)
Types.hs view
@@ -9,6 +9,7 @@ , hlintOpts :: [String] , ghcOpts :: [String] , operators :: Bool+ , detailed :: Bool , expandSplice :: Bool , sandbox :: Maybe String }@@ -19,6 +20,7 @@ , hlintOpts = [] , ghcOpts = [] , operators = False+ , detailed = False , expandSplice = False , sandbox = Nothing }
ghc-mod.cabal view
@@ -1,5 +1,5 @@ Name: ghc-mod-Version: 1.11.4+Version: 1.11.5 Author: Kazu Yamamoto <kazu@iij.ad.jp> Maintainer: Kazu Yamamoto <kazu@iij.ad.jp> License: BSD3@@ -25,7 +25,8 @@ Data-Files: Makefile ghc.el ghc-func.el ghc-doc.el ghc-comp.el ghc-flymake.el ghc-command.el ghc-info.el ghc-ins-mod.el ghc-indent.el-Extra-Source-Files: test/data/*.cabal+Extra-Source-Files: ChangeLog+ test/data/*.cabal test/data/*.hs test/data/ghc-mod-check/*.hs test/data/ghc-mod-check/*.cabal
test/BrowseSpec.hs view
@@ -12,3 +12,8 @@ it "lists up symbols in the module" $ do syms <- lines <$> browseModule defaultOptions "Data.Map" syms `shouldContain` "differenceWithKey"++ describe "browseModule -d" $ do+ it "lists up symbols with type info in the module" $ do+ syms <- lines <$> browseModule defaultOptions { detailed = True } "Data.Either"+ syms `shouldContain` "either :: (a -> c) -> (b -> c) -> Either a b -> c"