pub struct TreeSitterIndenter { /* private fields */ }Expand description
A small Tree-sitter powered indenter driven by an indents.scm query.
This is an optional companion to crate::TreeSitterProcessor:
- The processor focuses on derived state (highlighting/folding).
- The indenter focuses on edit-time indentation decisions (auto-indent on newline).
Query conventions (minimal subset):
- Captures named
@indentindicate syntax nodes that increase indentation for their contents. - Captures named
@outdentindicate syntax tokens/nodes that outdent when they begin a line.
Notes:
- This implementation is intentionally conservative; it aims to provide a solid baseline.
Implementations§
Source§impl TreeSitterIndenter
impl TreeSitterIndenter
Sourcepub fn new(config: TreeSitterIndenterConfig) -> Result<Self, TreeSitterError>
pub fn new(config: TreeSitterIndenterConfig) -> Result<Self, TreeSitterError>
Create a new indenter from the given config.
Sourcepub fn sync_to_text(
&mut self,
version: u64,
text: &str,
) -> Result<(), TreeSitterError>
pub fn sync_to_text( &mut self, version: u64, text: &str, ) -> Result<(), TreeSitterError>
Synchronize the indenter with the given editor version and full text.
Notes:
- This API is intentionally “full text” based (no
TextDeltarequired), to make it easy to drive from UI/FFI boundaries. - Re-parsing is skipped when
versionis unchanged.
Sourcepub fn indent_string_for_line(
&self,
line: usize,
indent_style: IndentStyle,
) -> Option<String>
pub fn indent_string_for_line( &self, line: usize, indent_style: IndentStyle, ) -> Option<String>
Compute the desired leading whitespace for a logical line.
Returns None if the indenter is not yet synchronized (call Self::sync_to_text first),
or if line is out of range.
Sourcepub fn reindent_text_edit_for_line(
&self,
line: usize,
indent_style: IndentStyle,
) -> Option<TextEditSpec>
pub fn reindent_text_edit_for_line( &self, line: usize, indent_style: IndentStyle, ) -> Option<TextEditSpec>
Build a text edit that replaces the current line’s leading whitespace with the computed Tree-sitter indentation.
Returns None if no change is needed, if the indenter is not synchronized, or if line
is out of range.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for TreeSitterIndenter
impl !UnwindSafe for TreeSitterIndenter
impl Freeze for TreeSitterIndenter
impl Send for TreeSitterIndenter
impl Sync for TreeSitterIndenter
impl Unpin for TreeSitterIndenter
impl UnsafeUnpin for TreeSitterIndenter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more