1 //! In-memory document information.
3 use rustc_hash::FxHashMap;
6 /// Holds the set of in-memory documents.
8 /// For these document, there true contents is maintained by the client. It
9 /// might be different from what's on disk.
10 #[derive(Default, Clone)]
11 pub(crate) struct MemDocs {
12 mem_docs: FxHashMap<VfsPath, DocumentData>,
16 pub(crate) fn contains(&self, path: &VfsPath) -> bool {
17 self.mem_docs.contains_key(path)
19 pub(crate) fn insert(&mut self, path: VfsPath, data: DocumentData) -> Result<(), ()> {
20 match self.mem_docs.insert(path, data) {
25 pub(crate) fn remove(&mut self, path: &VfsPath) -> Result<(), ()> {
26 match self.mem_docs.remove(path) {
31 pub(crate) fn get(&self, path: &VfsPath) -> Option<&DocumentData> {
32 self.mem_docs.get(path)
34 pub(crate) fn get_mut(&mut self, path: &VfsPath) -> Option<&mut DocumentData> {
35 self.mem_docs.get_mut(path)
38 pub(crate) fn iter(&self) -> impl Iterator<Item = &VfsPath> {
43 /// Information about a document that the Language Client
45 /// Its lifetime is driven by the textDocument/didOpen and textDocument/didClose
46 /// client notifications.
47 #[derive(Debug, Clone)]
48 pub(crate) struct DocumentData {
49 pub(crate) version: i32,
53 pub(crate) fn new(version: i32) -> Self {
54 DocumentData { version }