Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 2d13993

Browse files
committed
Remove module lookup, since it can never be a module
1 parent a63cbcc commit 2d13993

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

src/Haskell/Ide/Engine/Plugin/HieExtras.hs

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -555,43 +555,38 @@ findTypeDef uri pos = pluginGetFile "findTypeDef: " uri $ \file ->
555555
(IdeResultOk []) -- Default result
556556
(\info -> do
557557
let rfm = revMap info
558-
mm = moduleMap info
559558
tmap = typeMap info
560559
oldPos = newPosToOld info pos
561560

562-
case (\x -> Just $ getArtifactsAtPos x mm) =<< oldPos of
563-
Just ((_, mn) : _) -> gotoModule rfm mn
564-
_ -> do
565-
let
566-
-- | Get SrcSpan of the name at the given position.
567-
-- If the old position is Nothing, e.g. there is no cached info about it,
568-
-- Nothing is returned.
569-
--
570-
-- Otherwise, searches for the Type of the given position
571-
-- and retrieves its SrcSpan.
572-
getTypeSrcSpanFromPosition
573-
:: Maybe Position -> ExceptT () IdeDeferM SrcSpan
574-
getTypeSrcSpanFromPosition maybeOldPosition = do
575-
oldPosition <- liftMaybe maybeOldPosition
576-
let tmapRes = getArtifactsAtPos oldPosition tmap
577-
case tmapRes of
578-
[] -> throwError ()
579-
a -> do
580-
-- take last type since this is always the most accurate one
581-
tyCon <- liftMaybe $ tyConAppTyCon_maybe (snd $ last a)
582-
case nameSrcSpan (getName tyCon) of
583-
UnhelpfulSpan _ -> throwError ()
584-
realSpan -> return realSpan
585-
586-
liftMaybe :: Monad m => Maybe a -> ExceptT () m a
587-
liftMaybe val = liftEither $ case val of
588-
Nothing -> Left ()
589-
Just s -> Right s
590-
591-
runExceptT (getTypeSrcSpanFromPosition oldPos) >>= \case
592-
Left () -> return $ IdeResultOk []
593-
Right realSpan ->
594-
lift $ srcSpanToFileLocation "hare:findTypeDef" rfm realSpan
561+
-- | Get SrcSpan of the name at the given position.
562+
-- If the old position is Nothing, e.g. there is no cached info about it,
563+
-- Nothing is returned.
564+
--
565+
-- Otherwise, searches for the Type of the given position
566+
-- and retrieves its SrcSpan.
567+
getTypeSrcSpanFromPosition
568+
:: Maybe Position -> ExceptT () IdeDeferM SrcSpan
569+
getTypeSrcSpanFromPosition maybeOldPosition = do
570+
oldPosition <- liftMaybe maybeOldPosition
571+
let tmapRes = getArtifactsAtPos oldPosition tmap
572+
case tmapRes of
573+
[] -> throwError ()
574+
a -> do
575+
-- take last type since this is always the most accurate one
576+
tyCon <- liftMaybe $ tyConAppTyCon_maybe (snd $ last a)
577+
case nameSrcSpan (getName tyCon) of
578+
UnhelpfulSpan _ -> throwError ()
579+
realSpan -> return realSpan
580+
581+
liftMaybe :: Monad m => Maybe a -> ExceptT () m a
582+
liftMaybe val = liftEither $ case val of
583+
Nothing -> Left ()
584+
Just s -> Right s
585+
586+
runExceptT (getTypeSrcSpanFromPosition oldPos) >>= \case
587+
Left () -> return $ IdeResultOk []
588+
Right realSpan ->
589+
lift $ srcSpanToFileLocation "hare:findTypeDef" rfm realSpan
595590
)
596591

597592
-- | Return the definition

0 commit comments

Comments
 (0)