use std::path::PathBuf;
use std::time::SystemTime;
#[derive(Debug)]
pub enum QueryType {
FilePath(PathBuf),
FilePathLine(PathBuf, usize),
Glob(String),
Symbol(String),
Concept(String),
Regex(String),
Fallthrough(String),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Lang {
Rust,
TypeScript,
Tsx,
JavaScript,
Python,
Go,
Java,
Scala,
C,
Cpp,
Ruby,
Php,
Swift,
Kotlin,
CSharp,
Elixir,
Dockerfile,
Make,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FileType {
Code(Lang),
Markdown,
StructuredData,
Tabular,
Log,
Other,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ViewMode {
Full,
Outline,
OutlineCascade,
Signatures,
Keys,
#[allow(dead_code)]
HeadTail,
Empty,
Generated,
#[allow(dead_code)]
Binary,
#[allow(dead_code)]
Error,
Section,
SectionOutline,
}
impl std::fmt::Display for ViewMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Full => write!(f, "full"),
Self::Outline => write!(f, "outline"),
Self::OutlineCascade => write!(f, "outline (full requested, over budget)"),
Self::Signatures => write!(f, "signatures (full requested, over budget)"),
Self::Keys => write!(f, "keys"),
Self::HeadTail => write!(f, "head+tail"),
Self::Empty => write!(f, "empty"),
Self::Generated => write!(f, "generated — skipped"),
Self::Binary => write!(f, "skipped"),
Self::Error => write!(f, "error"),
Self::Section => write!(f, "section"),
Self::SectionOutline => write!(f, "section, outline (over limit)"),
}
}
}
#[derive(Debug, Clone)]
pub struct Match {
pub path: PathBuf,
pub line: u32,
pub text: String,
pub is_definition: bool,
pub exact: bool,
pub file_lines: u32,
pub mtime: SystemTime,
pub def_range: Option<(u32, u32)>,
pub def_name: Option<String>,
pub def_weight: u16,
pub impl_target: Option<String>,
pub base_target: Option<String>,
pub in_comment: bool,
}
#[derive(Debug)]
pub struct SearchResult {
pub query: String,
pub scope: PathBuf,
pub matches: Vec<Match>,
pub total_found: usize,
pub definitions: usize,
pub usages: usize,
pub comments: usize,
pub has_more: bool,
pub offset: usize,
}
#[derive(Debug)]
pub struct OutlineEntry {
pub kind: OutlineKind,
pub name: String,
pub start_line: u32,
pub end_line: u32,
pub signature: Option<String>,
pub children: Vec<OutlineEntry>,
pub doc: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum OutlineKind {
Import,
Function,
Class,
Struct,
Interface,
TypeAlias,
Enum,
Constant,
Variable,
ImmutableVariable,
Export,
#[allow(dead_code)]
Property,
Module,
#[allow(dead_code)]
TestSuite,
#[allow(dead_code)]
TestCase,
}
pub(crate) fn is_test_file(path: &std::path::Path) -> bool {
let s = path.to_string_lossy();
s.contains(".test.") || s.contains(".spec.") || s.contains("__tests__/")
}
#[must_use]
pub fn estimate_tokens(byte_len: u64) -> u64 {
byte_len.div_ceil(4)
}
#[must_use]
pub fn truncate_str(s: &str, max: usize) -> &str {
if s.len() <= max {
s
} else {
&s[..s.floor_char_boundary(max)]
}
}