sem_core/parser/plugins/
fallback.rs1use crate::model::entity::{build_entity_id, SemanticEntity};
2use crate::parser::plugin::SemanticParserPlugin;
3use crate::utils::hash::content_hash;
4
5pub struct FallbackParserPlugin;
6
7const CHUNK_SIZE: usize = 20;
8
9impl SemanticParserPlugin for FallbackParserPlugin {
10 fn id(&self) -> &str {
11 "fallback"
12 }
13
14 fn extensions(&self) -> &[&str] {
15 &[]
16 }
17
18 fn extract_entities(&self, content: &str, file_path: &str) -> Vec<SemanticEntity> {
19 let lines: Vec<&str> = content.lines().collect();
20 let mut entities = Vec::new();
21
22 let mut i = 0;
23 while i < lines.len() {
24 let end = (i + CHUNK_SIZE).min(lines.len());
25 let chunk: Vec<&str> = lines[i..end].to_vec();
26 let chunk_content = chunk.join("\n");
27 let start_line = i + 1;
28 let end_line = end;
29 let name = format!("lines {start_line}-{end_line}");
30
31 entities.push(SemanticEntity {
32 id: build_entity_id(file_path, "chunk", &name, None),
33 file_path: file_path.to_string(),
34 entity_type: "chunk".to_string(),
35 name,
36 parent_id: None,
37 content_hash: content_hash(&chunk_content),
38 structural_hash: None,
39 content: chunk_content,
40 start_line,
41 end_line,
42 metadata: None,
43 });
44
45 i += CHUNK_SIZE;
46 }
47
48 entities
49 }
50}