Skip to content

Commit

Permalink
Don't repeatedly update the progress (haskell/ghcide#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndmitchell authored and cocreature committed Dec 12, 2019
1 parent 63cae06 commit b9f619b
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions ghcide/src/Development/IDE/Core/Shake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ lspShakeProgress getLspId sendMsg prog = do
sendMsg $ LSP.ReqWorkDoneProgressCreate $ LSP.fmServerWorkDoneProgressCreateRequest
lspId $ LSP.WorkDoneProgressCreateParams
{ _token = u }
bracket_ (start u) (stop u) (loop u)
bracket_ (start u) (stop u) (loop u Nothing)
where
start id = sendMsg $ LSP.NotWorkDoneProgressBegin $ LSP.fmServerWorkDoneProgressBeginNotification
LSP.ProgressParams
Expand All @@ -331,20 +331,23 @@ lspShakeProgress getLspId sendMsg prog = do
}
}
sample = 0.1
loop id = forever $ do
loop id prev = do
sleep sample
p <- prog
let done = countSkipped p + countBuilt p
let todo = done + countUnknown p + countTodo p
sendMsg $ LSP.NotWorkDoneProgressReport $ LSP.fmServerWorkDoneProgressReportNotification
LSP.ProgressParams
{ _token = id
, _value = LSP.WorkDoneProgressReportParams
{ _cancellable = Nothing
, _message = Just $ T.pack $ show done <> "/" <> show todo
, _percentage = Nothing
}
}
let next = Just $ T.pack $ show done <> "/" <> show todo
when (next /= prev) $
sendMsg $ LSP.NotWorkDoneProgressReport $ LSP.fmServerWorkDoneProgressReportNotification
LSP.ProgressParams
{ _token = id
, _value = LSP.WorkDoneProgressReportParams
{ _cancellable = Nothing
, _message = next
, _percentage = Nothing
}
}
loop id next

shakeProfile :: IdeState -> FilePath -> IO ()
shakeProfile IdeState{..} = shakeProfileDatabase shakeDb
Expand Down

0 comments on commit b9f619b

Please sign in to comment.