@@ -40,41 +40,36 @@ import Language.LSP.Server (ProgressAmount (..),
40
40
withProgress )
41
41
import qualified Language.LSP.Server as LSP
42
42
import qualified StmContainers.Map as STM
43
- import UnliftIO (Async , MonadUnliftIO , async ,
44
- bracket , cancel )
43
+ import UnliftIO (Async , async , bracket , cancel )
45
44
46
45
data ProgressEvent
47
46
= ProgressNewStarted
48
47
| ProgressCompleted
49
48
| ProgressStarted
50
49
51
- data ProgressReportingNoTrace m = ProgressReportingNoTrace
52
- { progressUpdateI :: ProgressEvent -> m () ,
50
+ data ProgressReportingNoTrace = ProgressReportingNoTrace
51
+ { progressUpdateI :: ProgressEvent -> IO () ,
53
52
progressStopI :: IO ()
54
53
-- ^ we are using IO here because creating and stopping the `ProgressReporting`
55
54
-- is different from how we use it.
56
55
}
57
56
58
- data ProgressReporting m = ProgressReporting
57
+ data ProgressReporting = ProgressReporting
59
58
{
60
- inProgress :: forall a . NormalizedFilePath -> m a -> m a ,
59
+ inProgress :: forall a . NormalizedFilePath -> IO a -> IO a ,
61
60
-- ^ see Note [ProgressReporting API and InProgressState]
62
- progressReportingInner :: ProgressReportingNoTrace m
61
+ progressReportingInner :: ProgressReportingNoTrace
63
62
}
64
63
65
64
class ProgressReportingClass a where
66
- type M a :: * -> *
67
- progressUpdate :: a -> ProgressEvent -> M a ()
65
+ progressUpdate :: a -> ProgressEvent -> IO ()
68
66
progressStop :: a -> IO ()
69
67
70
- instance ProgressReportingClass (ProgressReportingNoTrace m ) where
71
- type M (ProgressReportingNoTrace m ) = m
68
+ instance ProgressReportingClass ProgressReportingNoTrace where
72
69
progressUpdate = progressUpdateI
73
70
progressStop = progressStopI
74
71
75
- instance ProgressReportingClass (ProgressReporting m ) where
76
- type M (ProgressReporting m ) = m
77
- progressUpdate :: ProgressReporting m -> ProgressEvent -> M (ProgressReporting m ) ()
72
+ instance ProgressReportingClass ProgressReporting where
78
73
progressUpdate = progressUpdateI . progressReportingInner
79
74
progressStop = progressStopI . progressReportingInner
80
75
@@ -91,12 +86,12 @@ The progress of tasks can be tracked in two ways:
91
86
The `inProgress` function is only useful when we are using `ProgressReporting`.
92
87
-}
93
88
94
- noProgressReportingNoTrace :: ( MonadUnliftIO m ) => ( ProgressReportingNoTrace m )
89
+ noProgressReportingNoTrace :: ProgressReportingNoTrace
95
90
noProgressReportingNoTrace = ProgressReportingNoTrace
96
91
{ progressUpdateI = const $ pure () ,
97
92
progressStopI = pure ()
98
93
}
99
- noProgressReporting :: ( MonadUnliftIO m ) => IO ( ProgressReporting m )
94
+ noProgressReporting :: IO ProgressReporting
100
95
noProgressReporting =
101
96
return $
102
97
ProgressReporting
@@ -141,14 +136,13 @@ newInProgress = InProgressState <$> newTVarIO 0 <*> newTVarIO 0 <*> STM.newIO
141
136
recordProgress :: InProgressState -> NormalizedFilePath -> (Int -> Int ) -> IO ()
142
137
recordProgress InProgressState {.. } file shift = do
143
138
(prev, new) <- atomicallyNamed " recordProgress" $ STM. focus alterPrevAndNew file currentVar
144
- atomicallyNamed " recordProgress2" $ do
145
- case (prev, new) of
146
- (Nothing , 0 ) -> modifyTVar' doneVar (+ 1 ) >> modifyTVar' todoVar (+ 1 )
147
- (Nothing , _) -> modifyTVar' todoVar (+ 1 )
148
- (Just 0 , 0 ) -> pure ()
149
- (Just 0 , _) -> modifyTVar' doneVar pred
150
- (Just _, 0 ) -> modifyTVar' doneVar (+ 1 )
151
- (Just _, _) -> pure ()
139
+ atomicallyNamed " recordProgress2" $ case (prev, new) of
140
+ (Nothing , 0 ) -> modifyTVar' doneVar (+ 1 ) >> modifyTVar' todoVar (+ 1 )
141
+ (Nothing , _) -> modifyTVar' todoVar (+ 1 )
142
+ (Just 0 , 0 ) -> pure ()
143
+ (Just 0 , _) -> modifyTVar' doneVar pred
144
+ (Just _, 0 ) -> modifyTVar' doneVar (+ 1 )
145
+ (Just _, _) -> pure ()
152
146
where
153
147
alterPrevAndNew = do
154
148
prev <- Focus. lookup
@@ -162,13 +156,12 @@ recordProgress InProgressState {..} file shift = do
162
156
-- It functions similarly to `progressReporting`, but it utilizes an external state for progress tracking.
163
157
-- Refer to Note [ProgressReporting API and InProgressState] for more details.
164
158
progressReportingNoTrace ::
165
- (MonadUnliftIO m , MonadIO m ) =>
166
159
STM Int ->
167
160
STM Int ->
168
161
Maybe (LSP. LanguageContextEnv c ) ->
169
162
T. Text ->
170
163
ProgressReportingStyle ->
171
- IO ( ProgressReportingNoTrace m )
164
+ IO ProgressReportingNoTrace
172
165
progressReportingNoTrace _ _ Nothing _title _optProgressStyle = return noProgressReportingNoTrace
173
166
progressReportingNoTrace todo done (Just lspEnv) title optProgressStyle = do
174
167
progressState <- newVar NotStarted
@@ -181,19 +174,18 @@ progressReportingNoTrace todo done (Just lspEnv) title optProgressStyle = do
181
174
-- It necessitates the active tracking of progress using the `inProgress` function.
182
175
-- Refer to Note [ProgressReporting API and InProgressState] for more details.
183
176
progressReporting ::
184
- forall c m .
185
- (MonadUnliftIO m , MonadIO m ) =>
186
177
Maybe (LSP. LanguageContextEnv c ) ->
187
178
T. Text ->
188
179
ProgressReportingStyle ->
189
- IO ( ProgressReporting m )
180
+ IO ProgressReporting
190
181
progressReporting Nothing _title _optProgressStyle = noProgressReporting
191
182
progressReporting (Just lspEnv) title optProgressStyle = do
192
183
inProgressState <- newInProgress
193
184
progressReportingInner <- progressReportingNoTrace (readTVar $ todoVar inProgressState)
194
185
(readTVar $ doneVar inProgressState) (Just lspEnv) title optProgressStyle
195
- let inProgress :: forall a . NormalizedFilePath -> m a -> m a
196
- inProgress = updateStateForFile inProgressState
186
+ let
187
+ inProgress :: NormalizedFilePath -> IO a -> IO a
188
+ inProgress = updateStateForFile inProgressState
197
189
return ProgressReporting {.. }
198
190
where
199
191
updateStateForFile inProgress file = UnliftIO. bracket (liftIO $ f succ ) (const $ liftIO $ f pred ) . const
@@ -202,7 +194,7 @@ progressReporting (Just lspEnv) title optProgressStyle = do
202
194
-- Do not remove the eta-expansion without profiling a session with at
203
195
-- least 1000 modifications.
204
196
205
- f shift = recordProgress inProgress file shift
197
+ f = recordProgress inProgress file
206
198
207
199
-- Kill this to complete the progress session
208
200
progressCounter ::
0 commit comments