racer
racer copied to clipboard
Complete field names in struct and enum initialization
I imagine this has already been bugged somewhere, but I wasn't able to find the relevant issue so I am reporting it on the off-chance it's not already known.
testcase.rs:
fn main() {
let s: Sample = Sample {
}
}
struct Sample {
field: u32
}
When executing racer complete 3 9 testcase.rs the output is only END
Shouldn't this be an easy case for racer?
I'm not sure how easy it would be to detect, as you'd have to rule out a variety of other cases to make sure you were in a struct initialization:
Start of a function:
fn foo() -> Bar {
// cursor here
}
Loop declaration:
for x in y {
// cursor goes here
}
However, this would definitely be a valuable addition to racer. If you're interested in submitting a PR, we'd be happy to provide code review and mentorship. I'd suggest approaching it in two steps:
- Make
racer::core::complete_from_file_recognize that a field completion is expected, including tests. This should recognize when the user is on the left-hand side of the colon in afield: valuepair, so that it doesn't provide field suggestions while the user is attempting to specify the values that occupy the fields. - Determine the type that is being completed, and then try to autocomplete based on that type and the characters the user has already typed in. This is something racer is good at, so it should be straightforward once the previous step is done.
Hi @TedDriggs
I'm absolutely new to racer - are there no routines in the racer code right now that determine what context the specified position is in?
We have to make those routines by hand, and nobody has made that one yet.