vimdoc_language_server/
store.rs1use std::collections::HashMap;
2
3use lsp_types::Uri;
4
5use crate::parser::Document;
6
7#[derive(Default)]
8pub struct Store {
9 docs: HashMap<Uri, (String, Document)>,
10}
11
12impl Store {
13 pub fn open(&mut self, uri: Uri, text: String) {
14 let doc = Document::parse(&text);
15 self.docs.insert(uri, (text, doc));
16 }
17
18 pub fn change(&mut self, uri: &Uri, text: String) {
19 let doc = Document::parse(&text);
20 self.docs.insert(uri.clone(), (text, doc));
21 }
22
23 pub fn close(&mut self, uri: &Uri) {
24 self.docs.remove(uri);
25 }
26
27 pub fn get(&self, uri: &Uri) -> Option<(&str, &Document)> {
28 self.docs
29 .get(uri)
30 .map(|(t, d): &(String, Document)| (t.as_str(), d))
31 }
32}