Skip to content
This repository has been archived by the owner on Apr 25, 2020. It is now read-only.

Commit

Permalink
[imported-from] Add some minimal error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
lierdakil committed Oct 25, 2016
1 parent f5e911b commit f7f4fd8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Language/Haskell/GhcMod/ImportedFrom.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module Language.Haskell.GhcMod.ImportedFrom (importedFrom) where

import Control.Applicative
import Control.Exception
import Control.Monad (zipWithM)
import Data.List
import Data.Maybe
import System.FilePath
Expand Down Expand Up @@ -213,14 +212,19 @@ importedFrom file lineNr colNr symbol =
modSum <- fileModSummaryWithMapping (cradleCurrentDir crdl </> file)
(decls,imports, _exports, _docs) <- fromJustNote "imported-from,importedFrom" . renamedSource <$> (parseModule modSum >>= typecheckModule)
importDescs <- mapM (getModuleDescFromImport . unLoc) imports
let bestids = fmap snd $ headMay $ sortBy (cmp `on` fst) $ findSpanName decls (lineNr, colNr)
idsMods = map (preferExplicit . (\x -> filter ((x `elem`) . mdVisibleExports) importDescs)) <$> bestids
bestids <-
case fmap snd $ headMay $ sortBy (cmp `on` fst) $ findSpanName decls (lineNr, colNr) of
Just x -> return x
Nothing -> error $ "No names found at " ++ show (lineNr, colNr)
let idsMods = map (preferExplicit . (\x -> filter ((x `elem`) . mdVisibleExports) importDescs)) bestids
mbsym = getExpression <$> symbol
fmap (maybe "Nothing found\n" unlines) $ runMaybeT $ do
imps <- lift . mapM modulesWithPackages =<< MaybeT (return idsMods)
bi <- MaybeT $ return bestids
bg <- MaybeT . return $ zipWithM (guessModule mbsym) bi imps
lift $ mapM (uncurry showOutput) bg
imps <- mapM modulesWithPackages idsMods
bg <-
case catMaybes $ zipWith (guessModule mbsym) bestids imps of
[] -> error $ "No modules exporting "
++ fromMaybe (intercalate "," (map (occNameString . getOccName) bestids)) mbsym
x -> return x
unlines <$> mapM (uncurry showOutput) bg
where
handler (SomeException ex) = do
gmLog GmException "imported-from" $ showDoc ex
Expand Down

0 comments on commit f7f4fd8

Please sign in to comment.