use serde::{Deserialize, Serialize};
use crate::document::Doc;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CodeChunk {
pub id: String,
pub code: String,
pub file: String,
pub language: String,
pub kind: SymbolKind,
pub name: Option<String>,
pub start_line: usize,
pub end_line: usize,
pub parent: Option<String>,
pub docs: Option<String>,
pub signature: Option<String>,
}
impl Doc for CodeChunk {
fn id(&self) -> &str {
&self.id
}
fn embed_text(&self) -> String {
let mut text = String::new();
if let Some(docs) = &self.docs {
text.push_str(docs);
text.push_str("\n\n");
}
if let Some(sig) = &self.signature {
text.push_str(sig);
text.push_str("\n\n");
}
text.push_str(&self.code);
text
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum SymbolKind {
Function,
Method,
Class,
Struct,
Trait,
Interface,
Enum,
Module,
Variable,
Constant,
Import,
Block,
}
#[derive(Debug, Clone)]
pub struct CodeHit {
pub chunk: CodeChunk,
pub score: f32,
}