logoalt Hacker News

Why building a Rust LSP is hard

73 pointsby agluszaklast Wednesday at 10:51 PM32 commentsview on HN

Comments

Panzerschrektoday at 5:45 AM

A lot of things described in this article applicable not only for Rust, but for almost any language. Like it's obvious that requests should be handled asynchronously and that conversions from/to UTF-16 are needed. But it's actually not so hard.

I have written a language server for my language too. The hardest thing was to find a way allowing providing useful autocompletion for a document in edited state, when it's not syntactically-correct. This is the trickiest part how to deal with such incorrectness without missing all the context necessary.

show 1 reply
mitxelatoday at 2:56 AM

Using a JSON TCP connection for what on Windows would be direct function calls (COM) or in Eclipse would be direct function calls between Java modules always felt a bit gross.

show 4 replies
klodolphtoday at 5:42 AM

The particulars of Rust make this a little more difficult, I think. There’s a certain tension between making your language more concise and adding useful redundancies, and Rust has generally gone to the “concise” side, with some redundancies that can make the tooling a little more painful. Like with imports.

  impl std::fmt::Display for Blah {
  }
If your language makes you qualify your imports (like above) then your LSP can, delightfully, still reliably do certain ops like renaming, even when chunks of your project aren’t parsing. But if you glob import std::fmt, and glob import something else, you are fucked. Display could come from anywhere (maybe from a module that has a parse error at the moment). I really appreciate languages where glob imports (or their equivalent) are either disallowed entirely or where typical code doesn’t use it.

Meanwhile, if you add a new file, there’s this little dance where you say:

  mod mycoolmod;
And then you create mycoolmod.rs. Or you do it the other way around. A little redundancy (the file exists and it is declared), that seems to just create a little friction in the LSP because mycoolmod doesn’t get a working LSP until it’s declared in the parent (you have to create both, and then you get a transient diagnostic that your module is unused for a while yet). A small issue, just another little bit of friction in the tooling of Rust that has nothing to do with the type system.
chrisjjtoday at 9:06 AM

> Why building a Rust LSP is hard

Not as hard as understanding what LSP means, apparently.

I was interested until I saw this project is simply an LSP server.

octoberfranklintoday at 3:11 AM

Enter hell: LSP assumes that it's the source of truth, but you still need to access the filesystem yourself, and do it in a synchronized way

LSP is an example of utterly horrid technical design.

Stop letting Microsoft design protocols and APIs. They are so. bad. at. it.

show 3 replies