Skip to content

Commit

Permalink
"Fix" intellisense for the f! macro in rust-analyzer.
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeMathWalker committed Jun 9, 2023
1 parent c72ea47 commit 9518d66
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions libs/pavex_builder/src/reflection/callable/mod.rs
Expand Up @@ -2,9 +2,24 @@ pub use identifiers::{RawCallable, RawCallableIdentifiers};

mod identifiers;

// The `pavex_ide_hint`-let binding is a hack to "nudge"
// rust-analyzer into parsing the macro input
// as an expression path, therefore enabling auto-completion and
// go-to-definition for the path that's passed as input.
//
// Rust-analyzer doesn't do this by default because it can't infer
// from the macro-generated code what the macro input "looks like".
// `stringify` accepts anything as input, so that's not enough.
//
// The perma-disabled `let` binding lets us workaround the issue
// that an _actual_ `let` binding would cause: it would fail to
// compile if the callable is generic, because the compiler would
// demand to know the type of each generic parameter without a default.
#[macro_export]
macro_rules! f {
($p:expr) => {{
#[cfg(pavex_ide_hint)]
let _ = $p;
$crate::reflection::RawCallable {
import_path: stringify!($p),
registered_at: ::std::env!("CARGO_PKG_NAME", "Failed to load the CARGO_PKG_NAME environment variable. Are you using a custom build system?")
Expand Down

0 comments on commit 9518d66

Please sign in to comment.