diff --git a/crates/ts-macros/src/lib.rs b/crates/ts-macros/src/lib.rs index 36c93bc..d63c583 100644 --- a/crates/ts-macros/src/lib.rs +++ b/crates/ts-macros/src/lib.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{hash_map::Entry, HashMap}; use proc_macro2::{Ident, TokenStream}; use proc_macro2_diagnostics::SpanDiagnosticExt; @@ -8,15 +8,15 @@ use syn::{parse::Parse, punctuated::Punctuated, *}; /// Usage: /// ```rust,noplayground /// ts_macros::query! { -/// MyQuery(FOO, BAR); -/// r#" +/// MyQuery(FOO, BAR); +/// r#" /// (function_definition /// (parameters . (string) @FOO) /// (block -/// (expression_statement -/// (call -/// (_) @callee -/// (parameters . (string) @BAR)))))"# +/// (expression_statement +/// (call +/// (_) @callee +/// (parameters . (string) @BAR)))))"# /// }; /// ``` /// @@ -24,9 +24,9 @@ use syn::{parse::Parse, punctuated::Punctuated, *}; /// ```rust,noplayground /// pub enum MyQuery {} /// impl MyQuery { -/// pub const FOO: u32 = 0; -/// pub const BAR: u32 = 2; -/// pub fn query() -> &'static Query; +/// pub const FOO: u32 = 0; +/// pub const BAR: u32 = 2; +/// pub fn query() -> &'static Query; /// } /// ``` #[proc_macro] @@ -74,8 +74,8 @@ impl QueryDefinition { .find(|c: char| !c.is_ascii_alphanumeric() && c != '_') .unwrap_or(query.len() - start); let capture = &query[start..start + end]; - if !captures.contains_key(&capture) { - captures.insert(capture, index); + if let Entry::Vacant(entry) = captures.entry(capture) { + entry.insert(index); index += 1; } query = &query[start + end..]; diff --git a/src/backend.rs b/src/backend.rs index 2a7820b..ff1ae53 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -289,7 +289,7 @@ impl Backend { let interner = interner(); let by_prefix = self.index.templates.by_prefix.read().await; let matches = by_prefix.iter_prefix(needle.as_bytes()).flat_map(|(_, set)| { - set.keys().into_iter().flat_map(|key| { + set.keys().flat_map(|key| { let label = interner.resolve(&*key).to_string(); Some(CompletionItem { text_edit: Some(CompletionTextEdit::InsertAndReplace(InsertReplaceEdit { diff --git a/src/catch_panic.rs b/src/catch_panic.rs index f68f89a..0ba4a71 100644 --- a/src/catch_panic.rs +++ b/src/catch_panic.rs @@ -64,7 +64,7 @@ pin_project_lite::pin_project! { } } -fn handle_panic_err(err: Box) { +fn handle_panic_err(err: &dyn Any) { if let Some(msg) = err.downcast_ref::() { error!("{msg}"); } else if let Some(msg) = err.downcast_ref::<&str>() { @@ -90,8 +90,7 @@ where let self_ = self.project(); match self_.kind.project() { KindProj::Panicked { panic_err } => { - let err = core::mem::replace(panic_err, Box::new(&())); - handle_panic_err(err); + handle_panic_err(panic_err); let resp = Response::from_error( self_.id.clone().unwrap_or_default(), Error::new(ErrorCode::ServerError(ServerErrors::PreawaitPanic as _)), @@ -101,7 +100,7 @@ where KindProj::Future { future } => match ready!(future.poll(cx)) { Ok(inner) => Poll::Ready(inner), Err(panic_err) => { - handle_panic_err(panic_err); + handle_panic_err(panic_err.as_ref()); let resp = Response::from_error( self_.id.clone().unwrap_or_default(), Error::new(ErrorCode::ServerError(ServerErrors::PostawaitPanic as _)), diff --git a/src/index.rs b/src/index.rs index 1e1c6f8..8be135b 100644 --- a/src/index.rs +++ b/src/index.rs @@ -292,11 +292,11 @@ async fn add_root_py(path: PathBuf) -> miette::Result { .with_context(|| format_loc!("Could not read {}", path.display()))?; let path = interner().get_or_intern(path.to_string_lossy().as_ref()); - let models = index_models(&contents).await?; + let models = index_models(&contents)?; Ok(Output::Models { path, models }) } -pub async fn index_models(contents: &[u8]) -> miette::Result> { +pub fn index_models(contents: &[u8]) -> miette::Result> { let mut parser = tree_sitter::Parser::new(); parser.set_language(tree_sitter_python::language()).into_diagnostic()?; diff --git a/src/lib.rs b/src/lib.rs index da9a618..5716ad0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +#![warn(clippy::unused_async)] + pub mod config; pub mod index; pub mod str; diff --git a/src/python.rs b/src/python.rs index a132256..2f0f9ea 100644 --- a/src/python.rs +++ b/src/python.rs @@ -148,7 +148,7 @@ impl Backend { // TODO: Limit range of possible updates based on delta Text::Delta(_) => Cow::from(rope.slice(..)), }; - let models = index_models(text.as_bytes()).await?; + let models = index_models(text.as_bytes())?; let path = interner().get_or_intern(uri.path()); self.index.models.append(path, interner(), true, &models).await; for model in models {