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