-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary ---- - The most notable change here is the removal of unnecessary clones as suggested by clippy. Furthermore, this also makes the TextStore a wrapper type of a `HashMap<String, String>` and implements Deref and DerefMut for it. - Workflow update to ensure that clippy runs in _more_ exhaustive way (this is actually how I found about the unnecessary cloning).
- Loading branch information
Showing
4 changed files
with
23 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,40 @@ | ||
use std::{ | ||
collections::HashMap, | ||
ops::{Deref, DerefMut}, | ||
sync::{Arc, Mutex, OnceLock}, | ||
}; | ||
|
||
use lsp_types::Url; | ||
|
||
pub struct TextStore { | ||
pub texts: HashMap<String, String>, | ||
type TxtStore = HashMap<String, String>; | ||
|
||
pub struct TextStore(TxtStore); | ||
|
||
impl Deref for TextStore { | ||
type Target = TxtStore; | ||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl DerefMut for TextStore { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.0 | ||
} | ||
} | ||
|
||
pub static TEXT_STORE: OnceLock<Arc<Mutex<TextStore>>> = OnceLock::new(); | ||
|
||
pub fn init_text_store() { | ||
_ = TEXT_STORE.set(Arc::new(Mutex::new(TextStore { | ||
texts: HashMap::new(), | ||
}))); | ||
_ = TEXT_STORE.set(Arc::new(Mutex::new(TextStore(HashMap::new())))); | ||
} | ||
|
||
pub fn get_text_document(uri: Url) -> Option<String> { | ||
return TEXT_STORE | ||
TEXT_STORE | ||
.get() | ||
.expect("text store not initialized") | ||
.lock() | ||
.expect("text store mutex poisoned") | ||
.texts | ||
.get(&uri.to_string()) | ||
.cloned(); | ||
.cloned() | ||
} |