use std::fmt;
use std::path::PathBuf;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SymbolKind {
Function,
Class,
Method,
Interface,
TypeAlias,
Variable,
}
impl fmt::Display for SymbolKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SymbolKind::Function => write!(f, "function"),
SymbolKind::Class => write!(f, "class"),
SymbolKind::Method => write!(f, "method"),
SymbolKind::Interface => write!(f, "interface"),
SymbolKind::TypeAlias => write!(f, "type"),
SymbolKind::Variable => write!(f, "variable"),
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct ByteRange {
pub start_byte: usize,
pub end_byte: usize,
pub start_line: usize,
pub end_line: usize,
}
#[cfg(feature = "semantic")]
impl From<tree_sitter::Node<'_>> for ByteRange {
fn from(n: tree_sitter::Node) -> Self {
ByteRange {
start_byte: n.start_byte(),
end_byte: n.end_byte(),
start_line: n.start_position().row + 1,
end_line: n.end_position().row + 1,
}
}
}
#[derive(Debug, Clone)]
pub struct Symbol {
pub kind: SymbolKind,
pub name: String,
pub range: ByteRange,
pub signature: String,
pub is_exported: bool,
pub parent_class: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[allow(dead_code)]
pub enum ImportKind {
Header,
Module,
Qualified,
}
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct Import {
pub names: Vec<String>,
pub source: String,
pub kind: ImportKind,
}
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct ExtractedFile {
pub file_path: PathBuf,
pub symbols: Vec<Symbol>,
pub imports: Vec<Import>,
pub exports: Vec<String>,
pub warnings: Vec<String>,
pub mtime: std::time::SystemTime,
pub size: u64,
pub head_hash: u64,
}