From 4c23cf9123acf8c8b7751805316c8eb394032700 Mon Sep 17 00:00:00 2001 From: fwcd Date: Mon, 14 Oct 2024 03:24:00 +0200 Subject: [PATCH] Display initialization progress --- src/Curry/LanguageServer/Handlers/Initialized.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Curry/LanguageServer/Handlers/Initialized.hs b/src/Curry/LanguageServer/Handlers/Initialized.hs index e4a80b1..2831bbb 100644 --- a/src/Curry/LanguageServer/Handlers/Initialized.hs +++ b/src/Curry/LanguageServer/Handlers/Initialized.hs @@ -1,6 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} module Curry.LanguageServer.Handlers.Initialized (initializedHandler) where +import Control.Monad (void, forM_) import Curry.LanguageServer.FileLoader (fileLoader) import Curry.LanguageServer.Handlers.Diagnostics (emitDiagnostics) import Curry.LanguageServer.Utils.Logging (infoM) @@ -11,13 +12,22 @@ import qualified Data.Text as T import qualified Language.LSP.Server as S import qualified Language.LSP.Protocol.Types as J import qualified Language.LSP.Protocol.Message as J +import System.FilePath (takeFileName) initializedHandler :: S.Handlers LSM initializedHandler = S.notificationHandler J.SMethod_Initialized $ \_nt -> do infoM "Building index store..." workspaceFolders <- fromMaybe [] <$> S.getWorkspaceFolders let folders = maybeToList . folderToPath =<< workspaceFolders - mapM_ addDirToIndexStore folders + folderCount = length folders + + void $ S.withProgress "Curry: Adding folders" Nothing 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 infoM $ "Indexed " <> T.pack (show count) <> " files" where folderToPath (J.WorkspaceFolder uri _) = J.uriToFilePath uri