Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there interest in moving ruff-lsp implementation into rust? #300

Closed
karthiknadig opened this issue Oct 27, 2023 · 10 comments
Closed

Is there interest in moving ruff-lsp implementation into rust? #300

karthiknadig opened this issue Oct 27, 2023 · 10 comments
Labels
question Further information is requested

Comments

@karthiknadig
Copy link

I work on the lsprotocol package which is used by pygls as the types implementation for LSP in python. I am working on a similar package for rust, and the intent is that general purpose rust LSP servers would use that as the base package.

This is a work in progress (and in initial phase): https://github.com/microsoft/lsprotocol/tree/main/packages/rust/lsprotocol

If you have any interest in adopting this to implement rust based servers please provide feedback on this.
PS: posted this as an issue since discussions are not enabled on this repo.

@charliermarsh
Copy link
Member

Very interesting! We do have interest in moving the LSP to Rust and building it directly into Rust. It would make development much easier, and also make the LSP more efficient -- plus, we could store long-lived state in Ruff itself.

I can't comment on that specific crate yet, but @MichaReiser did a proof-of-concept here with further notes: astral-sh/ruff#7262.

@karthiknadig
Copy link
Author

The intent of this lsprotocol package is to make the task on matching the LSP spec everytime there is an update to the spec out of inividual projects responsibility. I work on the spec, so I can generate this package and publish it as and when there are updates to spec. Basically take the drudgery od managing this out.

@karthiknadig
Copy link
Author

There are some marked advantages for doing this in ruff itself for scenarios involving notebooks. You won't have to serialize it to JSON and back to Notebook LSP model. In the end any tooling that works with ipynb really deals with the model, or an equivalent from the tools perspective. For massive notebooks, this JSON <-> Model transition can get super expensive. The pure rust implementation would give you the option of having the model available to you. Hopefully, making some of the interesting experiences like lint/format on type on massive notebooks a great experience.

An issue with formatting notebooks directly to disk is the loss of edit data. The editor will have to reload the file from disk, and useful information can get lost in the process. This can also prevent other extensions that user might have setup from contributing into this process during formatting.

@MichaReiser
Copy link
Member

The intent of this lsprotocol package is to make the task on matching the LSP spec everytime there is an update to the spec out of inividual projects responsibility. I work on the spec, so I can generate this package and publish it as and when there are updates to spec. Basically take the drudgery od managing this out.

Sounds interesting. How would it compare to the lspserver and lsptower crates?

@karthiknadig
Copy link
Author

karthiknadig commented Oct 28, 2023

The lsprotocol package is automatically generated every time there is a new update to the protocol spec. We regularly update the doc strings, add new requests, notifications, add new types, to the spec. A thing we have see is that types implementations often don't catch up to the supported features.

Example of changes to spec, this one I did replacing anonymous types with named types for better stability in types names: https://github.com/microsoft/vscode-languageserver-node/pull/1308/files

That is an example of a major change to how types are defined in the spec. We also refine the document string and type values more often than such large changes.

Once we have enough confidence in this package. we will approach server implementations to switch to this package. Similar to how we did with python. pygls had their own types implementation, which was replaced with the one we generate.

@karthiknadig
Copy link
Author

@MichaReiser The owner of the Tower-LSP (https://crates.io/crates/tower-lsp) asked for rust types, see here: microsoft/lsprotocol#151

@MichaReiser
Copy link
Member

MichaReiser commented Oct 28, 2023

So it's similar to lsp-types but with recent updates? It sounds interesting, depending on when it becomes available and how customizable it is (async vs custom scheduling)

@karthiknadig
Copy link
Author

So it's similar to lsp-types but with recent updates?

Yes. and this will be auto generated.

It sounds interesting, depending on when it becomes available and how customizable it is (async vs custom scheduling)

This is open for feedback, we want to shape it based on consumer feedback. So, my ask is if we could get some input from rust users who have experience with build LSP would be very helpful.

@karthiknadig
Copy link
Author

I just published an initial alpha build of lsprotocol https://crates.io/crates/lsprotocol have a look and leave feedback in the lsprotocol repo.

@MichaReiser MichaReiser added the question Further information is requested label Nov 27, 2023
@MichaReiser
Copy link
Member

Thanks for the update. We'll consider it when having a closer look on implementing our LSP in rust.

I'll close this issue for now since we answered the initial question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants