Skip to main content

TreeSitterIndenter

Struct TreeSitterIndenter 

Source
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 @indent indicate syntax nodes that increase indentation for their contents.
  • Captures named @outdent indicate 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

Source

pub fn new(config: TreeSitterIndenterConfig) -> Result<Self, TreeSitterError>

Create a new indenter from the given config.

Source

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 TextDelta required), to make it easy to drive from UI/FFI boundaries.
  • Re-parsing is skipped when version is unchanged.
Source

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.

Source

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§

Source§

impl Debug for TreeSitterIndenter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.