1use serde::{Deserialize, Serialize};
4
5use crate::document::Doc;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct CodeChunk {
10 pub id: String,
11 pub code: String,
13 pub file: String,
15 pub language: String,
17 pub kind: SymbolKind,
19 pub name: Option<String>,
21 pub start_line: usize,
23 pub end_line: usize,
25 pub parent: Option<String>,
27 pub docs: Option<String>,
29 pub signature: Option<String>,
31}
32
33impl Doc for CodeChunk {
34 fn id(&self) -> &str {
35 &self.id
36 }
37
38 fn embed_text(&self) -> String {
39 let mut text = String::new();
40 if let Some(docs) = &self.docs {
41 text.push_str(docs);
42 text.push_str("\n\n");
43 }
44 if let Some(sig) = &self.signature {
45 text.push_str(sig);
46 text.push_str("\n\n");
47 }
48 text.push_str(&self.code);
49 text
50 }
51}
52
53#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
55pub enum SymbolKind {
56 Function,
57 Method,
58 Class,
59 Struct,
60 Trait,
61 Interface,
62 Enum,
63 Module,
64 Variable,
65 Constant,
66 Import,
67 Block,
68}
69
70#[derive(Debug, Clone)]
72pub struct CodeHit {
73 pub chunk: CodeChunk,
74 pub score: f32,
75}