racer icon indicating copy to clipboard operation
racer copied to clipboard

Complete field names in struct and enum initialization

Open mqudsi opened this issue 8 years ago • 3 comments

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?

mqudsi avatar Jul 16 '17 00:07 mqudsi

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:

  1. 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 a field: value pair, so that it doesn't provide field suggestions while the user is attempting to specify the values that occupy the fields.
  2. 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.

TedDriggs avatar Jul 17 '17 16:07 TedDriggs

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?

mqudsi avatar Jul 17 '17 17:07 mqudsi

We have to make those routines by hand, and nobody has made that one yet.

TedDriggs avatar Jul 18 '17 16:07 TedDriggs