MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / parse_mago_json

Function parse_mago_json

src/mago.rs:303–323  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

301/// matches the file we ran against. `content` is the original buffer
302/// text, used to compute line/column positions from byte offsets.
303fn 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///

Callers 14

run_mago_lintFunction · 0.85
run_mago_analyzeFunction · 0.85
parse_lint_issuesFunction · 0.85
parse_analyze_issuesFunction · 0.85
parse_empty_resultFunction · 0.85
severity_mapping_errorFunction · 0.85
severity_mapping_warningFunction · 0.85
severity_mapping_noteFunction · 0.85
severity_mapping_helpFunction · 0.85
parse_invalid_jsonFunction · 0.85
parse_no_matching_fileFunction · 0.85

Calls 3

parse_mago_issueFunction · 0.85
pushMethod · 0.80
getMethod · 0.45

Tested by 12

parse_lint_issuesFunction · 0.68
parse_analyze_issuesFunction · 0.68
parse_empty_resultFunction · 0.68
severity_mapping_errorFunction · 0.68
severity_mapping_warningFunction · 0.68
severity_mapping_noteFunction · 0.68
severity_mapping_helpFunction · 0.68
parse_invalid_jsonFunction · 0.68
parse_no_matching_fileFunction · 0.68
parse_edits_from_jsonFunction · 0.68