@@ -6,7 +6,8 @@ module Development.IDE.Types.Exports
6
6
ExportsMap (.. ),
7
7
createExportsMap,
8
8
createExportsMapMg,
9
- createExportsMapTc
9
+ createExportsMapTc,
10
+ buildModuleExportMapFrom
10
11
,createExportsMapHieDb,size) where
11
12
12
13
import Avail (AvailInfo (.. ))
@@ -30,17 +31,24 @@ import HieDb
30
31
import Name
31
32
import TcRnTypes (TcGblEnv (.. ))
32
33
33
- newtype ExportsMap = ExportsMap
34
- { getExportsMap :: HashMap IdentifierText (HashSet IdentInfo )}
35
- deriving newtype (Monoid , NFData , Show )
34
+
35
+ data ExportsMap = ExportsMap
36
+ { getExportsMap :: HashMap IdentifierText (HashSet IdentInfo )
37
+ , getModuleExportsMap :: Map. HashMap ModuleNameText (HashSet IdentInfo )
38
+ }
39
+ deriving (Show )
36
40
37
41
size :: ExportsMap -> Int
38
42
size = sum . map length . elems . getExportsMap
39
43
40
44
instance Semigroup ExportsMap where
41
- ExportsMap a <> ExportsMap b = ExportsMap $ Map. unionWith (<>) a b
45
+ ExportsMap a b <> ExportsMap c d = ExportsMap (Map. unionWith (<>) a c) (Map. unionWith (<>) b d)
46
+
47
+ instance Monoid ExportsMap where
48
+ mempty = ExportsMap Map. empty Map. empty
42
49
43
50
type IdentifierText = Text
51
+ type ModuleNameText = Text
44
52
45
53
data IdentInfo = IdentInfo
46
54
{ name :: ! OccName
@@ -91,25 +99,34 @@ mkIdentInfos mod (AvailTC _ nn flds)
91
99
]
92
100
93
101
createExportsMap :: [ModIface ] -> ExportsMap
94
- createExportsMap = ExportsMap . Map. fromListWith (<>) . concatMap doOne
102
+ createExportsMap modIface = do
103
+ let exportList = concatMap doOne modIface
104
+ let exportsMap = Map. fromListWith (<>) $ map (\ (a,_,c) -> (a, c)) exportList
105
+ ExportsMap exportsMap $ buildModuleExportMap $ map (\ (_,b,c) -> (b, c)) exportList
95
106
where
96
- doOne mi = concatMap ( fmap (second Set. fromList) . unpackAvail mn) (mi_exports mi)
97
- where
98
- mn = moduleName $ mi_module mi
107
+ doOne modIFace = do
108
+ let getModDetails = unpackAvail $ moduleName $ mi_module modIFace
109
+ concatMap ( fmap (second Set. fromList) . getModDetails) (mi_exports modIFace)
99
110
100
111
createExportsMapMg :: [ModGuts ] -> ExportsMap
101
- createExportsMapMg = ExportsMap . Map. fromListWith (<>) . concatMap doOne
112
+ createExportsMapMg modGuts = do
113
+ let exportList = concatMap doOne modGuts
114
+ let exportsMap = Map. fromListWith (<>) $ map (\ (a,_,c) -> (a, c)) exportList
115
+ ExportsMap exportsMap $ buildModuleExportMap $ map (\ (_,b,c) -> (b, c)) exportList
102
116
where
103
- doOne mi = concatMap ( fmap (second Set. fromList) . unpackAvail mn) (mg_exports mi)
104
- where
105
- mn = moduleName $ mg_module mi
117
+ doOne mi = do
118
+ let getModuleName = moduleName $ mg_module mi
119
+ concatMap ( fmap (second Set. fromList) . unpackAvail getModuleName) (mg_exports mi)
106
120
107
121
createExportsMapTc :: [TcGblEnv ] -> ExportsMap
108
- createExportsMapTc = ExportsMap . Map. fromListWith (<>) . concatMap doOne
122
+ createExportsMapTc modIface = do
123
+ let exportList = concatMap doOne modIface
124
+ let exportsMap = Map. fromListWith (<>) $ map (\ (a,_,c) -> (a, c)) exportList
125
+ ExportsMap exportsMap $ buildModuleExportMap $ map (\ (_,b,c) -> (b, c)) exportList
109
126
where
110
- doOne mi = concatMap ( fmap (second Set. fromList) . unpackAvail mn) (tcg_exports mi)
111
- where
112
- mn = moduleName $ tcg_mod mi
127
+ doOne mi = do
128
+ let getModuleName = moduleName $ tcg_mod mi
129
+ concatMap ( fmap (second Set. fromList) . unpackAvail getModuleName) (tcg_exports mi)
113
130
114
131
nonInternalModules :: ModuleName -> Bool
115
132
nonInternalModules = not . (" .Internal" `isSuffixOf` ) . moduleNameString
@@ -121,7 +138,8 @@ createExportsMapHieDb hiedb = do
121
138
let mn = modInfoName $ hieModInfo m
122
139
mText = pack $ moduleNameString mn
123
140
fmap (wrap . unwrap mText) <$> getExportsForModule hiedb mn
124
- return $ ExportsMap $ Map. fromListWith (<>) (concat idents)
141
+ let exportsMap = Map. fromListWith (<>) (concat idents)
142
+ return $ ExportsMap exportsMap $ buildModuleExportMap (concat idents)
125
143
where
126
144
wrap identInfo = (rendered identInfo, Set. fromList [identInfo])
127
145
-- unwrap :: ExportRow -> IdentInfo
@@ -130,10 +148,35 @@ createExportsMapHieDb hiedb = do
130
148
n = pack (occNameString exportName)
131
149
p = pack . occNameString <$> exportParent
132
150
133
- unpackAvail :: ModuleName -> IfaceExport -> [(Text , [IdentInfo ])]
151
+ unpackAvail :: ModuleName -> IfaceExport -> [(Text , Text , [IdentInfo ])]
134
152
unpackAvail mn
135
153
| nonInternalModules mn = map f . mkIdentInfos mod
136
154
| otherwise = const []
137
155
where
138
156
! mod = pack $ moduleNameString mn
139
- f id @ IdentInfo {.. } = (pack (prettyPrint name), [id ])
157
+ f id @ IdentInfo {.. } = (pack (prettyPrint name), moduleNameText,[id ])
158
+
159
+
160
+ identInfoToKeyVal :: IdentInfo -> (ModuleNameText , IdentInfo )
161
+ identInfoToKeyVal identInfo =
162
+ (moduleNameText identInfo, identInfo)
163
+
164
+ buildModuleExportMap :: [(Text , HashSet IdentInfo )] -> Map. HashMap ModuleNameText (HashSet IdentInfo )
165
+ buildModuleExportMap exportsMap = do
166
+ let lst = concatMap (Set. toList. snd ) exportsMap
167
+ let lstThree = map identInfoToKeyVal lst
168
+ sortAndGroup lstThree
169
+
170
+ buildModuleExportMapFrom :: [ModIface ] -> Map. HashMap Text (HashSet IdentInfo )
171
+ buildModuleExportMapFrom modIfaces = do
172
+ let exports = map extractModuleExports modIfaces
173
+ Map. fromListWith (<>) exports
174
+
175
+ extractModuleExports :: ModIface -> (Text , HashSet IdentInfo )
176
+ extractModuleExports modIFace = do
177
+ let modName = pack $ moduleNameString $ moduleName $ mi_module modIFace
178
+ let functionSet = Set. fromList $ concatMap (mkIdentInfos modName) $ mi_exports modIFace
179
+ (modName, functionSet)
180
+
181
+ sortAndGroup :: [(ModuleNameText , IdentInfo )] -> Map. HashMap ModuleNameText (HashSet IdentInfo )
182
+ sortAndGroup assocs = Map. fromListWith (<>) [(k, Set. fromList [v]) | (k, v) <- assocs]
0 commit comments