Pre-HFTP: JSON Dump of GHC's Diagnostics

GHC is currently undergoing development GHC is currently undergoing a long scale project to move to a more structured error representation.
In harmony with this motion, there is a desire for a JSON dump of GHC’s diagnostic messages.
Such an implementation would facilitate easier consumption for downstream consumers of GHC’s diagnostic messages (e.g. IDE developers).
To best enforce a standardized JSON output, a JSON schema can be used.

I was chosen for Summer of Haskell to help implement this feature, but wanted to raise it here before finishing off my HFTP. I have an initial draft of a JSON schema, which I will share here. Though really I wanted to just get a sense for the community desire for such a feature, as well as current efforts to resolve the issue that I may be unaware of.

The schema is below for review as well:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Dump JSON",
  "description": "JSON dump of the GHC compiler error/warning output",
  "type": "object",
  "properties": {
    "version": {
      "description": "The current JSON schema version of the JSON dump",
      "type": "string"
    },
    "errors": {
      "description": "The list of errors produced by GHC",
      "type": "array",
      "items": {
        "properties": {
          "span": {
            "$ref": "#/$defs/span"
          },
          "severity": {
            "description": "The error severity",
            "type": "string",
            "enum": [
              "Warning",
              "Error"
            ]
          },
          "errorCode": {
            "description": "The error code (if it exists)",
              "type": ["integer", "null"]
          },
          "hints": {
            "description": "The hints suggested by GHC",
            "type": "array",
            "$comment": "How much should this be specified? See possible hints in compiler/GHC/Types/Hint.hs"
          },
          "message": {
            "description": "The string output of the error message by GHC",
            "type": "string"
          },
          "warnReason": {
            "description": "The flag, if it exists, which caused the warning",
            "type": "object",
            "properties": {
              "reason": {
                "description": "The reason why a diagnostic was emitted in the first place (e.g., flag, category)",
                "type": "string",
                "enum": [
                  "WarningWithoutFlag",
                  "WarningWithFlag",
                  "WarningWithCategory",
                  "ErrorWithoutFlag"
                ]
              },
              "flagOrCategory": {
                "desciption": "The flag or category which caused the warning",
                "type": "string",
                "$comment": "Should this validate against available flags?"
              }
            },
            "required": [
              "reason"
            ]
          }
        },
        "required": [
          "span",
          "severity",
          "message"
        ]
      }
    }
  },
  "required": [
    "version",
    "errors"
  ],
  "additionalProperties": false,
  "$defs": {
    "span": {
      "description": "The location of the error",
      "type": "object",
      "properties": {
        "file": {
          "description": "The file in which the error occurs",
          "type": "string"
        },
        "startLine": {
          "description": "The start line of the error",
          "type": "integer"
        },
        "startCol": {
          "description": "The start column of the error",
          "type": "integer"
        },
        "endLine": {
          "description": "The end line of the error",
          "type": "integer"
        },
        "endCol": {
          "description": "The end column of the error",
          "type": "integer"
        }
      },
      "required": [
        "file",
        "startLine",
        "startCol",
        "endLine",
        "endCol"
      ],
      "additionalProperties": false
    }
  }
}

Thanks!

7 Likes