Skip to content

Commit

Permalink
Merge pull request #29 from vihu/rg/clippy-and-txtstore-cleanup
Browse files Browse the repository at this point in the history
Cleanups for clippy and text_store
  • Loading branch information
ThePrimeagen authored Dec 3, 2023
2 parents 040b129 + ba4e324 commit 1f4071f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions lsp/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ fn handle_didChange(noti: Notification) -> Option<HtmxResult> {
.expect("text store not initialized")
.lock()
.expect("text store mutex poisoned")
.texts
.insert(uri, text);

None
Expand All @@ -96,11 +95,7 @@ fn handle_didOpen(noti: Notification) -> Option<HtmxResult> {
.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
}
Expand Down Expand Up @@ -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());
}

Expand Down
2 changes: 1 addition & 1 deletion lsp/src/htmx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn hx_completion(text_params: TextDocumentPositionParams) -> Option<Vec<HxCo
}

pub fn hx_hover(text_params: TextDocumentPositionParams) -> Option<HxCompletion> {
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 {
Expand Down
24 changes: 18 additions & 6 deletions lsp/src/text_store.rs
Original file line number Diff line number Diff line change
@@ -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<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> {
Expand All @@ -22,7 +35,6 @@ pub fn get_text_document(uri: Url) -> Option<String> {
.expect("text store not initialized")
.lock()
.expect("text store mutex poisoned")
.texts
.get(&uri.to_string())
.cloned();
}

0 comments on commit 1f4071f

Please sign in to comment.