Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Desdaemon committed Oct 27, 2023
1 parent 71dc1f0 commit 0daf03e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
24 changes: 12 additions & 12 deletions crates/ts-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,25 +8,25 @@ 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)))))"#
/// };
/// ```
///
/// Generates:
/// ```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]
Expand Down Expand Up @@ -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..];
Expand Down
2 changes: 1 addition & 1 deletion src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions src/catch_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pin_project_lite::pin_project! {
}
}

fn handle_panic_err(err: Box<dyn Any>) {
fn handle_panic_err(err: &dyn Any) {
if let Some(msg) = err.downcast_ref::<String>() {
error!("{msg}");
} else if let Some(msg) = err.downcast_ref::<&str>() {
Expand All @@ -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 _)),
Expand All @@ -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 _)),
Expand Down
4 changes: 2 additions & 2 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ async fn add_root_py(path: PathBuf) -> miette::Result<Output> {
.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<Vec<Model>> {
pub fn index_models(contents: &[u8]) -> miette::Result<Vec<Model>> {
let mut parser = tree_sitter::Parser::new();
parser.set_language(tree_sitter_python::language()).into_diagnostic()?;

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![warn(clippy::unused_async)]

pub mod config;
pub mod index;
pub mod str;
Expand Down
2 changes: 1 addition & 1 deletion src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0daf03e

Please sign in to comment.