rust-lang / rust-analyzer

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

Not finding/recognizing function from dependency #18494

Open Lingepumpe opened 2 weeks ago

Lingepumpe commented 2 weeks ago

I am having issues with the diff function of polars within vscode: rust-analyzer does not seem to find this function, I cannot ctrl+click it to go to its definition and also I don't see any type annotations in vscode (e.g. for the type of weight_differences in the example):

use polars::prelude::*;

fn main() {
    let df: DataFrame = df!(
        "name" => ["Alice Archer", "Ben Brown", "Chloe Cooper", "Daniel Donovan"],
        "weight" => [57.9, 72.5, 53.6, 83.1],  // (kg)
        "height" => [1.56, 1.77, 1.65, 1.75],  // (m)
    )
    .unwrap();
    let weight_differences = diff(
        df["weight"].as_series().unwrap(),
        1,
        polars::series::ops::NullBehavior::Drop,
    )
    .unwrap();
    println!("{weight_differences}");
}

Could it be related to the fact that diff is only available when the diff feature is enabled? In my Cargo.toml I have polars = { version=">=0.44.2", features = ["diff"]}.

Note that other features from the polars package that are feature gated are not behaving the same, so this cannot be the only thing that causes ruff-analyzer to miss/ignore the function.

I have created a repo with the above code and the necessary Cargo.toml files to reproduce it: https://github.com/Lingepumpe/minimal_rust_demo

Versions: rust-analyser version: 0.4.2176-standalone (this is the nightly version, I was on stable before, with the same issue) rustc 1.82.0 (f6e511eec 2024-10-15) vscode Version: 1.95.1

Lingepumpe commented 1 week ago

After playing around with it some more, I realized that the polars-ops feature should also be enabled to find diff, as the prelude of polars has this code:

Image

And diff should come from the line 8 pub use polars_ops::prelude::*;, which is conditional on the feature polars-ops. Interestingly, everything also compiles fine without that feature added, in fact adding the feature to Cargo.toml had no effect at all, also not to rust-analyzer.

Maybe the actual issue for rust-analyzer is that polars has "outsourced" diff into a crate called polars_ops, and that one is not parsed with the diff feature still enabled by rust-analyzer?

Here in line 76 you can see where diff should finally come from. This is hidden behind the diff feature. So if rust-analyzer no longer has the diff feature active (given this is a different crate!), then this would cause the issue: Image