pub struct Compactor { /* private fields */ }Expand description
AST-aware compactor bound to one language.
Implementations§
Source§impl Compactor
impl Compactor
Sourcepub fn for_path(path: impl AsRef<Path>) -> Result<Self>
pub fn for_path(path: impl AsRef<Path>) -> Result<Self>
Build a compactor by detecting the language from a path’s extension.
pub fn language(&self) -> Language
Sourcepub fn outline(&mut self, source: &str) -> Result<CompactResult>
pub fn outline(&mut self, source: &str) -> Result<CompactResult>
Produce a structural outline: every signature kept, every function body replaced with a one-line placeholder recording how much was elided.
Sourcepub fn compact_to_budget(
&mut self,
source: &str,
max_tokens: usize,
) -> Result<CompactResult>
pub fn compact_to_budget( &mut self, source: &str, max_tokens: usize, ) -> Result<CompactResult>
Return source untouched if it already fits max_tokens; otherwise
compact it to an outline (best-effort — a file that is all signatures may
still exceed the budget).
Sourcepub fn expand(&mut self, source: &str, symbol: &str) -> Result<Vec<String>>
pub fn expand(&mut self, source: &str, symbol: &str) -> Result<Vec<String>>
The inverse of compaction: return the full source of every function or
method named symbol, bodies included.
This is what makes compaction safe to act on. A caller orients on a
skeleton (bodies elided, signatures kept), then — when it needs to edit
one specific function whose body it never saw — fetches just that body on
demand instead of re-reading the whole file. The skeleton already shows
the name above each /* … elided */, so the caller always knows what to
ask for.
Names are not unique (several new methods, an overridden render), so
every match is returned in source order. An empty result means no such
named function exists — the caller should fall back to reading the file.