diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d5ad52..4e201d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: uses: ./.github/actions/setup-rust-env - name: Rust clippy - run: cargo clippy -- -D warnings + run: cargo clippy -- -Dclippy::all -D warnings rustfmt: name: Format diff --git a/lsp/src/handle.rs b/lsp/src/handle.rs index 7a62f24..b83f50b 100644 --- a/lsp/src/handle.rs +++ b/lsp/src/handle.rs @@ -74,7 +74,6 @@ fn handle_didChange(noti: Notification) -> Option { .expect("text store not initialized") .lock() .expect("text store mutex poisoned") - .texts .insert(uri, text); None @@ -96,11 +95,7 @@ fn handle_didOpen(noti: Notification) -> Option { .expect("text store not initialized") .lock() .expect("text store mutex poisoned") - .texts - .insert( - text_document_changes.uri, - text_document_changes.text.to_string(), - ); + .insert(text_document_changes.uri, text_document_changes.text); None } @@ -210,7 +205,6 @@ mod tests { .expect("text store not initialized") .lock() .expect("text store mutex poisoned") - .texts .insert(file.to_string(), content.to_string()); } diff --git a/lsp/src/htmx/mod.rs b/lsp/src/htmx/mod.rs index f676518..1c0db89 100644 --- a/lsp/src/htmx/mod.rs +++ b/lsp/src/htmx/mod.rs @@ -62,7 +62,7 @@ pub fn hx_completion(text_params: TextDocumentPositionParams) -> Option Option { - let result = crate::tree_sitter::get_position_from_lsp_completion(text_params.clone())?; + let result = crate::tree_sitter::get_position_from_lsp_completion(text_params)?; debug!("handle_hover result: {:?}", result); match result { diff --git a/lsp/src/text_store.rs b/lsp/src/text_store.rs index 9839b67..d7ed9e5 100644 --- a/lsp/src/text_store.rs +++ b/lsp/src/text_store.rs @@ -1,19 +1,32 @@ use std::{ collections::HashMap, + ops::{Deref, DerefMut}, sync::{Arc, Mutex, OnceLock}, }; use lsp_types::Url; -pub struct TextStore { - pub texts: HashMap, +type TxtStore = HashMap; + +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>> = 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 { @@ -22,7 +35,6 @@ pub fn get_text_document(uri: Url) -> Option { .expect("text store not initialized") .lock() .expect("text store mutex poisoned") - .texts .get(&uri.to_string()) .cloned(); }