Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not finding/recognizing function from dependency #18494

Open
Lingepumpe opened this issue Nov 8, 2024 · 1 comment
Open

Not finding/recognizing function from dependency #18494

Lingepumpe opened this issue Nov 8, 2024 · 1 comment
Labels
C-bug Category: bug

Comments

@Lingepumpe
Copy link

Lingepumpe commented Nov 8, 2024

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 Lingepumpe added the C-bug Category: bug label Nov 8, 2024
@Lingepumpe Lingepumpe changed the title Not finding/recognizing feature gated function Not finding/recognizing feature gated function of dependency Nov 8, 2024
@Lingepumpe Lingepumpe changed the title Not finding/recognizing feature gated function of dependency Not finding/recognizing function from dependency Nov 10, 2024
@Lingepumpe
Copy link
Author

Lingepumpe commented Nov 10, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

1 participant