Parse Mago's JSON output into LSP diagnostics. Both `mago lint` and `mago analyze` produce the same JSON format when invoked with `--reporting-format json`: ```json { "issues": [ { "level": "Error", "code": "invalid-return-statement", "message": "Invalid return type...", "notes": ["extra note text"], "help": "helpful suggestion text", "annotations": [ { "message": "This has type...", "kind": "Pr
(
json_str: &str,
content: &str,
file_path_str: &str,
source_name: &str,
)
| 301 | /// matches the file we ran against. `content` is the original buffer |
| 302 | /// text, used to compute line/column positions from byte offsets. |
| 303 | fn parse_mago_json( |
| 304 | json_str: &str, |
| 305 | content: &str, |
| 306 | file_path_str: &str, |
| 307 | source_name: &str, |
| 308 | ) -> Result<Vec<Diagnostic>, String> { |
| 309 | let output: serde_json::Value = |
| 310 | serde_json::from_str(json_str).map_err(|e| format!("Failed to parse Mago JSON: {}", e))?; |
| 311 | |
| 312 | let mut diagnostics = Vec::new(); |
| 313 | |
| 314 | if let Some(issues) = output.get("issues").and_then(|i| i.as_array()) { |
| 315 | for issue in issues { |
| 316 | if let Some(diag) = parse_mago_issue(issue, content, file_path_str, source_name) { |
| 317 | diagnostics.push(diag); |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | Ok(diagnostics) |
| 323 | } |
| 324 | |
| 325 | /// Parse a single Mago issue object into an LSP `Diagnostic`. |
| 326 | /// |