facebook / starlark-rust

A Rust implementation of the Starlark language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LSP: code completion

laurentlb opened this issue · comments

Hi,

Thanks to @DanielEliad's PR (#51), I've noticed the LSP code in the repo. It's very nice to see an update on this!

I think it's important to keep the LSP generic enough to accomodate multiple dialects of Starlark. I imagine you'll need it at Facebook too. Our approach at Google was to define a proto file that contains all the definitions for a dialect (all the builtins, all the types, all the methods on the types).

It would be very useful to align on this and use a compatible solution.

Hey Laurent,
So, this repo mostly cares about the rust side of things. We're going to be exposing a function on the context that dumps the Doc objects back for builtins (right now we just do global lookups one at a time when we jump to the definition of the builtins), for things like autocomplete, onhover, types, etc. This will be done just with the builtin documentation() method like we do elsewhere (which in turn pulls from either rust docstrings, or starlark ones for non-builtin types, things in the prelude, etc).

As such, nope, we don't actually need to do this at FB for our projects that are written in rust. We just expose a the globals object via the LspContext (again, that function doesn't exist quite yet, but will shortly), and things automagically work.

For what you folks are doing, with bazel being a separate Java program, I definitely think that could be a reasonable approach, and I'd say you'd want a tool that turned your protos there into an LspContext implementation. But that's not particularly something we'd be doing in this repo, since the major use case is using our rust implementation as our interpreter.

I presume this is what LspContext#get_environment does?

Yep, we're not going to do a proto-based completion, but given the LspContext hooks, someone could easily do that themselves, so closing this.