Simon Hengel pushed to branch wip/sol/latest-json-schema at Glasgow Haskell Compiler / GHC
Commits:
-
284fa6fc
by Simon Hengel at 2025-07-09T06:40:03+07:00
3 changed files:
- compiler/GHC/Types/Error.hs
- docs/users_guide/diagnostics-as-json-schema-1_1.json
- + docs/users_guide/diagnostics-as-json-schema-latest.json
Changes:
| ... | ... | @@ -573,16 +573,32 @@ instance ToJson DiagnosticCode where |
| 573 | 573 | {- Note [Diagnostic Message JSON Schema]
|
| 574 | 574 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 575 | 575 | The below instance of ToJson must conform to the JSON schema
|
| 576 | -specified in docs/users_guide/diagnostics-as-json-schema-1_1.json.
|
|
| 576 | +specified in docs/users_guide/diagnostics-as-json-schema-latest.json.
|
|
| 577 | 577 | When the schema is altered, please bump the version.
|
| 578 | 578 | If the content is altered in a backwards compatible way,
|
| 579 | 579 | update the minor version (e.g. 1.3 ~> 1.4).
|
| 580 | 580 | If the content is breaking, update the major version (e.g. 1.3 ~> 2.0).
|
| 581 | -When updating the schema, replace the above file and name it appropriately with
|
|
| 582 | -the version appended, and change the documentation of the -fdiagnostics-as-json
|
|
| 583 | -flag to reflect the new schema.
|
|
| 584 | -To learn more about JSON schemas, check out the below link:
|
|
| 585 | -https://json-schema.org
|
|
| 581 | + |
|
| 582 | +To update to the next minor version:
|
|
| 583 | + |
|
| 584 | +1. Update `schemaVersion`:
|
|
| 585 | + |
|
| 586 | + schemaVersion = "1.2"
|
|
| 587 | + |
|
| 588 | +2. Create a symlink for the new schema version:
|
|
| 589 | + |
|
| 590 | + cp --remove-destination docs/users_guide/diagnostics-as-json-schema-latest.json docs/users_guide/diagnostics-as-json-schema-1_1.json
|
|
| 591 | + ln -s diagnostics-as-json-schema-latest.json docs/users_guide/diagnostics-as-json-schema-1_2.json
|
|
| 592 | + git add docs/users_guide/diagnostics-as-json-schema-*
|
|
| 593 | + |
|
| 594 | +3. Update the schema path in the User's Guide:
|
|
| 595 | + |
|
| 596 | + sed -i s/schema-1_1/schema-1_2/ docs/users_guide/using.rst
|
|
| 597 | + |
|
| 598 | +4. Add your schema changes to `docs/users_guide/diagnostics-as-json-schema-latest.json`.
|
|
| 599 | + |
|
| 600 | +5. Update this instructions.
|
|
| 601 | + |
|
| 586 | 602 | -}
|
| 587 | 603 | |
| 588 | 604 | schemaVersion :: String
|
| 1 | -{
|
|
| 2 | - "$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
| 3 | - "title": "JSON Diagnostic Schema",
|
|
| 4 | - "description": "A Schema for specifying GHC diagnostics output as JSON",
|
|
| 5 | - "type": "object",
|
|
| 6 | - "properties": {
|
|
| 7 | - "version": {
|
|
| 8 | - "description": "The current JSON schema version this object conforms to",
|
|
| 9 | - "type": "string"
|
|
| 10 | - },
|
|
| 11 | - "ghcVersion": {
|
|
| 12 | - "description": "The GHC version",
|
|
| 13 | - "type": "string"
|
|
| 14 | - },
|
|
| 15 | - "span": {
|
|
| 16 | - "oneOf": [
|
|
| 17 | - { "$ref": "#/$defs/span" },
|
|
| 18 | - { "type": "null" }
|
|
| 19 | - ]
|
|
| 20 | - },
|
|
| 21 | - "severity": {
|
|
| 22 | - "description": "The diagnostic severity",
|
|
| 23 | - "type": "string",
|
|
| 24 | - "enum": [
|
|
| 25 | - "Warning",
|
|
| 26 | - "Error"
|
|
| 27 | - ]
|
|
| 28 | - },
|
|
| 29 | - "code": {
|
|
| 30 | - "description": "The diagnostic code (if it exists)",
|
|
| 31 | - "type": [
|
|
| 32 | - "integer",
|
|
| 33 | - "null"
|
|
| 34 | - ]
|
|
| 35 | - },
|
|
| 36 | - "message": {
|
|
| 37 | - "description": "The string output of the diagnostic message by GHC",
|
|
| 38 | - "type": "array",
|
|
| 39 | - "items": {
|
|
| 40 | - "type": "string"
|
|
| 41 | - }
|
|
| 42 | - },
|
|
| 43 | - "hints": {
|
|
| 44 | - "description": "The suggested fixes",
|
|
| 45 | - "type": "array",
|
|
| 46 | - "items": {
|
|
| 47 | - "type": "string"
|
|
| 48 | - }
|
|
| 49 | - },
|
|
| 50 | - "reason" : {
|
|
| 51 | - "description": "The GHC flag that was responsible for the emission of the diagnostic message",
|
|
| 52 | - "oneOf": [
|
|
| 53 | - {
|
|
| 54 | - "type": "object",
|
|
| 55 | - "description": "The diagnostic message was controlled by one or more GHC flags",
|
|
| 56 | - "properties": {
|
|
| 57 | - "flags": {
|
|
| 58 | - "type": "array",
|
|
| 59 | - "items": {
|
|
| 60 | - "description": "The name of a GHC flag controlling the diagnostic message",
|
|
| 61 | - "type": "string"
|
|
| 62 | - },
|
|
| 63 | - "minItems": 1
|
|
| 64 | - }
|
|
| 65 | - },
|
|
| 66 | - "required": ["flags"]
|
|
| 67 | - },
|
|
| 68 | - {
|
|
| 69 | - "type": "object",
|
|
| 70 | - "description": "The diagnostic message was controlled by a GHC diagnostic message category",
|
|
| 71 | - "properties": {
|
|
| 72 | - "category": {
|
|
| 73 | - "description": "The name of the GHC diagnostic message category controlling the diagnostic message",
|
|
| 74 | - "type": "string"
|
|
| 75 | - }
|
|
| 76 | - },
|
|
| 77 | - "required": ["category"]
|
|
| 78 | - }
|
|
| 79 | - ]
|
|
| 80 | - }
|
|
| 81 | - },
|
|
| 82 | - "required": [
|
|
| 83 | - "version",
|
|
| 84 | - "ghcVersion",
|
|
| 85 | - "span",
|
|
| 86 | - "severity",
|
|
| 87 | - "code",
|
|
| 88 | - "message",
|
|
| 89 | - "hints"
|
|
| 90 | - ],
|
|
| 91 | - "additionalProperties": false,
|
|
| 92 | - "$defs": {
|
|
| 93 | - "span": {
|
|
| 94 | - "description": "The span of the diagnostic",
|
|
| 95 | - "type": "object",
|
|
| 96 | - "properties": {
|
|
| 97 | - "file": {
|
|
| 98 | - "description": "The file in which the diagnostic occurs",
|
|
| 99 | - "type": "string"
|
|
| 100 | - },
|
|
| 101 | - "start": {
|
|
| 102 | - "description": "The start location of the diagnostic",
|
|
| 103 | - "$ref": "#/$defs/location"
|
|
| 104 | - },
|
|
| 105 | - "end": {
|
|
| 106 | - "description": "The end location of the diagnostic",
|
|
| 107 | - "$ref": "#/$defs/location"
|
|
| 108 | - }
|
|
| 109 | - },
|
|
| 110 | - "required": [
|
|
| 111 | - "file",
|
|
| 112 | - "start",
|
|
| 113 | - "end"
|
|
| 114 | - ],
|
|
| 115 | - "additionalProperties": false
|
|
| 116 | - },
|
|
| 117 | - "location": {
|
|
| 118 | - "description": "A location in a text file",
|
|
| 119 | - "type": "object",
|
|
| 120 | - "properties": {
|
|
| 121 | - "line": {
|
|
| 122 | - "description": "The line number",
|
|
| 123 | - "type": "integer"
|
|
| 124 | - },
|
|
| 125 | - "column": {
|
|
| 126 | - "description": "The column number",
|
|
| 127 | - "type": "integer"
|
|
| 128 | - }
|
|
| 129 | - },
|
|
| 130 | - "required": [
|
|
| 131 | - "line",
|
|
| 132 | - "column"
|
|
| 133 | - ],
|
|
| 134 | - "additionalProperties": false
|
|
| 135 | - }
|
|
| 136 | - }
|
|
| 137 | -} |
| 1 | +diagnostics-as-json-schema-latest.json |
|
| \ No newline at end of file |
| 1 | +{
|
|
| 2 | + "$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
| 3 | + "title": "JSON Diagnostic Schema",
|
|
| 4 | + "description": "A Schema for specifying GHC diagnostics output as JSON",
|
|
| 5 | + "type": "object",
|
|
| 6 | + "properties": {
|
|
| 7 | + "version": {
|
|
| 8 | + "description": "The current JSON schema version this object conforms to",
|
|
| 9 | + "type": "string"
|
|
| 10 | + },
|
|
| 11 | + "ghcVersion": {
|
|
| 12 | + "description": "The GHC version",
|
|
| 13 | + "type": "string"
|
|
| 14 | + },
|
|
| 15 | + "span": {
|
|
| 16 | + "oneOf": [
|
|
| 17 | + { "$ref": "#/$defs/span" },
|
|
| 18 | + { "type": "null" }
|
|
| 19 | + ]
|
|
| 20 | + },
|
|
| 21 | + "severity": {
|
|
| 22 | + "description": "The diagnostic severity",
|
|
| 23 | + "type": "string",
|
|
| 24 | + "enum": [
|
|
| 25 | + "Warning",
|
|
| 26 | + "Error"
|
|
| 27 | + ]
|
|
| 28 | + },
|
|
| 29 | + "code": {
|
|
| 30 | + "description": "The diagnostic code (if it exists)",
|
|
| 31 | + "type": [
|
|
| 32 | + "integer",
|
|
| 33 | + "null"
|
|
| 34 | + ]
|
|
| 35 | + },
|
|
| 36 | + "message": {
|
|
| 37 | + "description": "The string output of the diagnostic message by GHC",
|
|
| 38 | + "type": "array",
|
|
| 39 | + "items": {
|
|
| 40 | + "type": "string"
|
|
| 41 | + }
|
|
| 42 | + },
|
|
| 43 | + "hints": {
|
|
| 44 | + "description": "The suggested fixes",
|
|
| 45 | + "type": "array",
|
|
| 46 | + "items": {
|
|
| 47 | + "type": "string"
|
|
| 48 | + }
|
|
| 49 | + },
|
|
| 50 | + "reason" : {
|
|
| 51 | + "description": "The GHC flag that was responsible for the emission of the diagnostic message",
|
|
| 52 | + "oneOf": [
|
|
| 53 | + {
|
|
| 54 | + "type": "object",
|
|
| 55 | + "description": "The diagnostic message was controlled by one or more GHC flags",
|
|
| 56 | + "properties": {
|
|
| 57 | + "flags": {
|
|
| 58 | + "type": "array",
|
|
| 59 | + "items": {
|
|
| 60 | + "description": "The name of a GHC flag controlling the diagnostic message",
|
|
| 61 | + "type": "string"
|
|
| 62 | + },
|
|
| 63 | + "minItems": 1
|
|
| 64 | + }
|
|
| 65 | + },
|
|
| 66 | + "required": ["flags"]
|
|
| 67 | + },
|
|
| 68 | + {
|
|
| 69 | + "type": "object",
|
|
| 70 | + "description": "The diagnostic message was controlled by a GHC diagnostic message category",
|
|
| 71 | + "properties": {
|
|
| 72 | + "category": {
|
|
| 73 | + "description": "The name of the GHC diagnostic message category controlling the diagnostic message",
|
|
| 74 | + "type": "string"
|
|
| 75 | + }
|
|
| 76 | + },
|
|
| 77 | + "required": ["category"]
|
|
| 78 | + }
|
|
| 79 | + ]
|
|
| 80 | + }
|
|
| 81 | + },
|
|
| 82 | + "required": [
|
|
| 83 | + "version",
|
|
| 84 | + "ghcVersion",
|
|
| 85 | + "span",
|
|
| 86 | + "severity",
|
|
| 87 | + "code",
|
|
| 88 | + "message",
|
|
| 89 | + "hints"
|
|
| 90 | + ],
|
|
| 91 | + "additionalProperties": false,
|
|
| 92 | + "$defs": {
|
|
| 93 | + "span": {
|
|
| 94 | + "description": "The span of the diagnostic",
|
|
| 95 | + "type": "object",
|
|
| 96 | + "properties": {
|
|
| 97 | + "file": {
|
|
| 98 | + "description": "The file in which the diagnostic occurs",
|
|
| 99 | + "type": "string"
|
|
| 100 | + },
|
|
| 101 | + "start": {
|
|
| 102 | + "description": "The start location of the diagnostic",
|
|
| 103 | + "$ref": "#/$defs/location"
|
|
| 104 | + },
|
|
| 105 | + "end": {
|
|
| 106 | + "description": "The end location of the diagnostic",
|
|
| 107 | + "$ref": "#/$defs/location"
|
|
| 108 | + }
|
|
| 109 | + },
|
|
| 110 | + "required": [
|
|
| 111 | + "file",
|
|
| 112 | + "start",
|
|
| 113 | + "end"
|
|
| 114 | + ],
|
|
| 115 | + "additionalProperties": false
|
|
| 116 | + },
|
|
| 117 | + "location": {
|
|
| 118 | + "description": "A location in a text file",
|
|
| 119 | + "type": "object",
|
|
| 120 | + "properties": {
|
|
| 121 | + "line": {
|
|
| 122 | + "description": "The line number",
|
|
| 123 | + "type": "integer"
|
|
| 124 | + },
|
|
| 125 | + "column": {
|
|
| 126 | + "description": "The column number",
|
|
| 127 | + "type": "integer"
|
|
| 128 | + }
|
|
| 129 | + },
|
|
| 130 | + "required": [
|
|
| 131 | + "line",
|
|
| 132 | + "column"
|
|
| 133 | + ],
|
|
| 134 | + "additionalProperties": false
|
|
| 135 | + }
|
|
| 136 | + }
|
|
| 137 | +} |