Skip to content

Autocompletion doesn't work for implemented traits for rusymbols::Expression #15708

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

Closed
Andrew15-5 opened this issue Oct 4, 2023 · 2 comments
Closed
Labels
C-bug Category: bug

Comments

@Andrew15-5
Copy link

Andrew15-5 commented Oct 4, 2023

rust-analyzer version: 0.3.1681-standalone

rustc version: 1.72.1 (d5c2e9c34 2023-09-13)

relevant settings: "workspace.ignoredFolders": ["$HOME", "$HOME/.cargo/**", "$HOME/.rustup/**"]

I'm not sure how this is possible, but only methods of implemented (std) traits are not shown in autocompletion list:

screenshot

image

But methods of struct implementation are present:

screenshot

image

And after using non-present method, its methods are also won't exist (return type is Expression):

screenshot

image

example
fn main() {
    use rusymbols::Expression;
    use std::collections::HashMap;

    let x = Expression::new_var("x");
    let two = Expression::new_val(2.0);
    let polynomial = x.clone().pow(two.clone()) - x + two;

    let mut args: HashMap<&str, f64> = HashMap::new();
    args.insert("x", 1.0);

    assert_eq!(polynomial.to_string(), "x**2 - x + 2");
    assert_eq!(polynomial.eval_args(&args).unwrap(), 2.0);
}

OnHover event also doesn't work on clone() or on any methods after clone(). When hovering on polynomial server can't detect the type of Expression: let polynomial: {unknown}

I don't think that it is somehow linked to my rust-analyzer setup or coc.nvim plugin (but I guess everything is possible). I'm also new to Rust (idk if this is relevant). I'm also not sure if this is a bug in this specific crate or is this a known issue.

@Andrew15-5 Andrew15-5 added the C-bug Category: bug label Oct 4, 2023
@lnicola
Copy link
Member

lnicola commented Oct 4, 2023

Confirmed, we don't resolve clone():

image

Which is quite surprising, as the following works fine:

#[derive(Debug, Clone)]
pub enum Actions {
    Var(String),
}

#[derive(Clone, Debug, Default)]
pub struct Expression {
    args: Vec<Expression>,
    kind: Actions,
}

impl Expression {
    pub fn new(left: Expression, right: Expression, kind: Actions) -> Expression {
        Expression{ args: vec![left, right], kind}
    }

    pub fn new_var(literal: &str) -> Expression {
        Expression { args: vec![], kind: Actions::Var(String::from(literal)) }
    }
}

fn main() {
    let x = Expression::new_var("x");
    let polynomial = x.clone();
}

@lnicola
Copy link
Member

lnicola commented Oct 4, 2023

Duplicate of #13600.

@lnicola lnicola closed this as completed Oct 4, 2023
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

2 participants