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 pathDiagnosticsSpec.hs
88 lines (70 loc) · 3.36 KB
/
DiagnosticsSpec.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
{-# LANGUAGE OverloadedStrings #-}
module DiagnosticsSpec where
import Control.Applicative.Combinators
import Control.Lens hiding (List)
import Control.Monad.IO.Class
import Data.Aeson (toJSON)
import qualified Data.Text as T
import qualified Data.Default
import Haskell.Ide.Engine.MonadFunctions
import Haskell.Ide.Engine.Config
import Language.Haskell.LSP.Test hiding (message)
import Language.Haskell.LSP.Types
import qualified Language.Haskell.LSP.Types.Lens as LSP
import Test.Hspec
import TestUtils
import Utils
-- ---------------------------------------------------------------------
spec :: Spec
spec = describe "diagnostics providers" $ do
describe "diagnostics triggers" $
it "runs diagnostics on save" $
runSession hieCommandExamplePlugin codeActionSupportCaps "test/testdata" $ do
logm "starting DiagnosticSpec.runs diagnostic on save"
doc <- openDoc "ApplyRefact2.hs" "haskell"
diags@(reduceDiag:_) <- waitForDiagnostics
liftIO $ do
length diags `shouldBe` 2
reduceDiag ^. LSP.range `shouldBe` Range (Position 1 0) (Position 1 12)
reduceDiag ^. LSP.severity `shouldBe` Just DsInfo
reduceDiag ^. LSP.code `shouldBe` Just (StringValue "Eta reduce")
reduceDiag ^. LSP.source `shouldBe` Just "hlint"
diags2a <- waitForDiagnostics
liftIO $ length diags2a `shouldBe` 2
sendNotification TextDocumentDidSave (DidSaveTextDocumentParams doc)
diags3@(d:_) <- waitForDiagnosticsSource "eg2"
liftIO $ do
length diags3 `shouldBe` 1
d ^. LSP.range `shouldBe` Range (Position 0 0) (Position 1 0)
d ^. LSP.severity `shouldBe` Nothing
d ^. LSP.code `shouldBe` Nothing
d ^. LSP.message `shouldBe` T.pack "Example plugin diagnostic, triggered byDiagnosticOnSave"
describe "typed hole errors" $
it "is deferred" $
runSession hieCommand fullCaps "test/testdata" $ do
_ <- openDoc "TypedHoles.hs" "haskell"
[diag] <- waitForDiagnosticsSource "bios"
liftIO $ diag ^. LSP.severity `shouldBe` Just DsWarning
describe "Warnings are warnings" $
it "Overrides -Werror" $
runSession hieCommand fullCaps "test/testdata/wErrorTest" $ do
_ <- openDoc "src/WError.hs" "haskell"
[diag] <- waitForDiagnosticsSource "bios"
liftIO $ diag ^. LSP.severity `shouldBe` Just DsWarning
describe "only diagnostics on save" $
it "Respects diagnosticsOnChange setting" $
runSession hieCommandExamplePlugin codeActionSupportCaps "test/testdata" $ do
let config = Data.Default.def { diagnosticsOnChange = False } :: Config
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
doc <- openDoc "Hover.hs" "haskell"
diags <- waitForDiagnostics
liftIO $ do
length diags `shouldBe` 0
let te = TextEdit (Range (Position 0 0) (Position 0 13)) ""
_ <- applyEdit doc te
skipManyTill loggingNotification noDiagnostics
sendNotification TextDocumentDidSave (DidSaveTextDocumentParams doc)
diags2 <- waitForDiagnostics
liftIO $
length diags2 `shouldBe` 1
-- ---------------------------------------------------------------------