diff options
| author | bors <bors@rust-lang.org> | 2022-11-07 16:22:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-11-07 16:22:33 +0000 |
| commit | 0aa0da9dda7eaefe81b09f6e2f61b0bcff16a6be (patch) | |
| tree | 7453fdae876d166edee8470a12d6c04cdf689a35 /crates/rust-analyzer/src/mem_docs.rs | |
| parent | a27e4dad379453466a3d5b4500645c617c4e3dc6 (diff) | |
| parent | fa70b0a86ec89ea53c0855caba42d121cbcc5697 (diff) | |
| download | rust-0aa0da9dda7eaefe81b09f6e2f61b0bcff16a6be.tar.gz rust-0aa0da9dda7eaefe81b09f6e2f61b0bcff16a6be.zip | |
Auto merge of #13572 - Veykril:cancellable, r=Veykril
internal: Use Cancellable in favor of Result for clarity
Diffstat (limited to 'crates/rust-analyzer/src/mem_docs.rs')
| -rw-r--r-- | crates/rust-analyzer/src/mem_docs.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/crates/rust-analyzer/src/mem_docs.rs b/crates/rust-analyzer/src/mem_docs.rs index f86a0f66ad8..45a1dab9772 100644 --- a/crates/rust-analyzer/src/mem_docs.rs +++ b/crates/rust-analyzer/src/mem_docs.rs @@ -7,7 +7,7 @@ use vfs::VfsPath; /// Holds the set of in-memory documents. /// -/// For these document, there true contents is maintained by the client. It +/// For these document, their true contents is maintained by the client. It /// might be different from what's on disk. #[derive(Default, Clone)] pub(crate) struct MemDocs { @@ -19,6 +19,7 @@ impl MemDocs { pub(crate) fn contains(&self, path: &VfsPath) -> bool { self.mem_docs.contains_key(path) } + pub(crate) fn insert(&mut self, path: VfsPath, data: DocumentData) -> Result<(), ()> { self.added_or_removed = true; match self.mem_docs.insert(path, data) { @@ -26,6 +27,7 @@ impl MemDocs { None => Ok(()), } } + pub(crate) fn remove(&mut self, path: &VfsPath) -> Result<(), ()> { self.added_or_removed = true; match self.mem_docs.remove(path) { @@ -33,17 +35,21 @@ impl MemDocs { None => Err(()), } } + pub(crate) fn get(&self, path: &VfsPath) -> Option<&DocumentData> { self.mem_docs.get(path) } + pub(crate) fn get_mut(&mut self, path: &VfsPath) -> Option<&mut DocumentData> { // NB: don't set `self.added_or_removed` here, as that purposefully only // tracks changes to the key set. self.mem_docs.get_mut(path) } + pub(crate) fn iter(&self) -> impl Iterator<Item = &VfsPath> { self.mem_docs.keys() } + pub(crate) fn take_changes(&mut self) -> bool { mem::replace(&mut self.added_or_removed, false) } |
