pub mod ranked;
use schemars::JsonSchema;
use serde::Serialize;
pub trait Entity: Serialize + JsonSchema + Clone {
fn label(&self) -> &str;
}
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct FunctionEntity {
pub name: String,
pub parent: Option<String>,
pub file_path: String,
pub start_line: usize,
pub end_line: usize,
}
impl Entity for FunctionEntity {
fn label(&self) -> &str {
&self.name
}
}
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct ModuleEntity {
pub path: String,
}
impl Entity for ModuleEntity {
fn label(&self) -> &str {
&self.path
}
}
#[derive(Debug, Clone, Serialize, JsonSchema)]
pub struct FileEntity {
pub path: String,
}
impl Entity for FileEntity {
fn label(&self) -> &str {
&self.path
}
}
pub fn truncate_path(path: &str, max_len: usize) -> String {
if max_len <= 3 {
return path.to_string();
}
if path.len() > max_len {
let target = path.len().saturating_sub(max_len - 3);
let safe_start = path
.char_indices()
.map(|(i, _)| i)
.find(|&i| i >= target)
.unwrap_or(path.len());
format!("...{}", &path[safe_start..])
} else {
path.to_string()
}
}