Skip to main content

OpenDocuments

Struct OpenDocuments 

Source
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

Source

pub fn new() -> Self

Source

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.

Source

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.

Source

pub fn text(&self, path: impl AsRef<Path>) -> Option<String>

The buffer for a path, if it is open.

Source

pub fn is_open(&self, path: impl AsRef<Path>) -> bool

Source

pub fn paths(&self) -> Vec<PathBuf>

Every open document, in an unspecified order.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl Clone for OpenDocuments

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OpenDocuments

Source§

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

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

impl Default for OpenDocuments

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl FileProvider for OpenDocuments

Source§

fn read(&self, path: &Path) -> Option<String>

The contents of a file, or None if it cannot be read. Read more
Source§

fn exists(&self, path: &Path) -> bool

Does this path name a file that can be read? Read more
Source§

fn is_open_buffer(&self, path: &Path) -> bool

Is this path one the editor has open, rather than one on disk? Read more
Source§

fn is_case_insensitive(&self) -> bool

Is this filesystem case-insensitive? 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.