agcodex_core/context_engine/
semantic_index.rs1use std::collections::HashMap;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub struct FileId(pub u64);
8
9#[derive(Debug, Clone, Default)]
10pub struct SymbolInfo {
11 pub name: String,
12 pub kind: String,
13 pub location: Option<(String, u32, u32)>, }
15
16#[derive(Debug, Default)]
17pub struct SemanticIndex {
18 files: HashMap<FileId, String>,
19 symbols: HashMap<FileId, Vec<SymbolInfo>>,
20}
21
22impl SemanticIndex {
23 pub fn new() -> Self {
24 Self::default()
25 }
26
27 pub fn add_file(&mut self, id: FileId, path: String) {
28 self.files.insert(id, path);
29 }
30
31 pub fn add_symbol(&mut self, file: FileId, sym: SymbolInfo) {
32 self.symbols.entry(file).or_default().push(sym);
33 }
34
35 pub fn file_path(&self, id: FileId) -> Option<&str> {
36 self.files.get(&id).map(|s| s.as_str())
37 }
38
39 pub fn symbols_in_file(&self, id: FileId) -> &[SymbolInfo] {
40 self.symbols.get(&id).map(Vec::as_slice).unwrap_or(&[])
41 }
42}