Skip to main content

FoldingManager

Struct FoldingManager 

Source
pub struct FoldingManager { /* private fields */ }
Expand description

Folding manager

Implementations§

Source§

impl FoldingManager

Source

pub fn new() -> Self

Create an empty folding manager.

Source

pub fn add_region(&mut self, region: FoldRegion)

Add a user-created fold region.

Source

pub fn remove_region(&mut self, start_line: usize, end_line: usize) -> bool

Remove a user-created fold region.

Source

pub fn get_region_for_line(&self, line: usize) -> Option<&FoldRegion>

Get fold region containing specified line (merged view).

Source

pub fn get_region_for_line_mut( &mut self, line: usize, ) -> Option<&mut FoldRegion>

Get mutable reference to a fold region containing specified line (prefers user folds).

Source

pub fn collapse_line(&mut self, line: usize) -> bool

Collapse specified line

Source

pub fn expand_line(&mut self, line: usize) -> bool

Expand specified line

Source

pub fn toggle_line(&mut self, line: usize) -> bool

Toggle fold state of specified line

Source

pub fn toggle_region_starting_at_line(&mut self, start_line: usize) -> bool

Toggle fold region starting at specified line (preferring “innermost” region).

rust-analyzer / LSP folding ranges often contain nested regions. To make TUI and other frontends behave more intuitively when “cursor is on a start line”, we choose:

  • Among all regions with start_line == line, the one with smallest end_line (innermost)
Source

pub fn logical_to_visual( &self, logical_line: usize, base_visual: usize, ) -> Option<usize>

Calculate mapping from logical line to visual line

Returns the visual line number for the specified logical line number, or None if folded

Source

pub fn visual_to_logical(&self, visual_line: usize, base_visual: usize) -> usize

Calculate mapping from visual line to logical line

Source

pub fn collapsed_hidden_line_count(&self) -> usize

Total number of logical lines hidden by collapsed folds.

Overlapping and nested collapsed regions are counted once (the hidden ranges are merged first), so the result never exceeds the document’s logical line count.

Source

pub fn regions(&self) -> &[FoldRegion]

Get all fold regions

Source

pub fn derived_regions(&self) -> &[FoldRegion]

Get all derived fold regions.

Source

pub fn user_regions(&self) -> &[FoldRegion]

Get all user-created fold regions.

Source

pub fn clear(&mut self)

Clear all fold regions (derived + user).

Source

pub fn clear_derived_regions(&mut self)

Clear all derived fold regions, leaving user folds intact.

Source

pub fn replace_derived_regions(&mut self, regions: Vec<FoldRegion>)

Replace derived fold regions (will be sorted by start line and deduplicated).

Source

pub fn replace_derived_regions_preserving_collapsed( &mut self, regions: Vec<FoldRegion>, )

Replace derived fold regions while preserving collapsed state across small range drift.

Source

pub fn replace_regions(&mut self, regions: Vec<FoldRegion>)

Replace fold regions with new list (legacy API).

This replaces derived fold regions, leaving user folds intact.

Source

pub fn expand_all(&mut self)

Expand all folds

Source

pub fn collapse_all(&mut self)

Collapse all regions

Source

pub fn apply_line_delta(&mut self, edit_line: usize, line_delta: isize)

Update fold regions to account for an edit that changes the number of logical lines.

This is intended to keep user folds stable across newline insertions/deletions.

  • edit_line is the logical line where the edit occurred (pre-edit).
  • line_delta is the net change in line count (+n for inserted newlines, -n for deleted).
Source

pub fn clamp_to_line_count(&mut self, line_count: usize)

Clamp fold regions to the given line_count after a text edit, dropping invalid regions.

Trait Implementations§

Source§

impl Default for FoldingManager

Source§

fn default() -> Self

Returns the “default value” for a type. 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.