pub struct Workspace { /* private fields */ }Expand description
A collection of open buffers and their views.
Implementations§
Source§impl Workspace
impl Workspace
Sourcepub fn view_count(&self) -> usize
pub fn view_count(&self) -> usize
Returns the number of open views.
Sourcepub fn active_view_id(&self) -> Option<ViewId>
pub fn active_view_id(&self) -> Option<ViewId>
Return the active view id (if any).
Sourcepub fn active_buffer_id(&self) -> Option<BufferId>
pub fn active_buffer_id(&self) -> Option<BufferId>
Return the active buffer id (if any).
Sourcepub fn set_active_view(&mut self, id: ViewId) -> Result<(), WorkspaceError>
pub fn set_active_view(&mut self, id: ViewId) -> Result<(), WorkspaceError>
Set the active view.
Sourcepub fn open_buffer(
&mut self,
uri: Option<String>,
text: &str,
viewport_width: usize,
) -> Result<OpenBufferResult, WorkspaceError>
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.
uriis optional and host-provided (e.g.file:///...).textis the initial contents.viewport_widthis the initial view’s wrap width.
Sourcepub fn close_buffer(&mut self, id: BufferId) -> Result<(), WorkspaceError>
pub fn close_buffer(&mut self, id: BufferId) -> Result<(), WorkspaceError>
Close a buffer (and all its views).
Sourcepub fn close_view(&mut self, id: ViewId) -> Result<(), WorkspaceError>
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.
Sourcepub fn create_view(
&mut self,
buffer: BufferId,
viewport_width: usize,
) -> Result<ViewId, WorkspaceError>
pub fn create_view( &mut self, buffer: BufferId, viewport_width: usize, ) -> Result<ViewId, WorkspaceError>
Create a new view into an existing buffer.
Sourcepub fn buffer_id_for_uri(&self, uri: &str) -> Option<BufferId>
pub fn buffer_id_for_uri(&self, uri: &str) -> Option<BufferId>
Look up a buffer by uri.
Sourcepub fn buffer_metadata(&self, id: BufferId) -> Option<&BufferMetadata>
pub fn buffer_metadata(&self, id: BufferId) -> Option<&BufferMetadata>
Get a buffer’s metadata.
Sourcepub fn buffer_id_for_view(&self, id: ViewId) -> Result<BufferId, WorkspaceError>
pub fn buffer_id_for_view(&self, id: ViewId) -> Result<BufferId, WorkspaceError>
Get the buffer id that a view is pointing at.
Sourcepub fn cursor_position_for_view(
&self,
id: ViewId,
) -> Result<Position, WorkspaceError>
pub fn cursor_position_for_view( &self, id: ViewId, ) -> Result<Position, WorkspaceError>
Get the primary cursor position for a view.
Sourcepub fn selection_for_view(
&self,
id: ViewId,
) -> Result<Option<Selection>, WorkspaceError>
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”).
Sourcepub fn scroll_top_for_view(&self, id: ViewId) -> Result<usize, WorkspaceError>
pub fn scroll_top_for_view(&self, id: ViewId) -> Result<usize, WorkspaceError>
Get the scroll position (top visual row) for a view.
Sourcepub fn scroll_sub_row_offset_for_view(
&self,
id: ViewId,
) -> Result<u16, WorkspaceError>
pub fn scroll_sub_row_offset_for_view( &self, id: ViewId, ) -> Result<u16, WorkspaceError>
Get the sub-row smooth-scroll offset for a view.
Sourcepub fn overscan_rows_for_view(
&self,
id: ViewId,
) -> Result<usize, WorkspaceError>
pub fn overscan_rows_for_view( &self, id: ViewId, ) -> Result<usize, WorkspaceError>
Get overscan rows for a view.
Sourcepub fn smooth_scroll_state_for_view(
&self,
id: ViewId,
) -> Result<ViewSmoothScrollState, WorkspaceError>
pub fn smooth_scroll_state_for_view( &self, id: ViewId, ) -> Result<ViewSmoothScrollState, WorkspaceError>
Get smooth-scroll state for a view.
Sourcepub fn set_buffer_uri(
&mut self,
id: BufferId,
uri: Option<String>,
) -> Result<(), WorkspaceError>
pub fn set_buffer_uri( &mut self, id: BufferId, uri: Option<String>, ) -> Result<(), WorkspaceError>
Update a buffer’s uri/path.
Sourcepub fn view_version(&self, id: ViewId) -> Option<u64>
pub fn view_version(&self, id: ViewId) -> Option<u64>
Get a view’s current version (increments on view-local changes and buffer changes).
Sourcepub fn last_text_delta_for_view(&self, id: ViewId) -> Option<&Arc<TextDelta>>
pub fn last_text_delta_for_view(&self, id: ViewId) -> Option<&Arc<TextDelta>>
Get the last broadcast text delta for this view (if any).
Sourcepub fn take_last_text_delta_for_view(
&mut self,
id: ViewId,
) -> Option<Arc<TextDelta>>
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).
Sourcepub fn take_last_text_delta_for_buffer(
&mut self,
id: BufferId,
) -> Result<Option<Arc<TextDelta>>, WorkspaceError>
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.
Sourcepub fn subscribe_view<F>(
&mut self,
id: ViewId,
callback: F,
) -> Result<(), WorkspaceError>
pub fn subscribe_view<F>( &mut self, id: ViewId, callback: F, ) -> Result<(), WorkspaceError>
Subscribe to changes for a view.
Sourcepub fn execute(
&mut self,
view_id: ViewId,
command: Command,
) -> Result<CommandResult, WorkspaceError>
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.
Sourcepub fn set_viewport_height(
&mut self,
view_id: ViewId,
height: usize,
) -> Result<(), WorkspaceError>
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).
Sourcepub fn set_scroll_top(
&mut self,
view_id: ViewId,
scroll_top: usize,
) -> Result<(), WorkspaceError>
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.
Sourcepub fn set_scroll_sub_row_offset(
&mut self,
view_id: ViewId,
sub_row_offset: u16,
) -> Result<(), WorkspaceError>
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.
Sourcepub fn set_overscan_rows(
&mut self,
view_id: ViewId,
overscan_rows: usize,
) -> Result<(), WorkspaceError>
pub fn set_overscan_rows( &mut self, view_id: ViewId, overscan_rows: usize, ) -> Result<(), WorkspaceError>
Set overscan rows for a view.
Sourcepub fn set_smooth_scroll_state(
&mut self,
view_id: ViewId,
state: ViewSmoothScrollState,
) -> Result<(), WorkspaceError>
pub fn set_smooth_scroll_state( &mut self, view_id: ViewId, state: ViewSmoothScrollState, ) -> Result<(), WorkspaceError>
Set smooth-scroll state for a view.
Sourcepub fn viewport_state_for_view(
&mut self,
view_id: ViewId,
) -> Result<WorkspaceViewportState, WorkspaceError>
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.
Sourcepub fn total_visual_lines_for_view(
&mut self,
view_id: ViewId,
) -> Result<usize, WorkspaceError>
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).
Sourcepub fn visual_to_logical_for_view(
&mut self,
view_id: ViewId,
visual_row: usize,
) -> Result<(usize, usize), WorkspaceError>
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.
Sourcepub fn logical_to_visual_for_view(
&mut self,
view_id: ViewId,
line: usize,
column: usize,
) -> Result<Option<(usize, usize)>, WorkspaceError>
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.
Sourcepub fn visual_position_to_logical_for_view(
&mut self,
view_id: ViewId,
visual_row: usize,
x_cells: usize,
) -> Result<Option<Position>, WorkspaceError>
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.
Sourcepub fn buffer_text(&self, buffer_id: BufferId) -> Result<String, WorkspaceError>
pub fn buffer_text(&self, buffer_id: BufferId) -> Result<String, WorkspaceError>
Get the full document text for a buffer.
Sourcepub fn get_viewport_content_styled(
&mut self,
view_id: ViewId,
start_visual_row: usize,
count: usize,
) -> Result<HeadlessGrid, WorkspaceError>
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).
Sourcepub fn get_minimap_content(
&mut self,
view_id: ViewId,
start_visual_row: usize,
count: usize,
) -> Result<MinimapGrid, WorkspaceError>
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).
Sourcepub fn get_viewport_content_composed(
&mut self,
view_id: ViewId,
start_visual_row: usize,
count: usize,
) -> Result<ComposedGrid, WorkspaceError>
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.
Sourcepub fn apply_processing_edits<I>(
&mut self,
buffer_id: BufferId,
edits: I,
) -> Result<(), WorkspaceError>where
I: IntoIterator<Item = ProcessingEdit>,
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.
Sourcepub fn search_all_open_buffers(
&self,
query: &str,
options: SearchOptions,
) -> Result<Vec<WorkspaceSearchResult>, SearchError>
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).
Sourcepub fn apply_text_edits<I>(
&mut self,
edits: I,
) -> Result<Vec<(BufferId, usize)>, WorkspaceError>
pub fn apply_text_edits<I>( &mut self, edits: I, ) -> Result<Vec<(BufferId, usize)>, WorkspaceError>
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
BufferIdorder.