@@ -18,6 +18,7 @@ import Control.Monad.Trans.Class (lift)
18
18
import Data.Foldable (for_ )
19
19
import Data.Functor (($>) )
20
20
import qualified Data.HashMap.Strict as HMap
21
+ import Data.Maybe (isJust )
21
22
import qualified Data.Text as T
22
23
import Data.Unique
23
24
import Development.IDE.GHC.Orphans ()
@@ -46,7 +47,6 @@ noProgressReporting = return $ ProgressReporting
46
47
, inProgress = const id
47
48
, progressStop = pure ()
48
49
}
49
-
50
50
data State
51
51
= NotStarted
52
52
| Completed
@@ -65,6 +65,8 @@ updateState _ (Event KickCompleted) st = pure st
65
65
updateState _ StopProgress (Running a) = cancel a $> Stopped
66
66
updateState _ StopProgress st = pure st
67
67
68
+ data InProgress = InProgress { todo , done :: ! Int , current :: ! (HMap. HashMap NormalizedFilePath Int )}
69
+
68
70
-- | A 'ProgressReporting' that enqueues Begin and End notifications in a new
69
71
-- thread, with a grace period (nothing will be sent if 'KickCompleted' arrives
70
72
-- before the end of the grace period).
@@ -76,7 +78,7 @@ delayedProgressReporting
76
78
-> ProgressReportingStyle
77
79
-> IO ProgressReporting
78
80
delayedProgressReporting before after lspEnv optProgressStyle = do
79
- inProgressVar <- newVar ( HMap. empty @ NormalizedFilePath @ Int )
81
+ inProgressVar <- newVar $ InProgress 0 0 mempty
80
82
progressState <- newVar NotStarted
81
83
let progressUpdate event = modifyVar_ progressState $ updateState (mRunLspT lspEnv $ lspShakeProgress inProgressVar) (Event event)
82
84
progressStop = modifyVar_ progressState $ updateState (mRunLspT lspEnv $ lspShakeProgress inProgressVar) StopProgress
@@ -115,9 +117,7 @@ delayedProgressReporting before after lspEnv optProgressStyle = do
115
117
}
116
118
}
117
119
loop id prev = do
118
- current <- liftIO $ readVar inProgress
119
- let done = length $ filter (== 0 ) $ HMap. elems current
120
- let todo = HMap. size current
120
+ InProgress {.. } <- liftIO $ readVar inProgress
121
121
if todo == 0 then loop id 0 else do
122
122
let next = 100 * fromIntegral done / fromIntegral todo
123
123
liftIO $ sleep after
@@ -144,7 +144,15 @@ delayedProgressReporting before after lspEnv optProgressStyle = do
144
144
-- This functions are deliberately eta-expanded to avoid space leaks.
145
145
-- Do not remove the eta-expansion without profiling a session with at
146
146
-- least 1000 modifications.
147
- where f shift = void $ modifyVar' var $ HMap. insertWith (\ _ x -> shift x) file (shift 0 )
147
+ where
148
+ f shift = void $ modifyVar' var $ \ InProgress {.. } ->
149
+ case HMap. alterF alter file current of
150
+ ((prev, new), m') ->
151
+ let todo' = if isJust prev then todo else todo + 1
152
+ done' = if new == 0 then done+ 1 else done
153
+ in InProgress todo' done' m'
154
+ where
155
+ alter x = let x' = maybe (shift 0 ) shift x in ((x,x'), Just x')
148
156
149
157
mRunLspT :: Applicative m => Maybe (LSP. LanguageContextEnv c ) -> LSP. LspT c m () -> m ()
150
158
mRunLspT (Just lspEnv) f = LSP. runLspT lspEnv f
0 commit comments