racer icon indicating copy to clipboard operation
racer copied to clipboard

Use save-analysis info to improve suggestions

Open nrc opened this issue 7 years ago • 3 comments

The best way I can see to help here is to use save-analysis to find the types of expressions which Racer could not otherwise infer. E.g. (| is the cursor)

let x = foo();
x.s|

I believe in this case Racer would need an explicit type annotation on x, however, save-analysis knows the type of x without an annotation, and probably will have that info by the time Racer gets to suggestions for .s....

@kngwyu Do you think this would be useful? Do you know of any other ways save-analysis could help Racer?

Some questions about this idea:

  • what format would Racer need the type information in? We have pointers to the definitions, which I assume is what Racer would need to look up fields/methods. We could also provide some text or structured representation of the type.
  • How should we integrate the data from rls-analysis (source of save-analysis info) vis RLS to Racer? We would probably need some trait that rls-analysis would implement and would allow Racer to query it. What would that look like?
  • How much work would this be on the Racer side? If I can do the save-analysis/RLS work, would you (or others) have time to work on Racer?

nrc avatar Aug 27 '18 22:08 nrc

Since Rust's type inference rule is complex, I'm sure it's useful.

what format would Racer need the type information in?

For a type without type parameter just pointer to definitions is enough. But considering a type with type parameter/trait object, I think we need some structured format.

How should we integrate the data from rls-analysis

Like other APIs, I think trait object works.

What would that look like?

e.g.

type Error = // any boxed error type(e.g. failure::Error)
trait TypeInfProvider {
    fn get_type(ident_name: &str,  span: &Span) -> Result<IdentType, Error>;
}

but now I'm not sure.

How much work would this be on the Racer side?

I'm really not sure..., but it'll take not so much time. But racer still needs some urgent bug fixes and refactoring, so I'm planning to work for analysis support from mid September.

would you (or others) have time to work on Racer?

At least I can work for it weekends.

kngwyu avatar Aug 28 '18 06:08 kngwyu

But considering a type with type parameter/trait object, I think we need some structured format.

What kind of format? Could you point me at what Racer uses at the moment please?

At least I can work for it weekends.

Awesome, thank you!

nrc avatar Aug 29 '18 06:08 nrc

What kind of format? Could you point me at what Racer uses at the moment please?

Here: https://github.com/racer-rust/racer/blob/49412d9e4adef0b1a51240ffda468c1e9e51bade/src/racer/ast_types.rs#L441

kngwyu avatar Aug 29 '18 07:08 kngwyu