facebook / starlark-rust

A Rust implementation of the Starlark language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

interaction of rust defined structs (`StarlarkValue`)/ injected functions and LSP

benmkw opened this issue · comments

If one adds a function like in the examples quadratic to a module and a user works on that module, the user might want to get the IDE to suggest that method.

The same is true for rust-defined records (like Complex, in the case of the starlark example). A user might want to write a function which e.g. returns Complex.type.

In python+rust this can be done by using .pyi files as e.g. in https://pyo3.rs/v0.17.3/python_typing_hints.html

Ideally a similar file could be generated (maybe using proc macros underneath) when running the rust code, or it would just be manually created like its currently done in pyo3.

This library ships with an LSP server. The idea is that you create an LSP tailored to your specific flavor of Starlark, with your standard library preloaded, and then your LSP will be aware of it. See Buck2 as a project that does that.

Thats interesting.
It seems more difficult than the python/ pyo3 approach (every user has to install a different lsp for each project) but as long as the LSP remains small and hackable that still seems like a workable solution.

(for reference if others come acros this: https://github.com/facebook/buck2/blob/fa1551bb332aa279b1bb0a55d1dc2cfad3a7af43/app/buck2_server/src/lsp.rs this is the buck2 usage of the lsp)

It would be possible to take an approach where you could dump the configuration to disk (it's mostly DocItem values, which do have a Serialize trait) - but definitely more work to do compared to where we are. But once you also want execution (e.g. via DAP debug protocol, which we have demos of) you really need the full Rust code, so I'm not sure a halfway house is that useful.