1 //! In-memory document information.
5 use rustc_hash::FxHashMap;
8 /// Holds the set of in-memory documents.
10 /// For these document, there 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)
22 pub(crate) fn insert(&mut self, path: VfsPath, data: DocumentData) -> Result<(), ()> {
23 self.added_or_removed = true;
24 match self.mem_docs.insert(path, data) {
29 pub(crate) fn remove(&mut self, path: &VfsPath) -> Result<(), ()> {
30 self.added_or_removed = true;
31 match self.mem_docs.remove(path) {
36 pub(crate) fn get(&self, path: &VfsPath) -> Option<&DocumentData> {
37 self.mem_docs.get(path)
39 pub(crate) fn get_mut(&mut self, path: &VfsPath) -> Option<&mut DocumentData> {
40 // NB: don't set `self.added_or_removed` here, as that purposefully only
41 // tracks changes to the key set.
42 self.mem_docs.get_mut(path)
44 pub(crate) fn iter(&self) -> impl Iterator<Item = &VfsPath> {
47 pub(crate) fn take_changes(&mut self) -> bool {
48 mem::replace(&mut self.added_or_removed, false)
52 /// Information about a document that the Language Client
54 /// Its lifetime is driven by the textDocument/didOpen and textDocument/didClose
55 /// client notifications.
56 #[derive(Debug, Clone)]
57 pub(crate) struct DocumentData {
58 pub(crate) version: i32,
62 pub(crate) fn new(version: i32) -> Self {
63 DocumentData { version }