-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for GHC JSON diagnostics
- Loading branch information
Showing
15 changed files
with
266 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
packages: | ||
sensei.cabal | ||
|
||
package sensei | ||
program-options | ||
ghc-options: -Werror | ||
|
||
tests: True | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
module GHC.Diagnostic where | ||
|
||
import Prelude hiding (span) | ||
import GHC.Generics | ||
import Data.Aeson (ToJSON(..), FromJSON(..)) | ||
import Data.ByteString (ByteString) | ||
import Data.ByteString.Builder (Builder) | ||
import qualified Data.ByteString.Builder as Builder | ||
import Data.ByteString.Lazy (toStrict) | ||
|
||
data Diagnostic = Diagnostic { | ||
version :: String | ||
, ghcVersion :: String | ||
, span :: Span | ||
, severity :: Severity | ||
, code :: Maybe Int | ||
, message :: [String] | ||
, hints :: [String] | ||
} deriving (Eq, Show, Generic, ToJSON, FromJSON) | ||
|
||
data Span = Span { | ||
file :: FilePath | ||
, start :: Location | ||
, end :: Location | ||
} deriving (Eq, Show, Generic, ToJSON, FromJSON) | ||
|
||
data Location = Location { | ||
line :: Int | ||
, column :: Int | ||
} deriving (Eq, Show, Generic, ToJSON, FromJSON) | ||
|
||
data Severity = Warning | Error | ||
deriving (Eq, Show, Generic, ToJSON, FromJSON) | ||
|
||
format :: Diagnostic -> ByteString | ||
format diagnostic = toStrict . Builder.toLazyByteString $ Builder.stringUtf8 diagnostic.span.file <> ":" <> Builder.intDec start.line <> ":" <> Builder.intDec start.column <> ": " <> foo <> code <> Builder.stringUtf8 (unlines diagnostic.message) <> "\n" | ||
where | ||
span = diagnostic.span | ||
start = span.start | ||
|
||
code :: Builder | ||
code = case diagnostic.code of | ||
Nothing -> "" | ||
Just c -> "[GHC-" <> Builder.intDec c <> "] " | ||
|
||
foo = case diagnostic.severity of | ||
Warning -> "warning: " | ||
Error -> "error: " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.