on master help sign in
Support goto definition on types in type annotations and type signatures (#1845)
commit0336e41d2e395a978f780471fab83c452e2284d4 authorMoritz Kiefer <moritz.kiefer@purelyfunctional.org> dateMon 24 Jun 2019, 14:49 (7 years ago) parentf746db9
2 files changed+15−4
src/Development/IDE/Spans/AtPoint.hs+3−1 src/Development/IDE/Spans/Calculate.hs+12−3
src/Development/IDE/Spans/AtPoint.hs+3−1
@@ -28,6 +28,7 @@ import DynFlags
2828import FastString
2929import Name
3030import Outputable hiding ((<>))
31+import SrcLoc
3132
3233import Control.Monad.Extra
3334import Control.Monad.Trans.Maybe
@@ -98,7 +99,8 @@ locationsAtPoint getHieFile IdeOptions{..} pkgState pos =
9899 getSpan (SpanS sp) = pure $ Just sp
99100 getSpan (Named name) = case nameSrcSpan name of
100101 sp@(RealSrcSpan _) -> pure $ Just sp
101− UnhelpfulSpan _ -> runMaybeT $ do
102+ sp@(UnhelpfulSpan _) -> runMaybeT $ do
103+ guard (sp /= wiredInSrcSpan)
102104 -- This case usually arises when the definition is in an external package.
103105 -- In this case the interface files contain garbage source spans
104106 -- so we instead read the .hie files to get useful source spans.
src/Development/IDE/Spans/Calculate.hs+12−3
@@ -38,12 +38,14 @@ getSpanInfo mods tcm =
3838 bs = listifyAllSpans tcs :: [LHsBind GhcTc]
3939 es = listifyAllSpans tcs :: [LHsExpr GhcTc]
4040 ps = listifyAllSpans' tcs :: [Pat GhcTc]
41+ ts = listifyAllSpans $ tm_renamed_source tcm :: [LHsType GhcRn]
4142 bts <- mapM (getTypeLHsBind tcm) bs -- binds
4243 ets <- mapM (getTypeLHsExpr tcm) es -- expressions
4344 pts <- mapM (getTypeLPat tcm) ps -- patterns
45+ tts <- mapM (getLHsType tcm) ts -- types
4446 let imports = importInfo mods
4547 let exports = getExports tcm
46− let exprs = exports ++ imports ++ concat bts ++ catMaybes (ets ++ pts)
48+ let exprs = exports ++ imports ++ concat bts ++ concat tts ++ catMaybes (ets ++ pts)
4749 return (mapMaybe toSpanInfo (sortBy cmp exprs))
4850 where cmp (_,a,_) (_,b,_)
4951 | a `isSubspanOf` b = LT
@@ -113,6 +115,14 @@ getTypeLPat _ pat =
113115 (Named (dataConName dc), spn)
114116 getSpanSource _ = (NoSource, noSrcSpan)
115117
118+getLHsType
119+ :: GhcMonad m
120+ => TypecheckedModule
121+ -> LHsType GhcRn
122+ -> m [(SpanSource, SrcSpan, Maybe Type)]
123+getLHsType _ (L spn (HsTyVar _ _ v)) = pure [(Named $ unLoc v, spn, Nothing)]
124+getLHsType _ _ = pure []
125+
116126importInfo :: [(Located ModuleName, Maybe NormalizedFilePath)]
117127 -> [(SpanSource, SrcSpan, Maybe Type)]
118128importInfo = mapMaybe (uncurry wrk) where
@@ -126,8 +136,7 @@ importInfo = mapMaybe (uncurry wrk) where
126136 fpToSpanSource fp = SpanS $ RealSrcSpan $ zeroSpan $ mkFastString fp
127137
128138-- | Get ALL source spans in the source.
129−listifyAllSpans :: Typeable a
130− => TypecheckedSource -> [Located a]
139+listifyAllSpans :: (Typeable a, Data m) => m -> [Located a]
131140listifyAllSpans tcs =
132141 Data.Generics.listify p tcs
133142 where p (L spn _) = isGoodSrcSpan spn