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

Function parse_file_errors

src/phpstan.rs:588–641  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

586
587 #[test]
588 fn parse_file_errors() {
589 let json = r#"{
590 "totals": {"errors": 0, "file_errors": 2},
591 "files": {
592 "/project/src/Foo.php": {
593 "errors": 2,
594 "messages": [
595 {
596 "message": "Parameter #1 $x of method Foo::bar() expects int, string given.",
597 "line": 10,
598 "ignorable": true,
599 "identifier": "argument.type"
600 },
601 {
602 "message": "Method Foo::baz() should return string but returns int.",
603 "line": 25,
604 "ignorable": true,
605 "identifier": "return.type"
606 }
607 ]
608 }
609 },
610 "errors": []
611 }"#;
612 let path = Path::new("/project/src/Foo.php");
613 let diags = parse_phpstan_json(json, path).unwrap();
614 assert_eq!(diags.len(), 2);
615
616 // First diagnostic
617 assert_eq!(diags[0].range.start.line, 9); // 10 - 1
618 assert_eq!(diags[0].severity, Some(DiagnosticSeverity::ERROR));
619 assert_eq!(diags[0].source.as_deref(), Some("phpstan"));
620 assert_eq!(
621 diags[0].code,
622 Some(NumberOrString::String("argument.type".to_string()))
623 );
624 assert!(diags[0].message.contains("Parameter #1"));
625 // ignorable: true is stored in data
626 assert_eq!(
627 diags[0].data,
628 Some(serde_json::json!({ "ignorable": true }))
629 );
630
631 // Second diagnostic
632 assert_eq!(diags[1].range.start.line, 24); // 25 - 1
633 assert_eq!(
634 diags[1].code,
635 Some(NumberOrString::String("return.type".to_string()))
636 );
637 assert_eq!(
638 diags[1].data,
639 Some(serde_json::json!({ "ignorable": true }))
640 );
641 }
642
643 #[test]
644 fn parse_non_ignorable_diagnostic() {

Callers

nothing calls this directly

Calls 2

parse_phpstan_jsonFunction · 0.85
unwrapMethod · 0.45

Tested by

no test coverage detected