Add waitForDiagnosticsSource
authorLuke Lau <luke_lau@icloud.com>
Thu, 12 Jul 2018 13:07:25 +0000 (14:07 +0100)
committerLuke Lau <luke_lau@icloud.com>
Thu, 12 Jul 2018 13:07:25 +0000 (14:07 +0100)
src/Language/Haskell/LSP/Test.hs
test/Test.hs
test/data/error/Error.hs [new file with mode: 0644]

index bc1faa1b7976cfca975a8f72754a07318ca490cf..3def44000291d1e495cdc3924be80da94a4762b8 100644 (file)
@@ -52,6 +52,7 @@ module Language.Haskell.LSP.Test
   , getDocumentSymbols
   -- ** Diagnostics
   , waitForDiagnostics
+  , waitForDiagnosticsSource
   , noDiagnostics
   -- ** Commands
   , executeCommand
@@ -308,6 +309,17 @@ waitForDiagnostics = do
   let (List diags) = diagsNot ^. params . LSP.diagnostics
   return diags
 
+waitForDiagnosticsSource :: String -> Session [Diagnostic]
+waitForDiagnosticsSource src = do
+  diags <- waitForDiagnostics
+  let res = filter matches diags
+  if null res
+    then waitForDiagnosticsSource src
+    else return res
+  where
+    matches :: Diagnostic -> Bool
+    matches d = d ^. source == Just (T.pack src)
+
 -- | Expects a 'PublishDiagnosticsNotification' and throws an
 -- 'UnexpectedDiagnosticsException' if there are any diagnostics
 -- returned.
index 005018cab300db173de211ab013f4c03af872ced..eedc887b580094afacc611c0888dac6eae348756 100644 (file)
@@ -237,8 +237,16 @@ main = hspec $ do
         , mkRange 75 6 75 22
         , mkRange 71 6 71 22
         ]
-    where mkRange sl sc el ec = Range (Position sl sc) (Position el ec)
 
+  describe "waitForDiagnosticsSource" $
+    it "works" $ runSession "hie --lsp" "test/data/error" $ do
+      openDoc "Error.hs" "haskell"
+      [diag] <- waitForDiagnosticsSource "ghcmod"
+      liftIO $ do
+        diag ^. severity `shouldBe` Just DsError
+        diag ^. source `shouldBe` Just "ghcmod"
+
+mkRange sl sc el ec = Range (Position sl sc) (Position el ec)
 
 didChangeCaps :: ClientCapabilities
 didChangeCaps = def { _workspace = Just workspaceCaps }
diff --git a/test/data/error/Error.hs b/test/data/error/Error.hs
new file mode 100644 (file)
index 0000000..79c1dd9
--- /dev/null
@@ -0,0 +1,2 @@
+main :: IO Int
+main = return "hello"