X-Git-Url: https://git.lukelau.me/?a=blobdiff_plain;f=src%2FLanguage%2FLSP%2FTest%2FSession.hs;h=4b3ce84be89205dbd1637a382ec3e61f19295a25;hb=80f4e593dfc9bbf0971bb4ac556c82a5e664b3a6;hp=36007391c35965676be1a5f87a337e33947a3afb;hpb=fb6a9f6f2b3d9393f5b356416d46cc92b098839f;p=lsp-test.git diff --git a/src/Language/LSP/Test/Session.hs b/src/Language/LSP/Test/Session.hs index 3600739..4b3ce84 100644 --- a/src/Language/LSP/Test/Session.hs +++ b/src/Language/LSP/Test/Session.hs @@ -29,6 +29,7 @@ module Language.LSP.Test.Session , bumpTimeoutId , logMsg , LogMsgType(..) + , documentChangeUri ) where @@ -56,6 +57,7 @@ import Data.Default import Data.Foldable import Data.List import qualified Data.Map as Map +import qualified Data.Set as Set import qualified Data.Text as T import qualified Data.Text.IO as T import qualified Data.HashMap.Strict as HashMap @@ -174,6 +176,7 @@ data SessionState = SessionState , curDynCaps :: Map.Map T.Text SomeRegistration -- ^ The capabilities that the server has dynamically registered with us so -- far + , curProgressSessions :: Set.Set ProgressToken } class Monad m => HasState s m where @@ -264,7 +267,7 @@ runSession' serverIn serverOut mServerProc serverHandler config caps rootDir exi mainThreadId <- myThreadId let context = SessionContext serverIn absRootDir messageChan timeoutIdVar reqMap initRsp config caps - initState vfs = SessionState 0 vfs mempty False Nothing mempty + initState vfs = SessionState 0 vfs mempty False Nothing mempty mempty runSession' ses = initVFS $ \vfs -> runSessionMonad context (initState vfs) ses errorHandler = throwTo mainThreadId :: SessionException -> IO () @@ -296,8 +299,8 @@ updateStateC = awaitForever $ \msg -> do updateState msg yield msg - -- extract Uri out from DocumentChange +-- didn't put this in `lsp-types` because TH was getting in the way documentChangeUri :: DocumentChange -> Uri documentChangeUri (InL x) = x ^. textDocument . uri documentChangeUri (InR (InL x)) = x ^. uri @@ -306,6 +309,14 @@ documentChangeUri (InR (InR (InR x))) = x ^. uri updateState :: (MonadIO m, HasReader SessionContext m, HasState SessionState m) => FromServerMessage -> m () +updateState (FromServerMess SWindowWorkDoneProgressCreate req) = + sendMessage $ ResponseMessage "2.0" (Just $ req ^. LSP.id) (Right ()) +updateState (FromServerMess SProgress req) = case req ^. params . value of + Begin _ -> + modify $ \s -> s { curProgressSessions = Set.insert (req ^. params . token) $ curProgressSessions s } + End _ -> + modify $ \s -> s { curProgressSessions = Set.delete (req ^. params . token) $ curProgressSessions s } + _ -> pure () -- Keep track of dynamic capability registration updateState (FromServerMess SClientRegisterCapability req) = do @@ -351,6 +362,8 @@ updateState (FromServerMess SWorkspaceApplyEdit r) = do -- TODO: Don't do this when replaying a session forM_ mergedParams (sendMessage . NotificationMessage "2.0" STextDocumentDidChange) + sendMessage $ ResponseMessage "2.0" (Just $ r ^. LSP.id) (Right $ ApplyWorkspaceEditResponseBody True Nothing) + -- Update VFS to new document versions let sortedVersions = map (sortBy (compare `on` (^. textDocument . version))) groupedParams latestVersions = map ((^. textDocument) . last) sortedVersions