diff --git a/lib/Eclair/Error.hs b/lib/Eclair/Error.hs index 742f1bd..f1be9b2 100644 --- a/lib/Eclair/Error.hs +++ b/lib/Eclair/Error.hs @@ -92,7 +92,6 @@ posToSourcePos (Pos l c) = -- Actual location in the code (a range). -- Contains the file, start and end of the position. --- TODO make this the leading location type instead of SourceSpan data Location = Location { locationFile :: FilePath diff --git a/lib/Eclair/LSP/Handlers/Diagnostics.hs b/lib/Eclair/LSP/Handlers/Diagnostics.hs index 024904c..a06250a 100644 --- a/lib/Eclair/LSP/Handlers/Diagnostics.hs +++ b/lib/Eclair/LSP/Handlers/Diagnostics.hs @@ -37,7 +37,7 @@ diagnosticsHandler path = do mFileContents <- lift $ vfsLookupFile path case mFileContents of Nothing -> - pure $ DiagnosticsError path Nothing "Failed to read file from VFS!" + pure $ DiagnosticsError path Nothing "File not found in VFS!" Just fileContents -> do errs <- liftLSP $ emitDiagnostics params path diagnostics <- mconcat <$> traverse (errorToDiagnostics fileContents) errs diff --git a/tests/eclair/Test/Eclair/LSP/HandlersSpec.hs b/tests/eclair/Test/Eclair/LSP/HandlersSpec.hs index ea9e60c..03b3006 100644 --- a/tests/eclair/Test/Eclair/LSP/HandlersSpec.hs +++ b/tests/eclair/Test/Eclair/LSP/HandlersSpec.hs @@ -14,9 +14,7 @@ spec :: Spec spec = describe "LSP handlers" $ parallel $ do hoverSpec documentHighlightSpec - - describe "diagnostics" $ parallel $ do - it "" pending + diagnosticsSpec hoverSpec :: Spec hoverSpec = describe "Hover action" $ do @@ -98,6 +96,31 @@ documentHighlightSpec = describe "Document highlight action" $ do result <- withLSP (Just file) $ documentHighlightHandler file srcPos result `shouldBe` DocHLError file srcPos "Failed to get highlight information!" +diagnosticsSpec :: Spec +diagnosticsSpec = describe "Diagnostics action" $ parallel $ do + it "reports nothing if file is OK" pending + + it "reports invalid syntax" $ do + let file = fixture "invalid_syntax.eclair" + DiagnosticsOk diags <- withLSP (Just file) $ diagnosticsHandler file + length diags `shouldBe` 2 + + it "returns an error if file not found in vfs" $ do + let file = "not_found.eclair" + result <- withLSP Nothing $ diagnosticsHandler file + result `shouldBe` DiagnosticsError file Nothing "File not found in VFS!" + + it "reports semantic errors" $ do + let file = fixture "semantic_errors.eclair" + DiagnosticsOk [diag] <- withLSP (Just file) $ diagnosticsHandler file + let (Diagnostic _ _ _ msg) = diag + toString msg `shouldContain` "Wildcard in top level fact" + + it "reports type errors" $ do + let file = fixture "type_errors.eclair" + DiagnosticsOk (_:_:diag:_) <- withLSP (Just file) $ diagnosticsHandler file + let (Diagnostic _ _ _ msg) = diag + toString msg `shouldContain` "Type mismatch" fixture :: FilePath -> FilePath fixture file = diff --git a/tests/eclair/fixtures/lsp/invalid_syntax.eclair b/tests/eclair/fixtures/lsp/invalid_syntax.eclair new file mode 100644 index 0000000..53bf2d0 --- /dev/null +++ b/tests/eclair/fixtures/lsp/invalid_syntax.eclair @@ -0,0 +1,5 @@ +@def number(u32) output. + +number(123, ). +number(456). +number(789, ). diff --git a/tests/eclair/fixtures/lsp/semantic_errors.eclair b/tests/eclair/fixtures/lsp/semantic_errors.eclair new file mode 100644 index 0000000..e15c8b5 --- /dev/null +++ b/tests/eclair/fixtures/lsp/semantic_errors.eclair @@ -0,0 +1,3 @@ +@def wildcard_in_fact(u32) output. + +wildcard_in_fact(_).