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 intelligence(&self) -> &WorkspaceIntelligence

Read workspace-scoped language intelligence result sets (references/call hierarchy/etc.).

Source

pub fn intelligence_mut(&mut self) -> &mut WorkspaceIntelligence

Mutate workspace-scoped language intelligence result sets (references/call hierarchy/etc.).

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 buffer_ids(&self) -> Vec<BufferId>

Return all open buffer ids in deterministic order.

Source

pub fn view_ids(&self) -> Vec<ViewId>

Return all open view ids in deterministic order.

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_line_index( &self, buffer_id: BufferId, ) -> Result<&LineIndex, WorkspaceError>

Get a reference to a buffer’s line index (logical line/column <-> char offsets).

Source

pub fn buffer_char_count( &self, buffer_id: BufferId, ) -> Result<usize, WorkspaceError>

Get the document length for a buffer in Unicode scalar values (Rust chars).

Source

pub fn buffer_text_range( &self, buffer_id: BufferId, start: usize, len: usize, ) -> Result<String, WorkspaceError>

Get a slice of the buffer text as a String by character offset + length.

Notes:

  • start and len are in Unicode scalar indices (Rust chars), not bytes.
  • Out-of-bounds ranges are clamped by the underlying text buffer.
Source

pub fn buffer_decorations( &self, buffer_id: BufferId, ) -> Result<&BTreeMap<DecorationLayerId, Vec<Decoration>>, WorkspaceError>

Get all decoration layers for a buffer.

Source

pub fn folding_regions_for_buffer( &self, buffer_id: BufferId, ) -> Result<Vec<FoldRegion>, WorkspaceError>

Get the current folding regions for a buffer (user folds + derived folds).

Source

pub fn buffer_is_modified( &self, buffer_id: BufferId, ) -> Result<bool, WorkspaceError>

Returns whether a buffer has unsaved text edits.

Notes:

  • This tracks the executor’s “clean point” (usually the last mark_saved_* call), and is restored by undoing back to that clean point.
Source

pub fn line_ending_for_buffer( &self, buffer_id: BufferId, ) -> Result<LineEnding, WorkspaceError>

Return the preferred line ending for saving this buffer.

Source

pub fn set_line_ending_for_buffer( &mut self, buffer_id: BufferId, line_ending: LineEnding, ) -> Result<(), WorkspaceError>

Override the preferred line ending for saving this buffer.

Source

pub fn is_modified_for_view( &self, view_id: ViewId, ) -> Result<bool, WorkspaceError>

Returns whether the view’s underlying buffer has unsaved text edits.

Source

pub fn line_ending_for_view( &self, view_id: ViewId, ) -> Result<LineEnding, WorkspaceError>

Return the preferred line ending for saving this view’s underlying buffer.

Source

pub fn set_line_ending_for_view( &mut self, view_id: ViewId, line_ending: LineEnding, ) -> Result<(), WorkspaceError>

Override the preferred line ending for saving this view’s underlying buffer.

Source

pub fn mark_saved_for_buffer( &mut self, buffer_id: BufferId, ) -> Result<(), WorkspaceError>

Mark the current state of a buffer as saved (clean point).

Source

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

Mark the current state of a view’s buffer as saved (clean point).

Source

pub fn undo_history_snapshot_for_buffer( &self, buffer_id: BufferId, ) -> Result<UndoHistorySnapshot, WorkspaceError>

Capture a persistable snapshot of a buffer’s undo/redo history.

Source

pub fn restore_undo_history_for_buffer( &mut self, buffer_id: BufferId, snapshot: UndoHistorySnapshot, ) -> Result<(), WorkspaceUndoHistoryRestoreError>

Restore a buffer’s undo/redo history from a previously captured snapshot.

Notes:

  • This does not modify the current buffer text.
  • Callers should only restore a snapshot into the same text it was captured from.
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 tab_width_for_view(&self, id: ViewId) -> Result<usize, WorkspaceError>

Get the current tab width setting for a view (in monospace cells).

Source

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

Get the current viewport width setting for a view (in monospace cells).

Source

pub fn wrap_mode_for_view(&self, id: ViewId) -> Result<WrapMode, WorkspaceError>

Get the current soft wrap mode for a view.

Source

pub fn wrap_indent_for_view( &self, id: ViewId, ) -> Result<WrapIndent, WorkspaceError>

Get the current wrapped-line indentation policy for a view.

