@@ -49,7 +49,6 @@ import Development.Shake.Classes
49
49
import Development.Shake.Rule
50
50
import qualified Data.HashMap.Strict as HMap
51
51
import qualified Data.Map.Strict as Map
52
- import qualified Data.Map.Merge.Strict as Map
53
52
import qualified Data.ByteString.Char8 as BS
54
53
import Data.Dynamic
55
54
import Data.Maybe
@@ -95,13 +94,13 @@ data ShakeExtras = ShakeExtras
95
94
,state :: Var Values
96
95
,diagnostics :: Var DiagnosticStore
97
96
,hiddenDiagnostics :: Var DiagnosticStore
98
- ,publishedDiagnostics :: Var (Map NormalizedUri [Diagnostic ])
97
+ ,publishedDiagnostics :: Var (HMap. HashMap NormalizedUri [Diagnostic ])
99
98
-- ^ This represents the set of diagnostics that we have published.
100
99
-- 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 ))
102
101
-- ^ Map from a text document version to a PositionMapping that describes how to map
103
102
-- 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 )
105
104
-- ^ How many rules are running for each file
106
105
}
107
106
@@ -200,14 +199,14 @@ valueVersion = \case
200
199
Failed -> Nothing
201
200
202
201
mappingForVersion
203
- :: Map NormalizedUri (Map TextDocumentVersion PositionMapping )
202
+ :: HMap. HashMap NormalizedUri (Map TextDocumentVersion PositionMapping )
204
203
-> NormalizedFilePath
205
204
-> TextDocumentVersion
206
205
-> PositionMapping
207
206
mappingForVersion allMappings file ver =
208
207
fromMaybe idMapping $
209
208
Map. lookup ver =<<
210
- Map .lookup (filePathToUri' file) allMappings
209
+ HMap .lookup (filePathToUri' file) allMappings
211
210
212
211
type IdeRule k v =
213
212
( Shake. RuleResult k ~ v
@@ -301,14 +300,14 @@ shakeOpen :: IO LSP.LspId
301
300
-> Rules ()
302
301
-> IO IdeState
303
302
shakeOpen getLspId eventer logger debouncer shakeProfileDir (IdeReportProgress reportProgress) opts rules = do
304
- inProgress <- newVar Map . empty
303
+ inProgress <- newVar HMap . empty
305
304
shakeExtras <- do
306
305
globals <- newVar HMap. empty
307
306
state <- newVar HMap. empty
308
307
diagnostics <- newVar mempty
309
308
hiddenDiagnostics <- newVar mempty
310
309
publishedDiagnostics <- newVar mempty
311
- positionMapping <- newVar Map . empty
310
+ positionMapping <- newVar HMap . empty
312
311
pure ShakeExtras {.. }
313
312
(shakeDb, shakeClose) <-
314
313
shakeOpenDatabase
@@ -323,7 +322,7 @@ shakeOpen getLspId eventer logger debouncer shakeProfileDir (IdeReportProgress r
323
322
shakeDb <- shakeDb
324
323
return IdeState {.. }
325
324
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 ()
327
326
lspShakeProgress getLspId sendMsg inProgress = do
328
327
-- first sleep a bit, so we only show progress messages if it's going to take
329
328
-- 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
356
355
loop id prev = do
357
356
sleep sample
358
357
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
361
360
let next = Just $ T. pack $ show done <> " /" <> show todo
362
361
when (next /= prev) $
363
362
sendMsg $ LSP. NotWorkDoneProgressReport $ LSP. fmServerWorkDoneProgressReportNotification
@@ -452,9 +451,9 @@ garbageCollect keep = do
452
451
return $! dupe values
453
452
modifyVar_ diagnostics $ \ diags -> return $! filterDiagnostics keep diags
454
453
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
456
455
let versionsForFile =
457
- Map . fromListWith Set. union $
456
+ HMap . fromListWith Set. union $
458
457
mapMaybe (\ ((file, _key), v) -> (filePathToUri' file,) . Set. singleton <$> valueVersion v) $
459
458
HMap. toList newState
460
459
modifyVar_ positionMapping $ \ mappings -> return $! filterVersionMap versionsForFile mappings
@@ -534,9 +533,9 @@ usesWithStale key files = do
534
533
mapM (uncurry lastValue) (zip files values)
535
534
536
535
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
538
537
withProgress 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
540
539
541
540
542
541
defineEarlyCutoff
@@ -724,10 +723,10 @@ updateFileDiagnostics fp k ShakeExtras{diagnostics, hiddenDiagnostics, published
724
723
let delay = if null newDiags then 0.1 else 0
725
724
registerEvent debouncer delay uri $ do
726
725
mask_ $ modifyVar_ publishedDiagnostics $ \ published -> do
727
- let lastPublish = Map. findWithDefault [] uri published
726
+ let lastPublish = HMap. lookupDefault [] uri published
728
727
when (lastPublish /= newDiags) $
729
728
eventer $ publishDiagnosticsNotification (fromNormalizedUri uri) newDiags
730
- pure $! Map . insert uri newDiags published
729
+ pure $! HMap . insert uri newDiags published
731
730
732
731
publishDiagnosticsNotification :: Uri -> [Diagnostic ] -> LSP. FromServerMessage
733
732
publishDiagnosticsNotification uri diags =
@@ -818,19 +817,18 @@ filterDiagnostics keep =
818
817
HMap. filterWithKey (\ uri _ -> maybe True (keep . toNormalizedFilePath) $ uriToFilePath' $ fromNormalizedUri uri)
819
818
820
819
filterVersionMap
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 )
824
823
filterVersionMap =
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
827
825
828
826
updatePositionMapping :: IdeState -> VersionedTextDocumentIdentifier -> List TextDocumentContentChangeEvent -> IO ()
829
827
updatePositionMapping IdeState {shakeExtras = ShakeExtras {positionMapping}} VersionedTextDocumentIdentifier {.. } changes = do
830
828
modifyVar_ positionMapping $ \ allMappings -> do
831
829
let uri = toNormalizedUri _uri
832
- let mappingForUri = Map. findWithDefault Map. empty uri allMappings
830
+ let mappingForUri = HMap. lookupDefault Map. empty uri allMappings
833
831
let updatedMapping =
834
832
Map. insert _version idMapping $
835
833
Map. map (\ oldMapping -> foldl' applyChange oldMapping changes) mappingForUri
836
- pure $! Map . insert uri updatedMapping allMappings
834
+ pure $! HMap . insert uri updatedMapping allMappings
0 commit comments