racer
racer copied to clipboard
Ignore duplicate definitions due to cfg
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.
I'm not sure how racer would decide which cfg item to return, especially in the case of feature flags or other things.
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.
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 :)
Hmm, deduping for completions seems reasonable.
PR #778 deliberately doesn't handle this case, since the two occur at different points and therefore may have different doc strings.