Electron100 / butane

An ORM for Rust with a focus on simplicity and on writing Rust, not SQL
Apache License 2.0
101 stars 13 forks source link

rust-analyzer unable to parse query! macro, reports "Unsupported filter expression" #272

Closed michael-dm closed 2 months ago

michael-dm commented 2 months ago

I'm encountering an issue where rust-analyzer is unable to correctly parse the query! macro from Butane. Here's a minimal example of the problematic code:

query!(Profile, name == "Hello")

This results in the following error from rust-analyzer:

rust-analyzer: Unsupported filter expression '(name == "Hello")'

Additional debug info:

Expr::Paren { attrs: [], paren_token: Paren, expr: Expr::Binary { attrs: [], left: Expr::Path { attrs: [], qself: None, path: Path { leading_colon: None, segments: [PathSegment { ident: Ident { ident: "name", span: SpanData { range: 297..301, anchor: SpanAnchor(FileId(16777220), 5), ctx: SyntaxContextId(0) } }, arguments: PathArguments::None }] } }, op: BinOp::Eq(EqEq), right: Expr::Lit { attrs: [], lit: Lit::Str { token: "Hello" } } } }

This code compiles and runs correctly, but rust-analyzer is unable to properly analyze it. Also, this version work with no issue :

Profile::query().filter(filter!(Profile, name == "Hello"));

Environment:

Any assistance in resolving this issue would be greatly appreciated.

ugochukwu-850 commented 2 months ago

It's common for rust analyzer to have some issues with macros .

Have you considered restarting the server .

Or reopening your editor. That's should help reindex stuff .

Because if it can actually run but Rust analyzer doesn't parse it successfully , it's probably just an indexing issue . Restarting rust analyzer should solve it .

Electron100 commented 2 months ago

FWIW, I'm seeing rust-analyzer handle query! invocations correctly on my end. That doesn't invalidate your problem of course, but unless anybody can spot something wrong with the way we're defining the macro in Butane, this sounds like a rust-analyzer bug rather than a Butane.