on master help sign in
Support goto definition on types in type annotations and type signatures (#1845)
0336e41Moritz Kiefer
src/Development/IDE/Spans/AtPoint.hs+3−1
@@ -28,6 +28,7 @@ import DynFlags
28import FastString
28import FastString
29import Name
29import Name
30import Outputable hiding ((<>))
30import Outputable hiding ((<>))
31+import SrcLoc
31
32
32import Control.Monad.Extra
33import Control.Monad.Extra
33import Control.Monad.Trans.Maybe
34import Control.Monad.Trans.Maybe
@@ -98,7 +99,8 @@ locationsAtPoint getHieFile IdeOptions{..} pkgState pos =
98 getSpan (SpanS sp) = pure $ Just sp
99 getSpan (SpanS sp) = pure $ Just sp
99 getSpan (Named name) = case nameSrcSpan name of
100 getSpan (Named name) = case nameSrcSpan name of
100 sp@(RealSrcSpan _) -> pure $ Just sp
101 sp@(RealSrcSpan _) -> pure $ Just sp
101− UnhelpfulSpan _ -> runMaybeT $ do
102+ sp@(UnhelpfulSpan _) -> runMaybeT $ do
103+ guard (sp /= wiredInSrcSpan)
102 -- This case usually arises when the definition is in an external package.
104 -- This case usually arises when the definition is in an external package.
103 -- In this case the interface files contain garbage source spans
105 -- In this case the interface files contain garbage source spans
104 -- so we instead read the .hie files to get useful source spans.
106 -- 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 =
38 bs = listifyAllSpans tcs :: [LHsBind GhcTc]
38 bs = listifyAllSpans tcs :: [LHsBind GhcTc]
39 es = listifyAllSpans tcs :: [LHsExpr GhcTc]
39 es = listifyAllSpans tcs :: [LHsExpr GhcTc]
40 ps = listifyAllSpans' tcs :: [Pat GhcTc]
40 ps = listifyAllSpans' tcs :: [Pat GhcTc]
41+ ts = listifyAllSpans $ tm_renamed_source tcm :: [LHsType GhcRn]
41 bts <- mapM (getTypeLHsBind tcm) bs -- binds
42 bts <- mapM (getTypeLHsBind tcm) bs -- binds
42 ets <- mapM (getTypeLHsExpr tcm) es -- expressions
43 ets <- mapM (getTypeLHsExpr tcm) es -- expressions
43 pts <- mapM (getTypeLPat tcm) ps -- patterns
44 pts <- mapM (getTypeLPat tcm) ps -- patterns
45+ tts <- mapM (getLHsType tcm) ts -- types
44 let imports = importInfo mods
46 let imports = importInfo mods
45 let exports = getExports tcm
47 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)
47 return (mapMaybe toSpanInfo (sortBy cmp exprs))
49 return (mapMaybe toSpanInfo (sortBy cmp exprs))
48 where cmp (_,a,_) (_,b,_)
50 where cmp (_,a,_) (_,b,_)
49 | a `isSubspanOf` b = LT
51 | a `isSubspanOf` b = LT
@@ -113,6 +115,14 @@ getTypeLPat _ pat =
113 (Named (dataConName dc), spn)
115 (Named (dataConName dc), spn)
114 getSpanSource _ = (NoSource, noSrcSpan)
116 getSpanSource _ = (NoSource, noSrcSpan)
115
117
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+
116importInfo :: [(Located ModuleName, Maybe NormalizedFilePath)]
126importInfo :: [(Located ModuleName, Maybe NormalizedFilePath)]
117 -> [(SpanSource, SrcSpan, Maybe Type)]
127 -> [(SpanSource, SrcSpan, Maybe Type)]
118importInfo = mapMaybe (uncurry wrk) where
128importInfo = mapMaybe (uncurry wrk) where
@@ -126,8 +136,7 @@ importInfo = mapMaybe (uncurry wrk) where
126 fpToSpanSource fp = SpanS $ RealSrcSpan $ zeroSpan $ mkFastString fp
136 fpToSpanSource fp = SpanS $ RealSrcSpan $ zeroSpan $ mkFastString fp
127
137
128-- | Get ALL source spans in the source.
138-- | Get ALL source spans in the source.
129−listifyAllSpans :: Typeable a
139+listifyAllSpans :: (Typeable a, Data m) => m -> [Located a]
130− => TypecheckedSource -> [Located a]
131listifyAllSpans tcs =
140listifyAllSpans tcs =
132 Data.Generics.listify p tcs
141 Data.Generics.listify p tcs
133 where p (L spn _) = isGoodSrcSpan spn
142 where p (L spn _) = isGoodSrcSpan spn