@@ -49,7 +49,6 @@ import Development.Shake.Classes
4949import Development.Shake.Rule
5050import qualified Data.HashMap.Strict as HMap
5151import qualified Data.Map.Strict as Map
52−import qualified Data.Map.Merge.Strict as Map
5352import qualified Data.ByteString.Char8 as BS
5453import Data.Dynamic
5554import Data.Maybe
@@ -95,13 +94,13 @@ data ShakeExtras = ShakeExtras
9594 ,state :: Var Values
9695 ,diagnostics :: Var DiagnosticStore
9796 ,hiddenDiagnostics :: Var DiagnosticStore
98− ,publishedDiagnostics :: Var (Map NormalizedUri [Diagnostic])
97+ ,publishedDiagnostics :: Var (HMap.HashMap NormalizedUri [Diagnostic])
9998 -- ^ This represents the set of diagnostics that we have published.
10099 -- Due to debouncing not every change might get published.
101− ,positionMapping :: Var (Map NormalizedUri (Map TextDocumentVersion PositionMapping))
100+ ,positionMapping :: Var (HMap.HashMap NormalizedUri (Map TextDocumentVersion PositionMapping))
102101 -- ^ Map from a text document version to a PositionMapping that describes how to map
103102 -- positions in a version of that document to positions in the latest version
104− ,inProgress :: Var (Map NormalizedFilePath Int)
103+ ,inProgress :: Var (HMap.HashMap NormalizedFilePath Int)
105104 -- ^ How many rules are running for each file
106105 }
107106
@@ -200,14 +199,14 @@ valueVersion = \case
200199 Failed -> Nothing
201200
202201mappingForVersion
203− :: Map NormalizedUri (Map TextDocumentVersion PositionMapping)
202+ :: HMap.HashMap NormalizedUri (Map TextDocumentVersion PositionMapping)
204203 -> NormalizedFilePath
205204 -> TextDocumentVersion
206205 -> PositionMapping
207206mappingForVersion allMappings file ver =
208207 fromMaybe idMapping $
209208 Map.lookup ver =<<
210− Map.lookup (filePathToUri' file) allMappings
209+ HMap.lookup (filePathToUri' file) allMappings
211210
212211type IdeRule k v =
213212 ( Shake.RuleResult k ~ v
@@ -301,14 +300,14 @@ shakeOpen :: IO LSP.LspId
301300 -> Rules ()
302301 -> IO IdeState
303302shakeOpen getLspId eventer logger debouncer shakeProfileDir (IdeReportProgress reportProgress) opts rules = do
304− inProgress <- newVar Map.empty
303+ inProgress <- newVar HMap.empty
305304 shakeExtras <- do
306305 globals <- newVar HMap.empty
307306 state <- newVar HMap.empty
308307 diagnostics <- newVar mempty
309308 hiddenDiagnostics <- newVar mempty
310309 publishedDiagnostics <- newVar mempty
311− positionMapping <- newVar Map.empty
310+ positionMapping <- newVar HMap.empty
312311 pure ShakeExtras{..}
313312 (shakeDb, shakeClose) <-
314313 shakeOpenDatabase
@@ -323,7 +322,7 @@ shakeOpen getLspId eventer logger debouncer shakeProfileDir (IdeReportProgress r
323322 shakeDb <- shakeDb
324323 return IdeState{..}
325324
326−lspShakeProgress :: Show a => IO LSP.LspId -> (LSP.FromServerMessage -> IO ()) -> Var (Map a Int) -> IO ()
325+lspShakeProgress :: Hashable a => IO LSP.LspId -> (LSP.FromServerMessage -> IO ()) -> Var (HMap.HashMap a Int) -> IO ()
327326lspShakeProgress getLspId sendMsg inProgress = do
328327 -- first sleep a bit, so we only show progress messages if it's going to take
329328 -- a "noticable amount of time" (we often expect a thread kill to arrive before the sleep finishes)
@@ -356,8 +355,8 @@ lspShakeProgress getLspId sendMsg inProgress = do
356355 loop id prev = do
357356 sleep sample
358357 current <- readVar inProgress
359− let done = length $ filter (== 0) $ Map.elems current
360− let todo = Map.size current
358+ let done = length $ filter (== 0) $ HMap.elems current
359+ let todo = HMap.size current
361360 let next = Just $ T.pack $ show done <> "/" <> show todo
362361 when (next /= prev) $
363362 sendMsg $ LSP.NotWorkDoneProgressReport $ LSP.fmServerWorkDoneProgressReportNotification
@@ -452,9 +451,9 @@ garbageCollect keep = do
452451 return $! dupe values
453452 modifyVar_ diagnostics $ \diags -> return $! filterDiagnostics keep diags
454453 modifyVar_ hiddenDiagnostics $ \hdiags -> return $! filterDiagnostics keep hdiags
455− modifyVar_ publishedDiagnostics $ \diags -> return $! Map.filterWithKey (\uri _ -> keep (fromUri uri)) diags
454+ modifyVar_ publishedDiagnostics $ \diags -> return $! HMap.filterWithKey (\uri _ -> keep (fromUri uri)) diags
456455 let versionsForFile =
457− Map.fromListWith Set.union $
456+ HMap.fromListWith Set.union $
458457 mapMaybe (\((file, _key), v) -> (filePathToUri' file,) . Set.singleton <$> valueVersion v) $
459458 HMap.toList newState
460459 modifyVar_ positionMapping $ \mappings -> return $! filterVersionMap versionsForFile mappings
@@ -534,9 +533,9 @@ usesWithStale key files = do
534533 mapM (uncurry lastValue) (zip files values)
535534
536535
537−withProgress :: Ord a => Var (Map a Int) -> a -> Action b -> Action b
536+withProgress :: (Eq a, Hashable a) => Var (HMap.HashMap a Int) -> a -> Action b -> Action b
538537withProgress var file = actionBracket (f succ) (const $ f pred) . const
539− where f shift = modifyVar_ var $ return . Map.alter (Just . shift . fromMaybe 0) file
538+ where f shift = modifyVar_ var $ return . HMap.alter (Just . shift . fromMaybe 0) file
540539
541540
542541defineEarlyCutoff
@@ -724,10 +723,10 @@ updateFileDiagnostics fp k ShakeExtras{diagnostics, hiddenDiagnostics, published
724723 let delay = if null newDiags then 0.1 else 0
725724 registerEvent debouncer delay uri $ do
726725 mask_ $ modifyVar_ publishedDiagnostics $ \published -> do
727− let lastPublish = Map.findWithDefault [] uri published
726+ let lastPublish = HMap.lookupDefault [] uri published
728727 when (lastPublish /= newDiags) $
729728 eventer $ publishDiagnosticsNotification (fromNormalizedUri uri) newDiags
730− pure $! Map.insert uri newDiags published
729+ pure $! HMap.insert uri newDiags published
731730
732731publishDiagnosticsNotification :: Uri -> [Diagnostic] -> LSP.FromServerMessage
733732publishDiagnosticsNotification uri diags =
@@ -818,19 +817,18 @@ filterDiagnostics keep =
818817 HMap.filterWithKey (\uri _ -> maybe True (keep . toNormalizedFilePath) $ uriToFilePath' $ fromNormalizedUri uri)
819818
820819filterVersionMap
821− :: Map NormalizedUri (Set.Set TextDocumentVersion)
822− -> Map NormalizedUri (Map TextDocumentVersion a)
823− -> Map NormalizedUri (Map TextDocumentVersion a)
820+ :: HMap.HashMap NormalizedUri (Set.Set TextDocumentVersion)
821+ -> HMap.HashMap NormalizedUri (Map TextDocumentVersion a)
822+ -> HMap.HashMap NormalizedUri (Map TextDocumentVersion a)
824823filterVersionMap =
825− Map.merge Map.dropMissing Map.dropMissing $
826− Map.zipWithMatched $ \_ versionsToKeep versionMap -> Map.restrictKeys versionMap versionsToKeep
824+ HMap.intersectionWith $ \versionsToKeep versionMap -> Map.restrictKeys versionMap versionsToKeep
827825
828826updatePositionMapping :: IdeState -> VersionedTextDocumentIdentifier -> List TextDocumentContentChangeEvent -> IO ()
829827updatePositionMapping IdeState{shakeExtras = ShakeExtras{positionMapping}} VersionedTextDocumentIdentifier{..} changes = do
830828 modifyVar_ positionMapping $ \allMappings -> do
831829 let uri = toNormalizedUri _uri
832− let mappingForUri = Map.findWithDefault Map.empty uri allMappings
830+ let mappingForUri = HMap.lookupDefault Map.empty uri allMappings
833831 let updatedMapping =
834832 Map.insert _version idMapping $
835833 Map.map (\oldMapping -> foldl' applyChange oldMapping changes) mappingForUri
836− pure $! Map.insert uri updatedMapping allMappings
834+ pure $! HMap.insert uri updatedMapping allMappings