1pub mod ranked;
8
9use schemars::JsonSchema;
10use serde::Serialize;
11
12pub trait Entity: Serialize + JsonSchema + Clone {
14 fn label(&self) -> &str;
16}
17
18#[derive(Debug, Clone, Serialize, JsonSchema)]
20pub struct FunctionEntity {
21 pub name: String,
22 pub parent: Option<String>,
23 pub file_path: String,
24 pub start_line: usize,
25 pub end_line: usize,
26}
27
28impl Entity for FunctionEntity {
29 fn label(&self) -> &str {
30 &self.name
31 }
32}
33
34#[derive(Debug, Clone, Serialize, JsonSchema)]
36pub struct ModuleEntity {
37 pub path: String,
38}
39
40impl Entity for ModuleEntity {
41 fn label(&self) -> &str {
42 &self.path
43 }
44}
45
46#[derive(Debug, Clone, Serialize, JsonSchema)]
48pub struct FileEntity {
49 pub path: String,
50}
51
52impl Entity for FileEntity {
53 fn label(&self) -> &str {
54 &self.path
55 }
56}
57
58pub fn truncate_path(path: &str, max_len: usize) -> String {
62 if max_len <= 3 {
63 return path.to_string();
64 }
65 if path.len() > max_len {
66 let target = path.len().saturating_sub(max_len - 3);
67 let safe_start = path
68 .char_indices()
69 .map(|(i, _)| i)
70 .find(|&i| i >= target)
71 .unwrap_or(path.len());
72 format!("...{}", &path[safe_start..])
73 } else {
74 path.to_string()
75 }
76}