use crate::algorithm::AlgorithmOptions;
use crate::SortMode;
use std::path::PathBuf;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CoverageFilter {
Covered,
Uncovered,
}
#[derive(Debug, Clone)]
pub struct SearchOptions<'a> {
pub db_path: &'a std::path::Path,
pub query: &'a str,
pub path_filter: Option<&'a PathBuf>,
pub kind_filter: Option<&'a str>,
pub language_filter: Option<&'a str>,
pub limit: usize,
pub use_regex: bool,
pub candidates: usize,
pub context: ContextOptions,
pub snippet: SnippetOptions,
pub fqn: FqnOptions,
pub include_score: bool,
pub sort_by: SortMode,
pub metrics: MetricsOptions,
pub ast: AstOptions<'a>,
pub depth: DepthOptions<'a>,
pub algorithm: AlgorithmOptions<'a>,
pub symbol_id: Option<&'a str>,
pub fqn_pattern: Option<&'a str>,
pub exact_fqn: Option<&'a str>,
pub coverage_filter: Option<CoverageFilter>,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct ContextOptions {
pub include: bool,
pub lines: usize,
pub max_lines: usize,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct SnippetOptions {
pub include: bool,
pub max_bytes: usize,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct FqnOptions {
pub fqn: bool,
pub canonical_fqn: bool,
pub display_fqn: bool,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct MetricsOptions {
pub min_complexity: Option<usize>,
pub max_complexity: Option<usize>,
pub min_fan_in: Option<usize>,
pub min_fan_out: Option<usize>,
}
#[derive(Debug, Clone, Default)]
pub struct AstOptions<'a> {
pub ast_kinds: Vec<String>,
pub with_ast_context: bool,
pub _phantom: std::marker::PhantomData<&'a ()>,
}
impl<'a> AstOptions<'a> {
pub fn new() -> Self {
Self {
ast_kinds: Vec::new(),
with_ast_context: false,
_phantom: std::marker::PhantomData,
}
}
pub fn has_ast_kinds(&self) -> bool {
!self.ast_kinds.is_empty()
}
pub fn first_ast_kind(&self) -> Option<&str> {
self.ast_kinds.first().map(|s| s.as_str())
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct DepthOptions<'a> {
pub min_depth: Option<usize>,
pub max_depth: Option<usize>,
pub inside: Option<&'a str>,
pub contains: Option<&'a str>,
}