]>
git.proxmox.com Git - rustc.git/blob - src/tools/rust-analyzer/crates/rust-analyzer/src/mem_docs.rs
1 //! In-memory document information.
5 use rustc_hash
::FxHashMap
;
8 /// Holds the set of in-memory documents.
10 /// For these document, their true contents is maintained by the client. It
11 /// might be different from what's on disk.
12 #[derive(Default, Clone)]
13 pub(crate) struct MemDocs
{
14 mem_docs
: FxHashMap
<VfsPath
, DocumentData
>,
15 added_or_removed
: bool
,
19 pub(crate) fn contains(&self, path
: &VfsPath
) -> bool
{
20 self.mem_docs
.contains_key(path
)
23 pub(crate) fn insert(&mut self, path
: VfsPath
, data
: DocumentData
) -> Result
<(), ()> {
24 self.added_or_removed
= true;
25 match self.mem_docs
.insert(path
, data
) {
31 pub(crate) fn remove(&mut self, path
: &VfsPath
) -> Result
<(), ()> {
32 self.added_or_removed
= true;
33 match self.mem_docs
.remove(path
) {
39 pub(crate) fn get(&self, path
: &VfsPath
) -> Option
<&DocumentData
> {
40 self.mem_docs
.get(path
)
43 pub(crate) fn get_mut(&mut self, path
: &VfsPath
) -> Option
<&mut DocumentData
> {
44 // NB: don't set `self.added_or_removed` here, as that purposefully only
45 // tracks changes to the key set.
46 self.mem_docs
.get_mut(path
)
49 pub(crate) fn iter(&self) -> impl Iterator
<Item
= &VfsPath
> {
53 pub(crate) fn take_changes(&mut self) -> bool
{
54 mem
::replace(&mut self.added_or_removed
, false)
58 /// Information about a document that the Language Client
60 /// Its lifetime is driven by the textDocument/didOpen and textDocument/didClose
61 /// client notifications.
62 #[derive(Debug, Clone)]
63 pub(crate) struct DocumentData
{
64 pub(crate) version
: i32,
68 pub(crate) fn new(version
: i32) -> Self {
69 DocumentData { version }