racer icon indicating copy to clipboard operation
racer copied to clipboard

Ignore duplicate definitions due to cfg

Open Wilfred opened this issue 8 years ago • 5 comments

Given the code:

#[cfg(target_pointer_width = "32")]
const SIZE_OF_PTR: usize = 4;
#[cfg(target_pointer_width = "64")]
const SIZE_OF_PTR: usize = 8;

fn main() {
    SIZE
}

Racer gives:

PREFIX 149,153,SIZE
MATCH SIZE_OF_PTR,2,6,/home/wilfred/projects/remacs/rust_src/src/foo.rs,Const,const SIZE_OF_PTR: usize = 4;
MATCH SIZE_OF_PTR,4,6,/home/wilfred/projects/remacs/rust_src/src/foo.rs,Const,const SIZE_OF_PTR: usize = 8;
END

Ideally racer would not offer both of these.

Wilfred avatar Feb 28 '17 00:02 Wilfred

I'm not sure how racer would decide which cfg item to return, especially in the case of feature flags or other things.

TedDriggs avatar Jun 12 '17 18:06 TedDriggs

I'm not convinced find-definition shouldn't return "duplicate" definitions, at least by default. They are both real definitions for that identifier.

Perhaps there should be an option for looking into cfg? Big question then is where cfg definitions would come from. Compiler knows some of them; others are derived based on flags, Cargo.toml, etc. One option is to not have Racer attempt to figure out such definitions but instead provide such a table up-front.

jwilm avatar Jun 12 '17 18:06 jwilm

Reasonable points. Since we're trying to complete rather than find a definition in this example, it's not useful having duplicates offered. We might just filter duplicates before showing the list to the user.

I agree that looking at cfg would be desirable in an ideal world :)

Wilfred avatar Jun 12 '17 21:06 Wilfred

Hmm, deduping for completions seems reasonable.

jwilm avatar Jun 12 '17 21:06 jwilm

PR #778 deliberately doesn't handle this case, since the two occur at different points and therefore may have different doc strings.

TedDriggs avatar Jul 26 '17 20:07 TedDriggs