Skip to content

Commit a2a84a9

Browse files
committed
Clean up previous entries in the exports map when updating it
1 parent e1a08fb commit a2a84a9

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

ghcide/src/Development/IDE/Core/OfInterest.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ kick = do
113113
-- Update the exports map
114114
results <- uses GenerateCore files <* uses GetHieAst files
115115
let mguts = catMaybes results
116-
!exportsMap' = createExportsMapMg mguts
117-
void $ liftIO $ modifyVar' exportsMap (exportsMap' <>)
116+
void $ liftIO $ modifyVar' exportsMap (updateExportsMapMg mguts)
118117

119118
liftIO $ progressUpdate progress KickCompleted
120119

ghcide/src/Development/IDE/Types/Exports.hs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Development.IDE.Types.Exports
1010
buildModuleExportMapFrom,
1111
createExportsMapHieDb,
1212
size,
13+
updateExportsMapMg
1314
) where
1415

1516
import Control.DeepSeq (NFData (..))
@@ -30,11 +31,23 @@ import HieDb
3031

3132

3233
data ExportsMap = ExportsMap
33-
{getExportsMap :: HashMap IdentifierText (HashSet IdentInfo)
34-
, getModuleExportsMap :: Map.HashMap ModuleNameText (HashSet IdentInfo)
34+
{ getExportsMap :: HashMap IdentifierText (HashSet IdentInfo)
35+
, getModuleExportsMap :: HashMap ModuleNameText (HashSet IdentInfo)
3536
}
3637
deriving (Show)
3738

39+
deleteEntriesForModule :: ModuleNameText -> ExportsMap -> ExportsMap
40+
deleteEntriesForModule m em = ExportsMap
41+
{ getExportsMap =
42+
let moduleIds = Map.lookupDefault mempty m (getModuleExportsMap em)
43+
in deleteAll
44+
(rendered <$> Set.toList moduleIds)
45+
(getExportsMap em)
46+
, getModuleExportsMap = Map.delete m (getModuleExportsMap em)
47+
}
48+
where
49+
deleteAll keys map = foldr Map.delete map keys
50+
3851
size :: ExportsMap -> Int
3952
size = sum . map length . elems . getExportsMap
4053

@@ -119,6 +132,15 @@ createExportsMapMg modGuts = do
119132
let getModuleName = moduleName $ mg_module mi
120133
concatMap (fmap (second Set.fromList) . unpackAvail getModuleName) (mg_exports mi)
121134

135+
updateExportsMapMg :: [ModGuts] -> ExportsMap -> ExportsMap
136+
updateExportsMapMg modGuts old =
137+
old' <> new
138+
where
139+
new = createExportsMapMg modGuts
140+
old' = deleteAll old (Map.keys $ getModuleExportsMap new)
141+
deleteAll = foldr deleteEntriesForModule
142+
143+
122144
createExportsMapTc :: [TcGblEnv] -> ExportsMap
123145
createExportsMapTc modIface = do
124146
let exportList = concatMap doOne modIface

ghcide/test/exe/Main.hs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4319,7 +4319,25 @@ localCompletionTests = [
43194319
(Position 4 14)
43204320
[("abcd", CiFunction, "abcd", True, False, Nothing)
43214321
,("abcde", CiFunction, "abcde", True, False, Nothing)
4322-
]
4322+
],
4323+
testSessionWait "incomplete entries" $ do
4324+
let src a = "data Data = " <> a
4325+
doc <- createDoc "A.hs" "haskell" $ src "AAA"
4326+
void $ waitForTypecheck doc
4327+
let editA rhs =
4328+
changeDoc doc [TextDocumentContentChangeEvent
4329+
{ _range=Nothing
4330+
, _rangeLength=Nothing
4331+
, _text=src rhs}]
4332+
4333+
editA "AAAA"
4334+
void $ waitForTypecheck doc
4335+
editA "AAAAA"
4336+
void $ waitForTypecheck doc
4337+
4338+
compls <- getCompletions doc (Position 0 15)
4339+
liftIO $ take 2 (map _insertText compls) @?= [Just "AAAAA", Just "ArchAArch64"]
4340+
pure ()
43234341
]
43244342

43254343
nonLocalCompletionTests :: [TestTree]

0 commit comments

Comments
 (0)