Skip to content

Commit c9d328c

Browse files
committed
Break down span and require hints
1 parent 907cdf0 commit c9d328c

File tree

2 files changed

+44
-27
lines changed

2 files changed

+44
-27
lines changed

proposals/0000-specify-dump-json.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ The output of the JSON dump would consist of a list of errors, as well as a top
104104
- `"code"` corresponding to the change in this [proposal](https://github.com/haskellfoundation/tech-proposals/blob/main/proposals/accepted/024-error-messages.md) and the above `DiagnosticCode` in typeclass `Diagnostic`
105105
- this is required by the schema but is allowed to have a value of `null`. The hope is that once all diagnostics officially have error codes, this can be required and nonnullable, but that will happen once `diagnosticCode` itself doesn't return a `DiagnosticCode` wrapped in a `Maybe`
106106
- `"hints"` corresponding to the above `[GhcHint]`
107+
- While these are required by the schema, `[]` is an allowed value
107108
- The schema itself doesn't validate at all what these may be, only that they are themselves objects. In my view, the best way to handle them is to output a JSON-ified version of the type `GhcHint`. Any attempt to specify them more than that will result in spiraling complexity and a required update every time the `GhcHint` type changes. Another alternative is to just remove them from the output and only present suggestions as they are rendered in the `message`.
108109
- `"message"` corresponding to `DecoratedSDoc` of `diagnosticMessage`
109110
- this is required by the schema, and is the actual string output produced at the command line
110111

111112
The top level version is crucial for indicating to downstream consumers which JSON schema they must comply with in the case that the schema is updated in the future (which is quite likely).
112113

113114
Information encoded in `diagnosticReason` is not included in this initial version, as that feature is currently unstable. It can be incorporated down the line once it is both more stable and there is a desire to consume that information from users.
115+
114116
For demonstrative purposes, here is an example valid instance of the schema.
115117
```json
116118
{
@@ -120,13 +122,18 @@ For demonstrative purposes, here is an example valid instance of the schema.
120122
{
121123
"span": {
122124
"file": "typecheck/should_fail/T2414.hs",
123-
"startLine": 9,
124-
"startCol": 13,
125-
"endLine": 9,
126-
"endCol": 17
125+
"start": {
126+
"line": 9,
127+
"column": 13
128+
},
129+
"end": {
130+
"line": 9,
131+
"column": 17
132+
}
127133
},
128134
"severity": "Error",
129135
"code": 27958,
136+
"hints": [],
130137
"message": " • Couldn't match type ‘b0’ with ‘(Bool, b0)’ \n Expected: b0 -> Maybe (Bool, b0) \nActual: b0 -> Maybe b0 \n• In the first argument of ‘unfoldr’, namely ‘Just’ \nIn the expression: unfoldr Just \nIn an equation for ‘f’: f = unfoldr Just"
131138
}
132139
]
@@ -137,7 +144,7 @@ The schema itself will be brought into version control of the GHC repo and tests
137144

138145
One of the major benefits of utilizing a JSON schema is that the expected JSON payload can be well-defined for consumers of the messages. This has massive benefits, as consumers can presume the structure of the output without having to analyze the contents for the presence or absence of particular bits of data. However, one drawback may be the over specification of the output. There may be some opportunities in which flexibility is a benefit for the output. However, this schema can be adapted as further feedback rolls in (with incremented version), making the good net outweigh the bad.
139146

140-
In addition to adding a `-dump-json` flag, it may also prove useful to provide a `-dump-json-schema` flag which simply produces the relevant JSON schema for that particular version of GHC. This I leave open for discussion. Provided that the schema is in an easy to find location, it may be overkill.
147+
In addition to adding a `-dump-diags-json` flag, it may also prove useful to provide a `-dump-diags-json-schema` flag which simply produces the relevant JSON schema for that particular version of GHC. This I leave open for discussion. Provided that the schema is in an easy to find location, it may be overkill.
141148

142149
The schema evolution process is currently undetermined, though I imagine that due to the infrequency with which the schema will need to be changed, it can be handled on a case-by-base basis. Though keeping a running list of all relevant stakeholders that may need to be informed could be a good idea.
143150

proposals/0000-specify-dump-json/schema.json

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
]
3737
},
3838
"hints": {
39-
"description": "The hints suggested by GHC in a JSON-ified representation of the internal GhcHint type",
40-
"type": "array",
41-
"items": {
42-
"type": "object"
43-
}
39+
"description": "The hints suggested by GHC in a JSON-ified representation of the internal GhcHint type",
40+
"type": "array",
41+
"items": {
42+
"type": "object"
43+
}
4444
},
4545
"message": {
4646
"description": "The string output of the diagnostic message by GHC",
@@ -51,6 +51,7 @@
5151
"span",
5252
"severity",
5353
"code",
54+
"hints",
5455
"message"
5556
],
5657
"additionalProperties": false
@@ -65,36 +66,45 @@
6566
"additionalProperties": false,
6667
"$defs": {
6768
"span": {
68-
"description": "The location of the diagnostic",
69+
"description": "The span of the diagnostic",
6970
"type": "object",
7071
"properties": {
7172
"file": {
7273
"description": "The file in which the diagnostic occurs",
7374
"type": "string"
7475
},
75-
"startLine": {
76-
"description": "The start line of the diagnostic",
77-
"type": "integer"
78-
},
79-
"startCol": {
80-
"description": "The start column of the diagnostics",
81-
"type": "integer"
76+
"start": {
77+
"description": "The start location of the diagnostic",
78+
"$ref": "#/$defs/location"
8279
},
83-
"endLine": {
84-
"description": "The end line of the diagnostics",
80+
"end": {
81+
"description": "The end location of the diagnostic",
82+
"$ref": "#/$defs/location"
83+
}
84+
},
85+
"required": [
86+
"file",
87+
"start",
88+
"end"
89+
],
90+
"additionalProperties": false
91+
},
92+
"location": {
93+
"description": "A location in a text file",
94+
"type": "object",
95+
"properties": {
96+
"line": {
97+
"description": "The line number",
8598
"type": "integer"
8699
},
87-
"endCol": {
88-
"description": "The end column of the diagnostic",
100+
"column": {
101+
"description": "The column number",
89102
"type": "integer"
90103
}
91104
},
92105
"required": [
93-
"file",
94-
"startLine",
95-
"startCol",
96-
"endLine",
97-
"endCol"
106+
"line",
107+
"column"
98108
],
99109
"additionalProperties": false
100110
}

0 commit comments

Comments
 (0)