pub(crate) mod json;
pub(crate) mod minimal;
pub(crate) mod pseudo;
pub(crate) mod signatures;
pub(crate) mod structure;
pub(crate) mod toml;
pub(crate) mod truncate;
pub(crate) mod types;
pub(crate) mod utils;
pub(crate) mod yaml;
use crate::{Language, Mode, Result, TransformConfig};
use tree_sitter::Tree;
use truncate::NodeSpan;
type TransformOutput = (String, Vec<NodeSpan>);
pub(crate) fn transform_tree(
source: &str,
tree: &Tree,
language: Language,
config: &TransformConfig,
) -> Result<String> {
let (text, spans) = transform_tree_with_spans(source, tree, language, config)?;
if let Some(max_lines) = config.max_lines {
truncate::truncate_to_lines(&text, &spans, language, max_lines)
} else {
Ok(text)
}
}
fn transform_tree_with_spans(
source: &str,
tree: &Tree,
language: Language,
config: &TransformConfig,
) -> Result<TransformOutput> {
match config.mode {
Mode::Structure => {
structure::transform_structure_with_spans(source, tree, language, config)
}
Mode::Signatures => {
signatures::transform_signatures_with_spans(source, tree, language, config)
}
Mode::Types => types::transform_types_with_spans(source, tree, language, config),
Mode::Pseudo => pseudo::transform_pseudo_with_spans(source, tree, language, config),
Mode::Full => {
let text = source.to_string();
let line_count = text.lines().count();
let spans = vec![NodeSpan::new(0..line_count, "source_file")];
Ok((text, spans))
}
Mode::Minimal => {
let text = minimal::transform_minimal(source, tree, language, config)?;
let line_count = text.lines().count();
let spans = vec![NodeSpan::new(0..line_count, "source_file")];
Ok((text, spans))
}
}
}
#[cfg(test)]
mod tests {
}