pub struct Buffer { /* private fields */ }
Implementations§
source§impl Buffer
impl Buffer
pub fn new<T>(replica_id: u16, id: u64, base_text: T) -> Bufferwhere T: Into<String>,
pub fn remote(remote_id: u64, replica_id: u16, base_text: String) -> Buffer
pub fn from_proto( replica_id: u16, message: BufferState, file: Option<Arc<dyn File, Global>> ) -> Result<Buffer, Error>
pub fn to_proto(&self) -> BufferState
pub fn serialize_ops( &self, since: Option<Global>, cx: &AppContext ) -> Task<Vec<Operation, Global>>
pub fn with_language( self, language: Arc<Language, Global>, cx: &mut ModelContext<'_, Buffer> ) -> Buffer
pub fn build( buffer: Buffer, diff_base: Option<String>, file: Option<Arc<dyn File, Global>> ) -> Buffer
pub fn snapshot(&self) -> BufferSnapshot
pub fn as_text_snapshot(&self) -> &BufferSnapshot
pub fn text_snapshot(&self) -> BufferSnapshot
pub fn file(&self) -> Option<&Arc<dyn File, Global>>
pub fn saved_version(&self) -> &Global
pub fn saved_version_fingerprint(&self) -> HashMatrix
pub fn saved_mtime(&self) -> SystemTime
pub fn set_language( &mut self, language: Option<Arc<Language, Global>>, cx: &mut ModelContext<'_, Buffer> )
pub fn set_language_registry( &mut self, language_registry: Arc<LanguageRegistry, Global> )
pub fn did_save( &mut self, version: Global, fingerprint: HashMatrix, mtime: SystemTime, cx: &mut ModelContext<'_, Buffer> )
pub fn reload( &mut self, cx: &mut ModelContext<'_, Buffer> ) -> Receiver<Option<Transaction>>
pub fn did_reload( &mut self, version: Global, fingerprint: HashMatrix, line_ending: LineEnding, mtime: SystemTime, cx: &mut ModelContext<'_, Buffer> )
pub fn file_updated( &mut self, new_file: Arc<dyn File, Global>, cx: &mut ModelContext<'_, Buffer> )
pub fn diff_base(&self) -> Option<&str>
pub fn set_diff_base( &mut self, diff_base: Option<String>, cx: &mut ModelContext<'_, Buffer> )
pub fn git_diff_recalc( &mut self, cx: &mut ModelContext<'_, Buffer> ) -> Option<Task<()>>
pub fn close(&mut self, cx: &mut ModelContext<'_, Buffer>)
pub fn language(&self) -> Option<&Arc<Language, Global>>
pub fn language_at<D>(&self, position: D) -> Option<Arc<Language, Global>>where D: ToOffset,
pub fn parse_count(&self) -> usize
pub fn selections_update_count(&self) -> usize
pub fn diagnostics_update_count(&self) -> usize
pub fn file_update_count(&self) -> usize
pub fn git_diff_update_count(&self) -> usize
pub fn contains_unknown_injections(&self) -> bool
sourcepub fn reparse(&mut self, cx: &mut ModelContext<'_, Buffer>)
pub fn reparse(&mut self, cx: &mut ModelContext<'_, Buffer>)
Called after an edit to synchronize the buffer’s main parse tree with the buffer’s new underlying state.
Locks the syntax map and interpolates the edits since the last reparse into the foreground syntax tree.
Then takes a stable snapshot of the syntax map before unlocking it. The snapshot with the interpolated edits is sent to a background thread, where we ask Tree-sitter to perform an incremental parse.
Meanwhile, in the foreground, we block the main thread for up to 1ms waiting on the parse to complete. As soon as it completes, we proceed synchronously, unless a 1ms timeout elapses.
If we time out waiting on the parse, we spawn a second task waiting until the parse does complete and return with the interpolated tree still in the foreground. When the background parse completes, call back into the main thread and assign the foreground parse state.
If the buffer or grammar changed since the start of the background parse, initiate an additional reparse recursively. To avoid concurrent parses for the same buffer, we only initiate a new parse if we are not already parsing in the background.
pub fn update_diagnostics( &mut self, server_id: LanguageServerId, diagnostics: DiagnosticSet, cx: &mut ModelContext<'_, Buffer> )
pub fn edit_for_indent_size_adjustment( row: u32, current_size: IndentSize, new_size: IndentSize ) -> Option<(Range<Point>, String)>
pub fn diff(&self, new_text: String, cx: &AppContext) -> Task<Diff>
sourcepub fn remove_trailing_whitespace(&self, cx: &AppContext) -> Task<Diff>
pub fn remove_trailing_whitespace(&self, cx: &AppContext) -> Task<Diff>
Spawn a background task that searches the buffer for any whitespace
at the ends of a lines, and returns a Diff
that removes that whitespace.
sourcepub fn ensure_final_newline(&mut self, cx: &mut ModelContext<'_, Buffer>)
pub fn ensure_final_newline(&mut self, cx: &mut ModelContext<'_, Buffer>)
Ensure that the buffer ends with a single newline character, and no other whitespace.
sourcepub fn apply_diff(
&mut self,
diff: Diff,
cx: &mut ModelContext<'_, Buffer>
) -> Option<Lamport>
pub fn apply_diff( &mut self, diff: Diff, cx: &mut ModelContext<'_, Buffer> ) -> Option<Lamport>
Apply a diff to the buffer. If the buffer has changed since the given diff was calculated, then adjust the diff to account for those changes, and discard any parts of the diff that conflict with those changes.