@@ -20,12 +20,18 @@ import qualified Language.Haskell.LSP.Types.Capabilities as C
20
20
import Test.Hspec
21
21
import TestUtils
22
22
23
+ runSessionWithOnChange :: String -> C. ClientCapabilities -> FilePath -> Session a -> IO a
24
+ runSessionWithOnChange cmd caps name test = runSession cmd caps name $ do
25
+ let config = def { diagnosticsOnChange = True }
26
+ sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
27
+ test
28
+
23
29
spec :: Spec
24
30
spec = describe " code actions" $ do
25
31
describe " hlint suggestions" $ do
26
- it " provides 3.8 code actions" $ runSession hieCommand fullCaps " test/testdata" $ do
27
- doc <- openDoc " ApplyRefact2.hs" " haskell"
32
+ it " provides 3.8 code actions" $ runSessionWithOnChange hieCommand fullCaps " test/testdata" $ do
28
33
34
+ doc <- openDoc " ApplyRefact2.hs" " haskell"
29
35
diags@ (reduceDiag: _) <- waitForDiagnostics
30
36
31
37
liftIO $ do
@@ -49,7 +55,7 @@ spec = describe "code actions" $ do
49
55
50
56
-- ---------------------------------
51
57
52
- it " falls back to pre 3.8 code actions" $ runSession hieCommand noLiteralCaps " test/testdata" $ do
58
+ it " falls back to pre 3.8 code actions" $ runSessionWithOnChange hieCommand noLiteralCaps " test/testdata" $ do
53
59
doc <- openDoc " ApplyRefact2.hs" " haskell"
54
60
55
61
_ <- waitForDiagnostics
@@ -66,6 +72,33 @@ spec = describe "code actions" $ do
66
72
67
73
noDiagnostics
68
74
75
+ it " runs diagnostics on save" $ runSession hieCommand fullCaps " test/testdata" $ do
76
+ let config = def { diagnosticsOnChange = False }
77
+ sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
78
+
79
+ doc <- openDoc " ApplyRefact2.hs" " haskell"
80
+ diags@ (reduceDiag: _) <- waitForDiagnostics
81
+
82
+ liftIO $ do
83
+ length diags `shouldBe` 2
84
+ reduceDiag ^. L. range `shouldBe` Range (Position 1 0 ) (Position 1 12 )
85
+ reduceDiag ^. L. severity `shouldBe` Just DsInfo
86
+ reduceDiag ^. L. code `shouldBe` Just " Eta reduce"
87
+ reduceDiag ^. L. source `shouldBe` Just " hlint"
88
+
89
+ (CACodeAction ca: _) <- getAllCodeActions doc
90
+
91
+ -- Evaluate became redundant id in later hlint versions
92
+ liftIO $ [" Apply hint:Redundant id" , " Apply hint:Evaluate" ] `shouldContain` [ca ^. L. title]
93
+
94
+ executeCodeAction ca
95
+
96
+ contents <- getDocumentEdit doc
97
+ liftIO $ contents `shouldBe` " main = undefined\n foo x = x\n "
98
+ sendNotification TextDocumentDidSave (DidSaveTextDocumentParams doc)
99
+
100
+ noDiagnostics
101
+
69
102
-- -----------------------------------
70
103
71
104
describe " rename suggestions" $ do
0 commit comments