summaryrefslogtreecommitdiff
path: root/compiler/main/ErrUtils.hs
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2017-01-30 11:53:17 -0500
committerBen Gamari <ben@smart-cactus.org>2017-01-30 14:00:23 -0500
commit91691117fc194c525f58ccd5b266dd1d10493e5a (patch)
treec9fd4334d5bb2441ad4c75a57697cd80462f492e /compiler/main/ErrUtils.hs
parent7363d5380e600e2ef868a069d5df6857d9e5c17e (diff)
downloadhaskell-91691117fc194c525f58ccd5b266dd1d10493e5a.tar.gz
Add a flag to emit error messages as JSON
This patch adds the flag `-ddump-json` which dumps all the compiler output as a JSON array. This allows tooling to more easily parse GHC's output to display to users. The flag is currently experimental and will hopefully be refined for the next release. In particular I have avoided any changes which involve significant refactoring and provided what is easy given the current infrastructure. Reviewers: austin, bgamari Reviewed By: bgamari Subscribers: DanielG, gracjan, thomie Differential Revision: https://phabricator.haskell.org/D3010 GHC Trac Issues: #13190
Diffstat (limited to 'compiler/main/ErrUtils.hs')
-rw-r--r--compiler/main/ErrUtils.hs8
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/main/ErrUtils.hs b/compiler/main/ErrUtils.hs
index c410f06099..2aeddc26a7 100644
--- a/compiler/main/ErrUtils.hs
+++ b/compiler/main/ErrUtils.hs
@@ -6,6 +6,7 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE BangPatterns #-}
+{-# LANGUAGE RecordWildCards #-}
module ErrUtils (
-- * Basic types
@@ -63,6 +64,7 @@ import SrcLoc
import DynFlags
import FastString (unpackFS)
import StringBuffer (hGetStringBuffer, len, lexemeToString)
+import Json
import System.Directory
import System.Exit ( ExitCode(..), exitWith )
@@ -127,6 +129,7 @@ data ErrMsg = ErrMsg {
}
-- The SrcSpan is used for sorting errors into line-number order
+
-- | Categorise error msgs by their importance. This is so each section can
-- be rendered visually distinct. See Note [Error report] for where these come
-- from.
@@ -164,6 +167,11 @@ data Severity
-- plus "warning:" or "error:",
-- added by mkLocMessags
-- o Output is intended for end users
+ deriving Show
+
+
+instance ToJson Severity where
+ json s = JSString (show s)
instance Show ErrMsg where