pub mod base64;
#[cfg(not(target_arch = "wasm32"))]
pub mod cli;
pub mod index;
pub mod path;
pub(crate) mod path_util;
pub mod posting;
pub mod query;
pub mod search;
#[cfg(feature = "symbols")]
pub mod symbol;
pub mod tokenizer;
#[cfg(feature = "wasm")]
pub mod wasm;
use std::path::PathBuf;
#[derive(Debug, Clone)]
pub struct Config {
pub max_file_size: u64,
pub max_segments: usize,
pub index_dir: PathBuf,
pub repo_root: PathBuf,
pub verbose: bool,
pub strict_permissions: bool,
}
impl Default for Config {
fn default() -> Self {
Self {
max_file_size: 10 * 1024 * 1024,
max_segments: 10,
index_dir: PathBuf::from(".syntext"),
repo_root: PathBuf::from("."),
verbose: false,
strict_permissions: true,
}
}
}
#[derive(Debug, Clone)]
pub struct SearchMatch {
pub path: PathBuf,
pub line_number: u32,
pub line_content: Vec<u8>,
pub byte_offset: u64,
pub submatch_start: usize,
pub submatch_end: usize,
}
#[derive(Debug, Clone, Default)]
pub struct SearchOptions {
pub path_filter: Option<String>,
pub file_type: Option<String>,
pub exclude_type: Option<String>,
pub max_results: Option<usize>,
pub case_insensitive: bool,
}
#[derive(Debug, Clone)]
pub struct IndexStats {
pub total_documents: usize,
pub total_segments: usize,
pub total_grams: usize,
pub index_size_bytes: u64,
pub base_commit: Option<String>,
pub overlay_generations: usize,
pub pending_edits: usize,
}
#[derive(Debug)]
pub enum IndexError {
Io(std::io::Error),
InvalidPattern(String),
CorruptIndex(String),
PathOutsideRepo(PathBuf),
FileTooLarge {
path: PathBuf,
size: u64,
},
LockConflict(PathBuf),
OverlayFull {
overlay_docs: usize,
base_docs: usize,
},
DocIdOverflow {
base_doc_count: u32,
overlay_docs: usize,
},
}
impl From<std::io::Error> for IndexError {
fn from(err: std::io::Error) -> Self {
IndexError::Io(err)
}
}
impl std::fmt::Display for IndexError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
IndexError::Io(e) => write!(f, "I/O error: {e}"),
IndexError::InvalidPattern(p) => write!(f, "invalid pattern: {p}"),
IndexError::CorruptIndex(msg) => write!(f, "corrupt index: {msg}"),
IndexError::PathOutsideRepo(p) => {
let name = p.file_name().map(|n| n.to_string_lossy()).unwrap_or_default();
write!(f, "path outside repo: {name}")
}
IndexError::FileTooLarge { path, size } => {
let name =
path.file_name().map(|n| n.to_string_lossy()).unwrap_or_default();
write!(f, "file too large: {name} ({size} bytes)")
}
IndexError::LockConflict(p) => {
write!(f, "index locked by another process: {}", p.display())
}
IndexError::OverlayFull { overlay_docs, base_docs } => write!(
f,
"overlay too large ({overlay_docs} overlay docs, {base_docs} base docs): \
run `st index` to rebuild"
),
IndexError::DocIdOverflow {
base_doc_count,
overlay_docs,
} => write!(
f,
"doc_id overflow: base {base_doc_count} docs plus {overlay_docs} overlay docs exceeds u32::MAX"
),
}
}
}
impl std::error::Error for IndexError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
IndexError::Io(e) => Some(e),
_ => None,
}
}
}