pub mod error;
pub mod index;
#[cfg(feature = "symbols")]
pub mod symbol;
#[cfg(feature = "wasm")]
pub mod wasm;
pub use error::IndexError;
pub(crate) mod base64;
#[cfg(all(not(target_arch = "wasm32"), feature = "cli"))]
pub mod cli;
#[cfg(not(target_arch = "wasm32"))]
pub(crate) mod git_util;
#[cfg(all(not(target_arch = "wasm32"), feature = "cli"))]
pub mod hook;
pub(crate) mod path;
pub(crate) mod path_util;
pub(crate) mod posting;
pub(crate) mod query;
pub(crate) mod search;
pub(crate) mod tokenizer;
#[cfg(not(target_arch = "wasm32"))]
#[doc(hidden)]
pub mod __internal {
pub use crate::base64::encode;
pub use crate::path::filter;
pub use crate::posting::{
roaring_util, varint_decode, varint_encode, PostingList, ROARING_THRESHOLD,
};
pub use crate::query::regex_decompose;
pub use crate::query::{is_literal, literal_grams, route_query, GramQuery, QueryRoute};
pub use crate::tokenizer::{
build_all, build_covering, build_covering_inner, gram_hash, CoveringSet, MAX_GRAM_LEN,
MIN_GRAM_LEN,
};
pub use crate::index::manifest::Manifest;
pub use crate::index::overlay::{
compute_delete_set, EditKind, FileEdit, OverlayDoc, OverlayView,
};
pub use crate::index::pending::{PendingEdits, TakeResult};
pub use crate::index::segment::{
DictVerify, DocEntry, MmapSegment, PostVerify, SegmentMeta, SegmentWriter, FOOTER_SIZE,
FORMAT_VERSION, MAGIC,
};
pub use crate::index::snapshot::{new_snapshot, BaseSegments, IndexSnapshot};
pub use crate::index::walk::is_binary;
}
use std::path::PathBuf;
use std::sync::Arc;
#[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,
pub verify_on_open: bool,
pub recalibrate: bool,
pub auto_update: bool,
pub auto_update_max_files: usize,
pub auto_update_budget_ms: u64,
pub auto_update_async_catchup: bool,
#[cfg(feature = "rayon")]
pub thread_pool: Option<std::sync::Arc<rayon::ThreadPool>>,
}
impl Config {
pub fn new(index_dir: PathBuf, repo_root: PathBuf) -> Self {
Self {
index_dir,
repo_root,
max_file_size: 10 * 1024 * 1024,
max_segments: 10,
verbose: false,
strict_permissions: true,
verify_on_open: false,
recalibrate: false,
auto_update: true,
auto_update_max_files: 200,
auto_update_budget_ms: 150,
auto_update_async_catchup: true,
#[cfg(feature = "rayon")]
thread_pool: None,
}
}
}
impl Default for Config {
fn default() -> Self {
Self::new(PathBuf::from(".syntext"), PathBuf::from("."))
}
}
#[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)]
#[non_exhaustive]
pub struct FileMatches {
pub path: PathBuf,
pub matches: Vec<SearchMatch>,
pub content: Arc<[u8]>,
}
impl FileMatches {
pub fn lines(&self) -> Vec<(u32, &[u8])> {
let mut spans: Vec<(u32, usize, usize)> = Vec::new();
crate::search::lines::for_each_line(&self.content, |n, start, line| {
spans.push((n, start, line.len()));
});
spans
.into_iter()
.map(|(n, start, len)| (n, &self.content[start..start + len]))
.collect()
}
pub fn context(
&self,
line_number: u32,
before: usize,
after: usize,
) -> Vec<(u32, &[u8], bool)> {
let target = line_number as usize;
let lo = target.saturating_sub(before);
let hi = target.saturating_add(after);
let mut spans: Vec<(u32, usize, usize, bool)> = Vec::new();
crate::search::lines::for_each_line(&self.content, |n, start, line| {
let nn = n as usize;
if nn >= lo && nn <= hi {
spans.push((n, start, line.len(), nn == target));
}
});
spans
.into_iter()
.map(|(n, start, len, is_match)| (n, &self.content[start..start + len], is_match))
.collect()
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
#[derive(Default)]
pub struct SearchOptions {
pub path_filter: Option<String>,
pub file_type: Option<String>,
pub exclude_type: Option<String>,
pub file_types: Vec<String>,
pub exclude_types: Vec<String>,
pub max_results: Option<usize>,
pub case_insensitive: bool,
pub verify_pattern: Option<String>,
pub skip_line_content: bool,
pub deterministic: bool,
#[cfg(any(test, feature = "oracle"))]
pub force_full_scan: 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,
}
#[cfg(test)]
mod api_tests {
use std::sync::Arc;
#[test]
fn index_is_send_sync() {
fn assert_send_sync<T: Send + Sync>() {}
assert_send_sync::<crate::index::Index>();
assert_send_sync::<Arc<crate::index::snapshot::IndexSnapshot>>();
}
}