ghc-mod 1.10.4 → 1.10.5
raw patch · 6 files changed
+67/−34 lines, 6 files
Files
- GHCMod.hs +2/−12
- Info.hs +16/−15
- Types.hs +46/−4
- elisp/ghc-info.el +1/−1
- elisp/ghc.el +1/−1
- ghc-mod.cabal +1/−1
GHCMod.hs view
@@ -45,7 +45,7 @@ defaultOptions :: Options defaultOptions = Options {- convert = toPlain+ outputStyle = PlainStyle , hlintOpts = [] , ghcOpts = [] , operators = False@@ -53,7 +53,7 @@ argspec :: [OptDescr (Options -> Options)] argspec = [ Option "l" ["tolisp"]- (NoArg (\opts -> opts { convert = toLisp }))+ (NoArg (\opts -> opts { outputStyle = LispStyle })) "print as a list of Lisp" , Option "h" ["hlintOpt"] (ReqArg (\h opts -> opts { hlintOpts = h : hlintOpts opts }) "hlintOpt")@@ -128,16 +128,6 @@ safelist xs idx | length xs <= idx = throw SafeList | otherwise = xs !! idx-------------------------------------------------------------------toLisp :: [String] -> String-toLisp ms = "(" ++ unwords quoted ++ ")\n"- where- quote x = "\"" ++ x ++ "\""- quoted = map quote ms--toPlain :: [String] -> String-toPlain = unlines ----------------------------------------------------------------
Info.hs view
@@ -7,6 +7,7 @@ import Control.Exception import Control.Monad import CoreUtils+import Data.Function import Data.Generics as G import Data.List import Data.Maybe@@ -42,7 +43,7 @@ ---------------------------------------------------------------- typeExpr :: Options -> ModuleString -> Int -> Int -> FilePath -> IO String-typeExpr opt modstr lineNo colNo file = (++ "\n") <$> Info.typeOf opt file modstr lineNo colNo+typeExpr opt modstr lineNo colNo file = Info.typeOf opt file modstr lineNo colNo typeOf :: Options -> FilePath -> ModuleString -> Int -> Int -> IO String typeOf opt fileName modstr lineNo colNo = inModuleContext opt fileName modstr exprToType@@ -53,26 +54,26 @@ tcm <- typecheckModule p es <- liftIO $ findExpr tcm lineNo colNo ts <- catMaybes <$> mapM (getType tcm) es- let ts' = sortBy (\a b -> fst a `cmp` fst b) ts- return $ tolisp $ map (\(loc, e) -> ("(" ++ l loc ++ " " ++ show (pretty e) ++ ")")) ts'+ let sss = map toTup $ sortBy (cmp `on` fst) ts+ return $ convert opt sss - l :: SrcSpan -> String+ toTup :: (SrcSpan, Type) -> ((Int,Int,Int,Int),String)+ toTup (spn, typ) = (l spn, pretty typ)++ l :: SrcSpan -> (Int,Int,Int,Int) #if __GLASGOW_HASKELL__ >= 702 l (RealSrcSpan spn) #else l spn | isGoodSrcSpan spn #endif- = unwords . map show $- [ srcSpanStartLine spn, srcSpanStartCol spn- , srcSpanEndLine spn, srcSpanEndCol spn ]- l _ = "0 0 0 0"- + = (srcSpanStartLine spn, srcSpanStartCol spn+ , srcSpanEndLine spn, srcSpanEndCol spn)+ l _ = (0,0,0,0)+ cmp a b | a `isSubspanOf` b = O.LT | b `isSubspanOf` a = O.GT | otherwise = O.EQ- - tolisp ls = "(" ++ unwords ls ++ ")" findExpr :: TypecheckedModule -> Int -> Int -> IO [LHsExpr Id] findExpr tcm line col = do@@ -87,7 +88,7 @@ return $ case mret of Left (SomeException _) -> G.empty Right ret -> ret- + f :: LHsExpr Id -> Bool f (L spn _) = spn `spans` (line, col) @@ -133,9 +134,9 @@ $$ show_fixity fixity $$ vcat (map pprInstance insts) where- show_fixity fix- | fix == defaultFixity = Outputable.empty- | otherwise = ppr fix <+> ppr (getName thing)+ show_fixity fx+ | fx == defaultFixity = Outputable.empty+ | otherwise = ppr fx <+> ppr (getName thing) ----------------------------------------------------------------
Types.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE FlexibleInstances #-}+ module Types where import Control.Monad@@ -10,12 +12,52 @@ ---------------------------------------------------------------- +data OutputStyle = LispStyle | PlainStyle+ data Options = Options {- convert :: [String] -> String- , hlintOpts :: [String]- , ghcOpts :: [String]- , operators :: Bool+ outputStyle :: OutputStyle+ , hlintOpts :: [String]+ , ghcOpts :: [String]+ , operators :: Bool }++----------------------------------------------------------------+convert :: ToString a => Options -> a -> String+convert Options{ outputStyle = LispStyle } = toLisp+convert Options{ outputStyle = PlainStyle } = toPlain++class ToString a where+ toLisp :: a -> String+ toPlain :: a -> String++instance ToString [String] where+ toLisp = addNewLine . toSexp True+ toPlain = unlines++instance ToString [((Int,Int,Int,Int),String)] where+ toLisp = addNewLine . toSexp False . map toS+ where+ toS x = "(" ++ tupToString x ++ ")"+ toPlain = unlines . map tupToString++toSexp :: Bool -> [String] -> String+toSexp False ss = "(" ++ unwords ss ++ ")"+toSexp True ss = "(" ++ unwords (map quote ss) ++ ")"++tupToString :: ((Int,Int,Int,Int),String) -> String+tupToString ((a,b,c,d),s) = show a ++ " "+ ++ show b ++ " "+ ++ show c ++ " "+ ++ show d ++ " "+ ++ quote s++quote :: String -> String+quote x = "\"" ++ x ++ "\""++addNewLine :: String -> String+addNewLine = (++ "\n")++---------------------------------------------------------------- withGHC :: (MonadPlus m) => Ghc (m a) -> IO (m a) withGHC body = ghandle ignore $ runGhc (Just libdir) body
elisp/ghc-info.el view
@@ -125,7 +125,7 @@ (lambda () (cd cdir) (apply 'call-process ghc-module-command nil t nil- `(,@(ghc-make-ghc-options) "type" ,file ,modname ,ln ,cn))+ `(,@(ghc-make-ghc-options) "-l" "type" ,file ,modname ,ln ,cn)) (goto-char (point-min)) (while (search-forward "[Char]" nil t) (replace-match "String"))))))
elisp/ghc.el view
@@ -16,7 +16,7 @@ ;;; Code: -(defconst ghc-version "1.10.4")+(defconst ghc-version "1.10.5") ;; (eval-when-compile ;; (require 'haskell-mode))
ghc-mod.cabal view
@@ -1,5 +1,5 @@ Name: ghc-mod-Version: 1.10.4+Version: 1.10.5 Author: Kazu Yamamoto <kazu@iij.ad.jp> Maintainer: Kazu Yamamoto <kazu@iij.ad.jp> License: BSD3