‹ BackHN Continuity

Thread

Why building a Rust LSP is hard

144 points · 77 comments · agluszak

  1. octoberfranklin · · focus · HN ↗
    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.

    1. duttish · · focus · HN ↗
      I've never looked into LSP, how would you design it?
      1. mitxela · · focus · HN ↗
        Start with synchronous function calls instead of JSON. Microsoft knows how to do that - they invented COM and OLE. Function calls enable whatever data sharing is necessary to maintain a coherent view. Imagine trying to do OLE with JSON - just wouldn't work. (Does OLE still exist?)
        1. cyberax · · focus · HN ↗
          Moreover, it's not just stupid, it also does not actually solve _anything_.

          A synchronous function can also have obsolete indexing information if it races with the code updates.

          1. mitxela · · focus · HN ↗
            But it doesn't have to, because you call AboutToUpdateCode and the LSP doesn't return until it's safe, and then you update code and call DoneUpdatingCode.
            1. cyberax · · focus · HN ↗
              Yes, it does because the physical code update is asynchronous. Or you'd have to do a roundtrip for every little edit, resulting in unusably slow experience.
              1. mitxela · · focus · HN ↗
                I don't know what you're talking about. What is "physical code"? A function call roundtrip costs nothing, that's the reason we are saying it should be function calls.
                1. cyberax · · focus · HN ↗
                  TCP roundtrip overhead over localhost costs approximately nothing.

                  But running the LSP itself is slow. It's not instant, and you can't run it in a blocking way for each keypress.

                  1. mitxela · · focus · HN ↗
                    A function call costs nanoseconds. You can sprinkle them literally everywhere. A JSON-formatted TCP round trip to localhost costs, I'd guess conservatively, at least ten microseconds, 1000x slower.
                    1. cyberax · · focus · HN ↗
                      OK. Here's my simple implementation of an LSP:

                      > func doLspStuff() { sleep(60000); }

                      Now sprinkle them after each keypress. Do you see the issue now?

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.