| 1022 | } |
| 1023 | |
| 1024 | fn exec_list_entities(&self, args: &serde_json::Value) -> Result<String, String> { |
| 1025 | let path_str = args["path"] |
| 1026 | .as_str() |
| 1027 | .ok_or("missing required parameter: path")?; |
| 1028 | |
| 1029 | if !atomic_semantic::is_supported(path_str) { |
| 1030 | return Err(format!("unsupported file type: {path_str}")); |
| 1031 | } |
| 1032 | |
| 1033 | let full_path = self.root.join(path_str); |
| 1034 | let source = std::fs::read_to_string(&full_path) |
| 1035 | .map_err(|e| format!("cannot read {path_str}: {e}"))?; |
| 1036 | |
| 1037 | let mut registry = atomic_semantic::ParserRegistry::new(); |
| 1038 | let entities = registry.extract(path_str, &source); |
| 1039 | |
| 1040 | // Serialize a compact representation. |
| 1041 | let compact: Vec<serde_json::Value> = entities |
| 1042 | .iter() |
| 1043 | .map(|e| { |
| 1044 | let mut obj = json!({ |
| 1045 | "name": e.name, |
| 1046 | "kind": e.kind.as_str(), |
| 1047 | "line": e.line, |
| 1048 | "end_line": e.end_line, |
| 1049 | "exported": e.exported, |
| 1050 | }); |
| 1051 | if let Some(sig) = &e.signature { |
| 1052 | obj["signature"] = json!(sig); |
| 1053 | } |
| 1054 | obj |
| 1055 | }) |
| 1056 | .collect(); |
| 1057 | |
| 1058 | serde_json::to_string_pretty(&compact).map_err(|e| format!("serialize error: {e}")) |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | // ── Helpers ───────────────────────────────────────────────────── |