Skip to content

Commit

Permalink
Merge branch 'master' into static-completion-structure
Browse files Browse the repository at this point in the history
  • Loading branch information
lavafroth committed Dec 4, 2023
2 parents 305eb1e + 1f4071f commit c3ab192
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 16 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 @@ -208,7 +203,6 @@ mod tests {
.expect("text store not initialized")
.lock()
.expect("text store mutex poisoned")
.texts
.insert(file.to_string(), content.to_string());
}

Expand Down
17 changes: 17 additions & 0 deletions lsp/src/htmx/attributes/hx-disabled-elt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
The hx-disabled-elt attribute allows you to specify elements that will have the disabled attribute added to them for the duration of the request.

The value of this attribute is a CSS query selector of the element or elements to apply the class to, or the keyword closest, followed by a CSS selector, which will find the closest ancestor element or itself, that matches the given CSS selector (e.g. closest tr), or the keyword this.

Here is an example with a button that will disable itself during a request:

<button hx-post="/example" hx-disabled-elt="this">
Post It!
</button>

When a request is in flight, this will cause the button to be marked with the disabled attribute, which will prevent further clicks from occurring.

Notes

hx-disable-elt is inherited and can be placed on a parent element

[HTMX reference](https://htmx.org/attributes/hx-disabled-elt/)
4 changes: 4 additions & 0 deletions lsp/src/htmx/hx-disabled-elt/closest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
closest <CSS selector> which will find the closest ancestor element or itself, that matches the given CSS selector (e.g. closest tr will target the closest table row to the element).


[HTMX Reference](https://htmx.org/attributes/hx-disabled-elt/)
4 changes: 4 additions & 0 deletions lsp/src/htmx/hx-disabled-elt/this.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
this which indicates that the element that the hx-disabled-elt attribute is on is the target.


[HTMX Reference](https://htmx.org/attributes/hx-disabled-elt/)
4 changes: 2 additions & 2 deletions lsp/src/htmx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn hx_completion(text_params: TextDocumentPositionParams) -> Option<&'static
}

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 Expand Up @@ -194,4 +194,4 @@ pub static HX_ATTRIBUTE_VALUES: phf::Map<&'static str, &[HxCompletion]> = phf::p
("replace", "./hx-sync/replace.md"),
("queue", "./hx-sync/queue.md")
] as &[_]
};
};
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 c3ab192

Please sign in to comment.