pub struct OpenDocuments { /* private fields */ }Expand description
The documents an editor has open, as a provider.
§Why this exists next to crate::OverlayFiles
OverlayFiles is the shape — one provider in front of another — and it is generic over both halves. This is
the front half an editor needs: a set of buffers that changes while the analysis reads through it, keyed by
normalized path, and readable through &self because the handle is shared rather than borrowed — the session
holds one, and every caller that kept this handle holds another.
§What an open document means
The text in here is the text, and the file on disk is not consulted for it. That is the whole difference
between an analysis that works while a user types and one that works after they save: a buffer’s includes
resolve against what has been typed, a buffer that has never been saved has no file at all, and a save is a
notification that the two now agree. An unsaved buffer is indexed as itself — see Session::advance — and its
summary is filed under the hash of its text, so the cache entry is correct the moment that text reaches a
disk and merely unused until it does.
§Why a lock rather than &mut self
Because two owners write here and they are not the same owner. A session writes through
Session::did_open, which holds &mut Session and is the editor’s ordinary notification path; a caller that
kept this handle writes without the session at all. An editor that had to borrow its session mutably to record
one keystroke would serialise every request behind that keystroke. A read-mostly lock is what lets an edit land
between two queries instead — this handle is written while a session reads through it. The lock is never held
across one.
Implementations§
Source§impl OpenDocuments
impl OpenDocuments
pub fn new() -> Self
Sourcepub fn open(&self, path: impl AsRef<Path>, text: impl Into<String>)
pub fn open(&self, path: impl AsRef<Path>, text: impl Into<String>)
A document is now open, with this text — LSP’s didOpen, or any later text for the same path.
One method for both because the analysis has one question about it: which text is this path’s. The protocol distinguishes the two events; nothing here does.
&self rather than &mut self, because the buffer map is behind a lock: a caller holding the handle can
write a buffer while a session reads through it, which is the whole reason the handle exists.
Sourcepub fn close(&self, path: impl AsRef<Path>) -> bool
pub fn close(&self, path: impl AsRef<Path>) -> bool
The document is closed: the path is the filesystem’s again.
Returns whether there was a buffer to drop. The text is not kept: after a close, the disk is the answer, and holding the last buffer would answer with an edit that may never have been saved.
Sourcepub fn text(&self, path: impl AsRef<Path>) -> Option<String>
pub fn text(&self, path: impl AsRef<Path>) -> Option<String>
The buffer for a path, if it is open.
pub fn is_open(&self, path: impl AsRef<Path>) -> bool
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl Clone for OpenDocuments
impl Clone for OpenDocuments
Source§impl Debug for OpenDocuments
impl Debug for OpenDocuments
Source§impl Default for OpenDocuments
impl Default for OpenDocuments
Source§impl FileProvider for OpenDocuments
impl FileProvider for OpenDocuments
Source§fn read(&self, path: &Path) -> Option<String>
fn read(&self, path: &Path) -> Option<String>
None if it cannot be read. Read moreSource§fn is_open_buffer(&self, path: &Path) -> bool
fn is_open_buffer(&self, path: &Path) -> bool
Source§fn is_case_insensitive(&self) -> bool
fn is_case_insensitive(&self) -> bool
Auto Trait Implementations§
impl Forget for OpenDocuments
impl Freeze for OpenDocuments
impl Move for OpenDocuments
impl RefUnwindSafe for OpenDocuments
impl Send for OpenDocuments
impl Sync for OpenDocuments
impl Unpin for OpenDocuments
impl UnsafeUnpin for OpenDocuments
impl UnwindSafe for OpenDocuments
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more