Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanups for clippy and text_store #29

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 20 additions & 8 deletions lsp/src/text_store.rs
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use explicit return !

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this isn't going to fly for me fyi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ba4e324

.get()
.expect("text store not initialized")
.lock()
.expect("text store mutex poisoned")
.texts
.get(&uri.to_string())
.cloned();
.cloned()
}