rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14k stars 1.55k forks source link

Support for Macros (Leptos) #14045

Open Dqgs opened 1 year ago

Dqgs commented 1 year ago

Leptos currently uses cfg_if! macros and when having something like

 cfg_if! {
     if #[cfg(feature = "ssr")] {
       // First Main function
        pub fn main() {
            println!("cargo-leptos is not enabled. Please enable it in your Cargo.toml");
        }
    }
    else {
       // Second Main FUnction 
        pub fn main() {
            println!("cargo-leptos is not enabled. Please enable it in your Cargo.toml");
        }
    }
}

it does not support the first one even if i type something random that has no function or anything it will not produce any errors

rust-analyzer version: rust-analyzer version: 0.3.1377-standalone (daa0138e4 2023-01-21)

rustc version: rustc 1.68.0-nightly (0fb8b72ce 2023-01-06)

bjorn3 commented 1 year ago

You can set the rust-analyzer.cargo.features config to ["ssr"] to enable the first arm, but that will also disable the second arm at the same time. Rust-analyzer only supports a single #[cfg] configuration at the same time currently.

Dqgs commented 1 year ago

Any plans on updating for more?

bjorn3 commented 1 year ago

I believe there is an open issue for it, but I can't find it.

ntrp commented 1 year ago

For anybody stumbling on this and using nvim, here is an example on how to make the ssr blocks work https://gist.github.com/GeordieP/07ad21a714f98deda71a9ea4330caef1