Continue work on refinement

This commit is contained in:
Alejandro Serrano 2014-07-18 17:09:02 +02:00
parent b21fa674ea
commit 852d742796
1 changed files with 14 additions and 20 deletions

View File

@ -7,6 +7,7 @@ module Language.Haskell.GhcMod.FillSig (
import Data.Char (isSymbol) import Data.Char (isSymbol)
import Data.List (find, intercalate) import Data.List (find, intercalate)
import Data.Maybe (isJust)
import Exception (ghandle, SomeException(..)) import Exception (ghandle, SomeException(..))
import GHC (GhcMonad, Id, ParsedModule(..), TypecheckedModule(..), DynFlags, SrcSpan, Type, GenLocated(L)) import GHC (GhcMonad, Id, ParsedModule(..), TypecheckedModule(..), DynFlags, SrcSpan, Type, GenLocated(L))
import qualified GHC as G import qualified GHC as G
@ -188,33 +189,26 @@ refine :: IOish m
-> Int -- ^ Column number. -> Int -- ^ Column number.
-> Expression -- ^ A Haskell expression. -> Expression -- ^ A Haskell expression.
-> GhcModT m String -> GhcModT m String
refine file lineNo colNo expr = undefined
{-
refine file lineNo colNo expr = ghandle handler body refine file lineNo colNo expr = ghandle handler body
where where
body = inModuleContext file $ \dflag style -> do body = inModuleContext file $ \dflag style -> do
opt <- options opt <- options
modSum <- Gap.fileModSummary file modSum <- Gap.fileModSummary file
ty <- G.exprType expr -- ty <- G.exprType expr -- If involving local bindings, it's not useful
whenFound opt (findVar modSum lineNo colNo) $ \s -> case s of whenFound opt (findVar dflag style modSum lineNo colNo) $ \s -> case s of
loc -> "a" (loc, name, ty) -> (fourInts loc, name)
handler (SomeException _) = emptyResult =<< options handler (SomeException _) = emptyResult =<< options
-- Look for the variable in the specified -- Look for the variable in the specified position
findVar :: GhcMonad m => G.ModSummary -> Int -> Int -> m (SrcSpan, Type) findVar :: GhcMonad m => DynFlags -> PprStyle -> G.ModSummary -> Int -> Int -> m (Maybe (SrcSpan, String, Type))
findVar modSum lineNo colNo = do findVar dflag style modSum lineNo colNo = do
p <- G.parseModule modSum p <- G.parseModule modSum
tcm@TypecheckedModule{tm_typechecked_source = tcs} <- G.typecheckModule p tcm@TypecheckedModule{tm_typechecked_source = tcs} <- G.typecheckModule p
let es = listifySpans tcs (lineNo, colNo) :: [LHsExpr Id] case listifySpans tcs (lineNo, colNo) :: [G.LHsExpr Id] of
ets <- mapM (getType tcm) es e@(L _ (G.HsVar i)):_ -> do tyInfo <- Gap.getType tcm e
return $ catMaybes $ concat [ets, bts, pts] let name = getFnName dflag style i
if isJust tyInfo && (name == "undefined" || head name == '_')
findVar :: GhcMonad m => G.ModSummary -> Int -> Int -> m (Maybe SrcSpan) then let Just (s,t) = tyInfo in return $ Just (s, name, t)
findVar modSum lineNo colNo = do else return Nothing
ParsedModule{pm_parsed_source = ps} <- G.parseModule modSum _ -> return Nothing
-- Inspect the parse tree to find the variable
case listifyParsedSpans ps (lineNo, colNo) :: [G.LHsExpr G.RdrName] of
(L loc (G.HsVar _)):_ -> return $ Just loc
_ -> return Nothing
-}