This repository was archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathProgressSpec.hs
115 lines (89 loc) · 4.74 KB
/
ProgressSpec.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
{-# LANGUAGE OverloadedStrings #-}
module ProgressSpec where
import Control.Applicative.Combinators
import Control.Lens
import Control.Monad.IO.Class
import Data.Aeson
import Data.Default
import Haskell.Ide.Engine.Config
import Language.Haskell.LSP.Test
import Language.Haskell.LSP.Messages -- TODO: Move this into haskell-lsp-types
import Language.Haskell.LSP.Types
import qualified Language.Haskell.LSP.Types.Lens as L
import Language.Haskell.LSP.Types.Capabilities
import Test.Hspec
import TestUtils
spec :: Spec
spec = describe "window/workDoneProgress" $ do
it "sends indefinite progress notifications" $
-- Testing that ghc-mod sends progress notifications
runSession hieCommand progressCaps "test/testdata" $ do
doc <- openDoc "ApplyRefact2.hs" "haskell"
skipMany loggingNotification
createRequest <- message :: Session WorkDoneProgressCreateRequest
liftIO $ do
createRequest ^. L.params `shouldBe` WorkDoneProgressCreateParams (ProgressNumericToken 0)
startNotification <- message :: Session WorkDoneProgressBeginNotification
liftIO $ do
-- Expect a stack cradle, since the given `hie.yaml` is expected
-- to contain a multi-stack cradle.
startNotification ^. L.params . L.value . L.title `shouldBe` "Initializing Stack project"
startNotification ^. L.params . L.token `shouldBe` (ProgressNumericToken 0)
reportNotification <- message :: Session WorkDoneProgressReportNotification
liftIO $ do
reportNotification ^. L.params . L.value . L.message `shouldBe` Just "Main"
reportNotification ^. L.params . L.token `shouldBe` (ProgressNumericToken 0)
-- may produce diagnostics
skipMany publishDiagnosticsNotification
doneNotification <- message :: Session WorkDoneProgressEndNotification
liftIO $ doneNotification ^. L.params . L.token `shouldBe` (ProgressNumericToken 0)
-- Initial hlint notifications
_ <- publishDiagnosticsNotification
-- Test incrementing ids
sendNotification TextDocumentDidSave (DidSaveTextDocumentParams doc)
createRequest' <- skipManyTill loggingNotification (message :: Session WorkDoneProgressCreateRequest)
liftIO $ do
createRequest' ^. L.params `shouldBe` WorkDoneProgressCreateParams (ProgressNumericToken 1)
startNotification' <- message :: Session WorkDoneProgressBeginNotification
liftIO $ do
startNotification' ^. L.params . L.value . L.title `shouldBe` "loading"
startNotification' ^. L.params . L.token `shouldBe` (ProgressNumericToken 1)
reportNotification' <- message :: Session WorkDoneProgressReportNotification
liftIO $ do
reportNotification' ^. L.params . L.value . L.message `shouldBe` Just "Main"
reportNotification' ^. L.params . L.token `shouldBe` (ProgressNumericToken 1)
doneNotification' <- message :: Session WorkDoneProgressEndNotification
liftIO $ doneNotification' ^. L.params . L.token `shouldBe` (ProgressNumericToken 1)
-- Initial hlint notifications
_ <- publishDiagnosticsNotification
return ()
it "sends indefinite progress notifications with liquid" $
-- Testing that Liquid Haskell sends progress notifications
runSession hieCommand progressCaps "test/testdata" $ do
doc <- openDoc "liquid/Evens.hs" "haskell"
skipMany loggingNotification
_ <- message :: Session WorkDoneProgressCreateRequest
_ <- message :: Session WorkDoneProgressBeginNotification
_ <- message :: Session WorkDoneProgressReportNotification
_ <- message :: Session WorkDoneProgressEndNotification
-- the hie-bios diagnostics
_ <- skipManyTill loggingNotification publishDiagnosticsNotification
-- Enable liquid haskell plugin
let config = def { liquidOn = True, hlintOn = False }
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
-- Test liquid
sendNotification TextDocumentDidSave (DidSaveTextDocumentParams doc)
-- hlint notifications
-- TODO: potential race between typechecking, e.g. context intialisation
-- TODO: and disabling hlint notifications
-- _ <- skipManyTill loggingNotification publishDiagnosticsNotification
let startPred (NotWorkDoneProgressBegin m) =
m ^. L.params . L.value . L.title == "Running Liquid Haskell on Evens.hs"
startPred _ = False
let donePred (NotWorkDoneProgressEnd _) = True
donePred _ = False
_ <- skipManyTill anyMessage $ between (satisfy startPred) (satisfy donePred) $
many (satisfy (\x -> not (startPred x || donePred x)))
return ()
progressCaps :: ClientCapabilities
progressCaps = fullCaps { _window = Just (WindowClientCapabilities (Just True)) }