on master help sign in
Support goto definition on symbols in the module export list (#1801)
commit26d932c14fb6bce5bcdba3a672d6233352632324 authorMoritz Kiefer <moritz.kiefer@purelyfunctional.org> dateFri 21 Jun 2019, 16:07 (7 years ago) parenta590e8d
1 file changed+19−1
src/Development/IDE/Functions/SpanInfo.hs+19−1
src/Development/IDE/Functions/SpanInfo.hs+19−1
@@ -42,13 +42,31 @@ getSpanInfo mods tcm =
4242 ets <- mapM (getTypeLHsExpr tcm) es -- expressions
4343 pts <- mapM (getTypeLPat tcm) ps -- patterns
4444 let imports = importInfo mods
45− let exprs = imports ++ concat bts ++ catMaybes (ets ++ pts)
45+ let exports = getExports tcm
46+ let exprs = exports ++ imports ++ concat bts ++ catMaybes (ets ++ pts)
4647 return (mapMaybe toSpanInfo (sortBy cmp exprs))
4748 where cmp (_,a,_) (_,b,_)
4849 | a `isSubspanOf` b = LT
4950 | b `isSubspanOf` a = GT
5051 | otherwise = EQ
5152
53+getExports :: TypecheckedModule -> [(SpanSource, SrcSpan, Maybe Type)]
54+getExports m
55+ | Just (_, _, Just exports, _) <- renamedSource m =
56+ [ (Named $ unLoc n, getLoc n, Nothing)
57+ | (e, _) <- exports
58+ , n <- ieLNames $ unLoc e
59+ ]
60+getExports _ = []
61+
62+-- | Variant of GHC’s ieNames that produces LIdP instead of IdP
63+ieLNames :: IE pass -> [LIdP pass]
64+ieLNames (IEVar _ n ) = [ieLWrappedName n]
65+ieLNames (IEThingAbs _ n ) = [ieLWrappedName n]
66+ieLNames (IEThingAll _ n ) = [ieLWrappedName n]
67+ieLNames (IEThingWith _ n _ ns _) = ieLWrappedName n : map ieLWrappedName ns
68+ieLNames _ = []
69+
5270-- | Get the name and type of a binding.
5371getTypeLHsBind :: (GhcMonad m)
5472 => TypecheckedModule