Skip to main content

Workspace

Struct Workspace 

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

A collection of open buffers and their views.

Implementations§

Source§

impl Workspace

Source

pub fn new() -> Self

Create an empty workspace.

Source

pub fn len(&self) -> usize

Returns the number of open buffers.

Source

pub fn is_empty(&self) -> bool

Returns true if there are no open buffers.

Source

pub fn view_count(&self) -> usize

Returns the number of open views.

Source

pub fn active_view_id(&self) -> Option<ViewId>

Return the active view id (if any).

Source

pub fn active_buffer_id(&self) -> Option<BufferId>

Return the active buffer id (if any).

Source

pub fn set_active_view(&mut self, id: ViewId) -> Result<(), WorkspaceError>

Set the active view.

Source

pub fn open_buffer( &mut self, uri: Option<String>, text: &str, viewport_width: usize, ) -> Result<OpenBufferResult, WorkspaceError>

Open a new buffer in the workspace, creating an initial view.

  • uri is optional and host-provided (e.g. file:///...).
  • text is the initial contents.
  • viewport_width is the initial view’s wrap width.
Source

pub fn close_buffer(&mut self, id: BufferId) -> Result<(), WorkspaceError>

Close a buffer (and all its views).

Source

pub fn close_view(&mut self, id: ViewId) -> Result<(), WorkspaceError>

Close a view. If it was the last view of its buffer, the buffer is also closed.

Source

pub fn create_view( &mut self, buffer: BufferId, viewport_width: usize, ) -> Result<ViewId, WorkspaceError>

Create a new view into an existing buffer.

Source

pub fn buffer_id_for_uri(&self, uri: &str) -> Option<BufferId>

Look up a buffer by uri.

Source

pub fn buffer_metadata(&self, id: BufferId) -> Option<&BufferMetadata>

Get a buffer’s metadata.

Source

pub fn buffer_id_for_view(&self, id: ViewId) -> Result<BufferId, WorkspaceError>

Get the buffer id that a view is pointing at.

Source

pub fn cursor_position_for_view( &self, id: ViewId, ) -> Result<Position, WorkspaceError>

Get the primary cursor position for a view.

Source

pub fn selection_for_view( &self, id: ViewId, ) -> Result<Option<Selection>, WorkspaceError>

Get the primary selection for a view (None means “empty selection / caret only”).

Source

pub fn scroll_top_for_view(&self, id: ViewId) -> Result<usize, WorkspaceError>

Get the scroll position (top visual row) for a view.

Source

pub fn scroll_sub_row_offset_for_view( &self, id: ViewId, ) -> Result<u16, WorkspaceError>

Get the sub-row smooth-scroll offset for a view.

Source

pub fn overscan_rows_for_view( &self, id: ViewId, ) -> Result<usize, WorkspaceError>

Get overscan rows for a view.

Source

pub fn smooth_scroll_state_for_view( &self, id: ViewId, ) -> Result<ViewSmoothScrollState, WorkspaceError>

Get smooth-scroll state for a view.

Source

pub fn set_buffer_uri( &mut self, id: BufferId, uri: Option<String>, ) -> Result<(), WorkspaceError>

Update a buffer’s uri/path.

Source

pub fn view_version(&self, id: ViewId) -> Option<u64>

Get a view’s current version (increments on view-local changes and buffer changes).

Source

pub fn last_text_delta_for_view(&self, id: ViewId) -> Option<&Arc<TextDelta>>

Get the last broadcast text delta for this view (if any).

Source

pub fn take_last_text_delta_for_view( &mut self, id: ViewId, ) -> Option<Arc<TextDelta>>

Take the last broadcast text delta for this view (if any).

Source

pub fn take_last_text_delta_for_buffer( &mut self, id: BufferId, ) -> Result<Option<Arc<TextDelta>>, WorkspaceError>

Take the last text delta for a buffer (if any).

This is useful for incremental consumers (e.g. LSP sync) that want to observe each buffer edit exactly once, regardless of how many views exist for that buffer.

Source

pub fn subscribe_view<F>( &mut self, id: ViewId, callback: F, ) -> Result<(), WorkspaceError>
where F: FnMut(&StateChange) + Send + 'static,

Subscribe to changes for a view.

Source

pub fn execute( &mut self, view_id: ViewId, command: Command, ) -> Result<CommandResult, WorkspaceError>

Execute a command against a specific view.

  • Cursor/selection state is view-local.
  • Text edits and derived-state edits are applied to the underlying buffer.
  • Any text delta is broadcast to all views of that buffer.
Source

pub fn set_viewport_height( &mut self, view_id: ViewId, height: usize, ) -> Result<(), WorkspaceError>

Set the viewport height for a view (used for ViewportState calculations).

Source

pub fn set_scroll_top( &mut self, view_id: ViewId, scroll_top: usize, ) -> Result<(), WorkspaceError>

Set the scroll position (top visual row) for a view.

Source

pub fn set_scroll_sub_row_offset( &mut self, view_id: ViewId, sub_row_offset: u16, ) -> Result<(), WorkspaceError>

Set sub-row smooth-scroll offset for a view.

Source

pub fn set_overscan_rows( &mut self, view_id: ViewId, overscan_rows: usize, ) -> Result<(), WorkspaceError>

Set overscan rows for a view.

Source

pub fn set_smooth_scroll_state( &mut self, view_id: ViewId, state: ViewSmoothScrollState, ) -> Result<(), WorkspaceError>

Set smooth-scroll state for a view.

Source

pub fn viewport_state_for_view( &mut self, view_id: ViewId, ) -> Result<WorkspaceViewportState, WorkspaceError>

Get viewport state for a view, including total visual lines and overscan prefetch range.

Source

pub fn total_visual_lines_for_view( &mut self, view_id: ViewId, ) -> Result<usize, WorkspaceError>

Get total visual lines for a view (wrap + folding aware).

Source

pub fn visual_to_logical_for_view( &mut self, view_id: ViewId, visual_row: usize, ) -> Result<(usize, usize), WorkspaceError>

Map global visual row to (logical_line, visual_in_logical) for a view.

Source

pub fn logical_to_visual_for_view( &mut self, view_id: ViewId, line: usize, column: usize, ) -> Result<Option<(usize, usize)>, WorkspaceError>

Map logical position to global visual (row, x_cells) for a view.

Source

pub fn visual_position_to_logical_for_view( &mut self, view_id: ViewId, visual_row: usize, x_cells: usize, ) -> Result<Option<Position>, WorkspaceError>

Map visual (row, x_cells) back to logical position for a view.

Source

pub fn buffer_text(&self, buffer_id: BufferId) -> Result<String, WorkspaceError>

Get the full document text for a buffer.

Source

pub fn get_viewport_content_styled( &mut self, view_id: ViewId, start_visual_row: usize, count: usize, ) -> Result<HeadlessGrid, WorkspaceError>

Get styled viewport content for a view (by visual line).

Source

pub fn get_minimap_content( &mut self, view_id: ViewId, start_visual_row: usize, count: usize, ) -> Result<MinimapGrid, WorkspaceError>

Get lightweight minimap content for a view (by visual line).

Source

pub fn get_viewport_content_composed( &mut self, view_id: ViewId, start_visual_row: usize, count: usize, ) -> Result<ComposedGrid, WorkspaceError>

Get a decoration-aware composed viewport snapshot for a view (by composed visual line).

This snapshot can include virtual text (inlay hints, code lens) injected from the buffer’s decoration layers. See crate::EditorCore::get_headless_grid_composed for details.

Source

pub fn apply_processing_edits<I>( &mut self, buffer_id: BufferId, edits: I, ) -> Result<(), WorkspaceError>
where I: IntoIterator<Item = ProcessingEdit>,

Apply derived-state edits to a buffer and broadcast them to all views of that buffer.

Source

pub fn search_all_open_buffers( &self, query: &str, options: SearchOptions, ) -> Result<Vec<WorkspaceSearchResult>, SearchError>

Search across all open buffers in the workspace.

  • This is purely in-memory (no file I/O).
  • Match ranges are returned as character offsets (half-open).
Source

pub fn apply_text_edits<I>( &mut self, edits: I, ) -> Result<Vec<(BufferId, usize)>, WorkspaceError>
where I: IntoIterator<Item = (BufferId, Vec<TextEditSpec>)>,

Apply a set of text edits to multiple open buffers.

  • This is purely in-memory (no file I/O).
  • Edits are applied as a single undoable step per buffer.
  • Buffers are applied in deterministic BufferId order.

Trait Implementations§

Source§

impl Debug for Workspace

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Workspace

Source§

fn default() -> Workspace

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 = 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.