Skip to content

Commit

Permalink
Display initialization progress
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Mar 15, 2021
1 parent 6636ab4 commit fe00747
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Curry/LanguageServer/Handlers/Initialized.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE OverloadedStrings #-}
module Curry.LanguageServer.Handlers.Initialized (initializedHandler) where

import Control.Monad ((<=<), join)
import Control.Monad ((<=<), join, void, forM_)
import Control.Monad.IO.Class (liftIO)
import qualified Curry.LanguageServer.Compiler as C
import Curry.LanguageServer.FileLoader (fileLoader)
Expand All @@ -10,9 +11,11 @@ import qualified Curry.LanguageServer.IndexStore as I
import Curry.LanguageServer.Monad
import Data.Default (Default (..))
import Data.Maybe (maybeToList, fromMaybe)
import qualified Data.Text as T
import qualified Language.LSP.Server as S
import qualified Language.LSP.Types as J
import qualified Language.LSP.Types.Lens as J
import System.FilePath (takeFileName)
import System.Log.Logger

initializedHandler :: S.Handlers LSM
Expand All @@ -21,7 +24,15 @@ initializedHandler = S.notificationHandler J.SInitialized $ \_nt -> do
liftIO $ infoM "cls.initialized" "Building index store..."
workspaceFolders <- fromMaybe [] <$> S.getWorkspaceFolders
let folders = maybeToList . folderToPath =<< workspaceFolders
mapM_ addDirToIndexStore folders
folderCount = length folders

void $ S.withProgress "Curry: Adding folders" S.Cancellable $ \update ->
forM_ (zip [0..] folders) $ \(i, fp) -> do
let percent = (i * 100) `div` folderCount
msg = T.pack $ "[" ++ show (i + 1) ++ " of " ++ show folderCount ++ "] " ++ takeFileName fp
update (S.ProgressAmount (Just $ fromIntegral percent) $ Just msg)
addDirToIndexStore fp

count <- I.getModuleCount
liftIO $ infoM "cls.initialized" $ "Indexed " ++ show count ++ " files"
where folderToPath (J.WorkspaceFolder uri _) = J.uriToFilePath $ J.Uri uri
Expand Down

0 comments on commit fe00747

Please sign in to comment.