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

Function parse_edits_from_json

src/mago.rs:1053–1111  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1051
1052 #[test]
1053 fn parse_edits_from_json() {
1054 let content = "<?php\nfoo();\n";
1055 let file_path = "/tmp/test.php";
1056 let json = r#"{
1057 "issues": [
1058 {
1059 "level": "Warning",
1060 "code": "fixable",
1061 "message": "Use bar() instead",
1062 "notes": [],
1063 "help": "",
1064 "annotations": [
1065 {
1066 "message": "",
1067 "kind": "Primary",
1068 "span": {
1069 "file_id": {
1070 "name": "test.php",
1071 "path": "/tmp/test.php",
1072 "size": 14,
1073 "file_type": "Host"
1074 },
1075 "start": { "offset": 6, "line": 1 },
1076 "end": { "offset": 11, "line": 1 }
1077 }
1078 }
1079 ],
1080 "edits": [
1081 [
1082 { "name": "test.php", "path": "/tmp/test.php", "size": 14, "file_type": "Host" },
1083 [
1084 { "range": { "start": 6, "end": 11 }, "new_text": "bar()", "safety": "Safe" }
1085 ]
1086 ],
1087 [
1088 { "name": "other.php", "path": "/tmp/other.php", "size": 20, "file_type": "Host" },
1089 [
1090 { "range": { "start": 0, "end": 5 }, "new_text": "baz()", "safety": "Unsafe" }
1091 ]
1092 ]
1093 ]
1094 }
1095 ]
1096 }"#;
1097 let diags = parse_mago_json(json, content, file_path, "mago-lint").unwrap();
1098 assert_eq!(diags.len(), 1);
1099
1100 let data = diags[0].data.as_ref().expect("diagnostic should have data");
1101 let mago_edits = data
1102 .get("mago_edits")
1103 .expect("should have mago_edits key")
1104 .as_array()
1105 .expect("mago_edits should be an array");
1106 assert_eq!(mago_edits.len(), 1);
1107 assert_eq!(mago_edits[0]["start"], 6);
1108 assert_eq!(mago_edits[0]["end"], 11);
1109 assert_eq!(mago_edits[0]["new_text"], "bar()");
1110 assert_eq!(mago_edits[0]["safety"], "Safe");

Callers

nothing calls this directly

Calls 3

parse_mago_jsonFunction · 0.85
unwrapMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected