-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from fwcd/initialize-handling
Move initialization into `doInitialize` and report progress
- Loading branch information
Showing
4 changed files
with
23 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 19 additions & 13 deletions
32
...ry/LanguageServer/Handlers/Initialized.hs → ...rry/LanguageServer/Handlers/Initialize.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Curry.LanguageServer.Handlers.Initialized (initializedHandler) where | ||
{-# LANGUAGE DataKinds, OverloadedStrings #-} | ||
module Curry.LanguageServer.Handlers.Initialize (initializeHandler, initializedHandler) where | ||
|
||
import Control.Lens ((^.)) | ||
import Curry.LanguageServer.FileLoader (fileLoader) | ||
import Curry.LanguageServer.Handlers.Diagnostics (emitDiagnostics) | ||
import Curry.LanguageServer.Utils.Logging (infoM) | ||
import qualified Curry.LanguageServer.Index.Store as I | ||
import Curry.LanguageServer.Monad (LSM) | ||
import Data.Maybe (maybeToList, fromMaybe) | ||
import qualified Data.Text as T | ||
import qualified Language.LSP.Server as S | ||
import qualified Language.LSP.Protocol.Lens as J | ||
import qualified Language.LSP.Protocol.Types as J | ||
import qualified Language.LSP.Protocol.Message as J | ||
import qualified Language.LSP.Server as S | ||
|
||
initializeHandler :: J.TMessage J.Method_Initialize -> LSM () | ||
initializeHandler req = do | ||
let token = req ^. J.params . J.workDoneToken | ||
S.withIndefiniteProgress "Initializing Curry..." token S.NotCancellable $ \updater -> do | ||
Check warning on line 20 in src/Curry/LanguageServer/Handlers/Initialize.hs GitHub Actions / build (ubuntu-latest)
Check warning on line 20 in src/Curry/LanguageServer/Handlers/Initialize.hs GitHub Actions / build (macos-latest)
|
||
infoM "Building index store..." | ||
workspaceFolders <- fromMaybe [] <$> S.getWorkspaceFolders | ||
let folderToPath (J.WorkspaceFolder uri _) = J.uriToFilePath uri | ||
folders = maybeToList . folderToPath =<< workspaceFolders | ||
mapM_ addDirToIndexStore folders | ||
count <- I.getModuleCount | ||
infoM $ "Indexed " <> T.pack (show count) <> " files" | ||
|
||
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 | ||
count <- I.getModuleCount | ||
infoM $ "Indexed " <> T.pack (show count) <> " files" | ||
where folderToPath (J.WorkspaceFolder uri _) = J.uriToFilePath uri | ||
entries <- I.getModuleList | ||
mapM_ (uncurry emitDiagnostics) entries | ||
|
||
-- | Indexes a workspace folder recursively. | ||
addDirToIndexStore :: FilePath -> LSM () | ||
addDirToIndexStore dirPath = do | ||
fl <- fileLoader | ||
cfg <- S.getConfig | ||
I.addWorkspaceDir cfg fl dirPath | ||
entries <- I.getModuleList | ||
mapM_ (uncurry emitDiagnostics) entries | ||
|