use std::path::Path;
use crate::index::parser;
use crate::language::Language;
#[derive(Debug, Clone)]
pub struct SymbolFact {
pub kind: String,
pub value: String,
}
#[derive(Debug, Clone)]
pub struct Symbol {
pub name: String,
pub qualified_name: String,
pub kind: String,
pub start_byte: usize,
pub end_byte: usize,
pub start_line: usize,
pub end_line: usize,
pub signature: Option<String>,
pub docs: Option<String>,
pub facts: Vec<SymbolFact>,
}
pub fn symbols_for_file(path: &Path, language: Language, text: &str) -> Vec<Symbol> {
from_parsed(&parser::parse_symbols(path, language, text).unwrap_or_default())
}
pub fn from_parsed(parsed: &[parser::ParsedSymbol]) -> Vec<Symbol> {
parsed
.iter()
.map(|symbol| Symbol {
name: symbol.name.clone(),
qualified_name: symbol.qualified_name.clone(),
kind: symbol.kind.clone(),
start_byte: symbol.start_byte,
end_byte: symbol.end_byte,
start_line: symbol.start_line,
end_line: symbol.end_line,
signature: symbol.signature.clone(),
docs: symbol.docs.clone(),
facts: symbol
.facts
.iter()
.map(|fact| SymbolFact { kind: fact.kind.clone(), value: fact.value.clone() })
.collect(),
})
.collect()
}