Source

pub fn tab_key_behavior_for_view( &self, id: ViewId, ) -> Result<TabKeyBehavior, WorkspaceError>

Get the current tab key behavior for a view.

Source

pub fn indentation_config_for_view( &self, id: ViewId, ) -> Result<IndentationConfig, WorkspaceError>

Get the current indentation configuration for a view.

Source

pub fn auto_pairs_config_for_view( &self, id: ViewId, ) -> Result<AutoPairsConfig, WorkspaceError>

Get the current auto-pairs configuration for a view.

Source

pub fn cursor_state_for_view( &self, id: ViewId, ) -> Result<CursorState, WorkspaceError>

Get a view’s normalized cursor/selection snapshot.

This matches the semantics of EditorStateManager::get_cursor_state, but for workspace views.

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 has_active_snippet_session( &self, view_id: ViewId, ) -> Result<bool, WorkspaceError>

Return true if the given view currently has an active snippet session.

Snippet sessions are created by snippet inserts (for example LSP completion items with insertTextFormat == 2) and allow tab/shift-tab navigation between placeholders.

Source

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

Toggle a bookmark at the current cursor line for the given view.

Returns true if a bookmark was added, or false if an existing bookmark on that line was removed.

Source

pub fn bookmark_lines( &self, buffer_id: BufferId, ) -> Result<Vec<usize>, WorkspaceError>

Return all bookmark line numbers (0-based) for a buffer.

Source

pub fn clear_bookmarks( &mut self, buffer_id: BufferId, ) -> Result<(), WorkspaceError>

Clear all bookmarks for a buffer.

Source

pub fn goto_next_bookmark( &mut self, view_id: ViewId, ) -> Result<Option<Position>, WorkspaceError>

Move the cursor to the next bookmark (wrapping to the first bookmark).

Returns the new cursor position, or None if there are no bookmarks.

Source

pub fn goto_prev_bookmark( &mut self, view_id: ViewId, ) -> Result<Option<Position>, WorkspaceError>

Move the cursor to the previous bookmark (wrapping to the last bookmark).

Returns the new cursor position, or None if there are no bookmarks.

Source

pub fn set_mark_at_cursor( &mut self, view_id: ViewId, name: String, ) -> Result<(), WorkspaceError>

Set (or replace) a named mark at the current cursor position of the given view.

Source

pub fn goto_mark( &mut self, view_id: ViewId, name: &str, ) -> Result<Option<Position>, WorkspaceError>

Move the cursor to a named mark (if present).

Returns the new cursor position, or None if the mark does not exist.

Source

pub fn clear_mark( &mut self, buffer_id: BufferId, name: &str, ) -> Result<bool, WorkspaceError>

Remove a named mark from a buffer.

Returns true if the mark existed.

Source

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

Return all mark names for a buffer (deterministic order).

Source

pub fn clear_all_marks( &mut self, buffer_id: BufferId, ) -> Result<(), WorkspaceError>

Clear all marks for a buffer.

Source

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

Record the current cursor position as a jump-list location for a view.

Typical usage: call this before performing a “jump” (go-to-definition, search result, symbol navigation, …).

Source

pub fn jump_back( &mut self, view_id: ViewId, ) -> Result<Option<JumpTarget>, WorkspaceError>

Jump back in the view’s jump list.

Returns the navigation target (including the buffer id). If the target belongs to the current view’s buffer, this method also moves the cursor and clears selection.

Source

pub fn jump_forward( &mut self, view_id: ViewId, ) -> Result<Option<JumpTarget>, WorkspaceError>

Jump forward in the view’s jump list.

Returns the navigation target (including the buffer id). If the target belongs to the current view’s buffer, this method also moves the cursor and clears selection.

Source

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

Clear the jump list (both back/forward stacks) for a view.

Source

pub fn apply_jump_target( &mut self, view_id: ViewId, target: JumpTarget, ) -> Result<(), WorkspaceError>

Apply a previously produced JumpTarget to a view (moves the cursor and clears selection).

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 buffer_text_for_saving( &self, buffer_id: BufferId, ) -> Result<String, WorkspaceError>

Get the full document text converted to the buffer’s preferred line ending for saving.

Source

pub fn text_for_saving_for_view( &self, view_id: ViewId, ) -> Result<String, WorkspaceError>

Get the full document text converted to the view’s preferred line ending for saving.

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.