use crate::error::Result;
use crate::graph::magellan_integration::MagellanIntegration;
use std::path::Path;
pub struct MagellanIngestor {
integration: MagellanIntegration,
}
impl MagellanIngestor {
pub fn new(db_path: &Path) -> Result<Self> {
Ok(Self {
integration: MagellanIntegration::open(db_path)?,
})
}
pub fn index_file(&mut self, file_path: &Path) -> Result<usize> {
self.integration.index_file(file_path)
}
#[cfg(feature = "sqlite")]
pub fn query_by_labels(
&self,
labels: &[&str],
) -> Result<Vec<crate::graph::magellan_integration::SymbolInfo>> {
self.integration.query_by_labels(labels)
}
pub fn get_code(&self, file_path: &Path, start: usize, end: usize) -> Result<Option<String>> {
self.integration
.get_code_chunk(file_path, start, end)
.map(|opt_chunk| opt_chunk.map(|chunk| chunk.content))
}
pub fn integration(&self) -> &MagellanIntegration {
&self.integration
}
pub fn integration_mut(&mut self) -> &mut MagellanIntegration {
&mut self.integration
}
}
pub fn ingest_file_with_magellan(db_path: &Path, file_path: &Path) -> Result<usize> {
let mut ingestor = MagellanIngestor::new(db_path)?;
ingestor.index_file(file_path)
}
#[cfg(test)]
mod tests {
use super::*;
use tempfile::TempDir;
#[cfg(feature = "sqlite")]
#[test]
fn test_create_ingestor() {
let temp_dir = TempDir::new().unwrap();
let db_path = temp_dir.path().join("test.db");
let ingestor = MagellanIngestor::new(&db_path).unwrap();
assert_eq!(ingestor.query_by_labels(&["rust"]).unwrap().len(), 0);
}
}