Hacker News

Top stories

Live mirror
30 storiesupdated just nowView source snapshot
  1. Human brain is two separate organs, Stanford Medicine-led research finds(stanford.edu ↗)
    28comments
  2. San Francisco Onion Futures Company(onionfutures.com ↗)
    53comments
  3. If math is more than proof, we need to better celebrate the rest of it(terrytao.wordpress.com ↗)
    9comments
  4. Android 17 is the first since 3.x to add new APIs without releasing to the AOSP(grapheneos.social ↗)
    369comments
  5. GPT-6 Astra Solves a WWI German Radio Cipher(prinzai.com ↗)
    discuss
  6. Typesafe-computer-use drives a Mac toward a goal for 1/50th of a cent per step(github.com/awlevin ↗)
    22comments
  7. SDCC – Small Device C Compiler(sourceforge.net ↗)
    15comments
  8. Science Is Open Software(jepedersen.dk ↗)
    26comments
  9. Cloudflare Quick Tunnels(cloudflare.com ↗)
    275comments
  10. Saving another 100TB of RAM(cloudflare.com ↗)
    64comments
  11. Why building a Rust LSP is hard(rust-glancer.github.io ↗)
    24comments
  12. NASA-IBM Lunar Foundation open-Source Geospatial AI Model(usra.edu ↗)
    1comments
  13. How to Write with an LLM(sockpuppet.org ↗)
    316comments
  14. How OpenAI Used Its Own LLMs to Design Its Jalapeño Chip(ieee.org ↗)
    77comments
  15. You can run Git on object storage if you re-make packfiles(tigrisdata.com ↗)
    6comments
  16. Ctenophores: Wonders of Biology(quantamagazine.org ↗)
    4comments
  17. Goroutine Leak Profiles(go.dev ↗)
    2comments
  18. The first new cat species discovered in 100 years(nationalgeographic.com ↗)
    90comments
  19. Veronese's Dogs(publicdomainreview.org ↗)
    discuss
  20. OpenJev(openjev.com ↗)
    257comments
  21. Show HN: Cactus Needle 3: 8-29MB automation models can match DeepSeek V4 Flash(cactuscompute.com ↗)
    87comments
  22. Photon-Emission-Guided Laser Fault Injection Enables RP2350 Secure Debug(ledger.com ↗)
    66comments
  23. Cache-to-Cache: Direct Semantic Communication Between LLMs (2025)(arxiv.org ↗)
    12comments
  24. Stepfun Step 5 Preview (LLM): On AA Pareto frontier(artificialanalysis.ai ↗)
    1comments
  25. The Farnese letter(simonklee.dk ↗)
    6comments
  26. Minimal Phone 2(minimalcompany.com ↗)
    212comments
  27. Xcode 27.1 Beta Release Notes(developer.apple.com ↗)
    96comments
  28. Cyclomatic Complexity in C#(ndepend.com ↗)
    18comments
  29. Inside ZCode: Silently uploading your Git history to the cloud(ferstar.org ↗)
    97comments
  30. Warez: The Infrastructure and Aesthetics of Piracy (2021)(archive.org ↗)
    49comments

Why building a Rust LSP is hard

50 pointsby 2d agorust-glancer.github.io
24 comments
4h agoHN ↗

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.

3h agoHN ↗

I agree, the only reason LSP exists as it does is for a world running on electron based applications. Plug-ins and application extensions are not new technology and they are nearly universally more efficient in the forms designed and used prior to 2005-ish. I understand why VSCode exists and why it is used so often by developers, but it is certainly a downgrade from more language specific options that could exist.

There are some arguments that do carry water in favor of using a client/server protocol transmitting JSON, in particular, the ability for a nearly complete decoupling of analysis of code and the displaying and editing of that code. Also, LSP was (to my knowledge) the first language/platform/usecase agnostic protocol intended for use in code editors.

I get why this is where a big chunk of developers have ended up, but I do bemoan the lost potential for a language to grab mindshare and popularity on the usability and performance of its tooling and developer experience via-a-vis a custom designed and hyper specific code editor. I mean, Rust and Elm received endless praise for their error messages as a massive boon to developer experience, so it is a facet of language design and implementation that can act as great advertisement. I just hate that the prevalence of LSP at this point precludes custom editors as a first choice in the current zeitgeist.

2h agoHN ↗

It only makes sense in the context of host security and stability, as proven by plugin issues in those IDEs.

However, to come back to your point, there are much better high performance OS IPC mechanisms for inter process communication than sending JSON down through a TCP wire.

As others point out, Electron.

1h agoHN ↗

In order to have direct function calls, you need to load the plugin's code in your own memory. Which means you expose your own memory to the plugin. Any malicious/buggy plugin could wreak havoc on your program - even managed code doesn't solve that problem in general.

IPC is the natural solution to that - run a process in its own address space and communicate with it via I/O. TCP is not most optimal, but it is uniquous. Same thing with JSON.

In LSP, most of the processing happens in the LSP server anyway - communication overhead between client and server is negligible in comparison to it.

1h agoHN ↗

TCP isn't really necessary. Usually a language server just uses stdin/stdout, which are just pipes.

And overall overhead for running a language server in a separate process isn't that big. LSP is designed in such a way that only minimal amount of information is needed to be passed, like edits or short responses. Packing/unpacking JSONs isn't a bottleneck, the heaviest job like program analysis is done in the language server itself without interprocess communication overhead involved.

4h agoHN ↗

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.

4h agoHN ↗

I've never looked into LSP, how would you design it?

4h agoHN ↗

Well for one I wouldn't design it so both the LSP and the editor need a synchronized view of the underlying file.

4h agoHN ↗

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?)

3h agoHN ↗

Stupid idea.

So the LSP crashes and/or goes into a runaway memory consumption loop. And your main application dies with it.

Or what if you want, you know, to be able to use the same LSP from TWO different applications at the same time?

Never mind issues with other managed runtimes not expecting to deal with something else in their address space.

3h agoHN ↗

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.

2h agoHN ↗

I feel like MS actually learned their lesson with synchronously integrating the language intelligence into the IDE. Old versions of VS would hang or crash based on bugs in the language tooling trying to provide intellisense. You'd restart and it'd work fine till you hit some other weird edge case. Generally this settled to a level of rare-bugginess where you were happy enough with the advantages not to go back to Emacs/VIM, but still annoyed at the occasional restart needed.

In no way does this mean LSP is a perfect solution, but anything synchronous would be a step backwards.

2h agoHN ↗

That doesn't really fix anything. The filesystem is fundamentally a racy shared data structure. If you made the entrypoint API synchronous, any half-way decent editor would shove the LSP queries to the synchronous API into a different thread, because "Do Not Block the UI Thread" is a fundamental principle of good UI programming.

Once you get past that, JSON-over-TCP is just another kind of asynchronous RPC mechanism, one that has the advantage that you can build it in just about any language with out-of-the-box tools. Trying to make a plugin system or a COM or CORBA or OLE based system really cuts out the ability to build language servers in most languages, because you have to be able to build the code in just the right way.

2h agoHN ↗

Actually, COM is inspired by DCE/RPC and the initial versions had some similarities.

Parallel to that, IBM had SOM on OS/2, which was even better allowing for metaclasses and proper class inheritance, it was the key mechanism between Smalltalk and C++ on OS/2, where Smalltalk enjoyed a role similar to .NET on Windows nowadays.

OLE naturally still exists when using Office natively on Windows, other vendors seem to have forgotten about it.

COM's role on Windows has grown since Vista, and the Windows team redid many of the Longhorn ideas originally implemented in .NET into COM/C++, with WinRT being an evolution of COM.

1h agoHN ↗

I've never heard of anyone calling SOM 'better' at anything this century. I came across it when it was the foundation for OpenDoc at Apple, your comment brought back many bad memories

55m agoHN ↗

Compared with COM's design, it was much better.

33m agoHN ↗

Wouldn't a normalized protocol based on AST vocabulary and tree operations make more sense ?

3h agoHN ↗

Stop letting Microsoft design protocols and APIs.

Unfortunately nobody else stepped up to do it.

I'm glad that the code editors out there didn't wait for your theoretical better designed protocol and decided to adopt LSP. Otherwise we'd still have editor that only support one language properly, and the rest is treated like text. If the price to pay is that it sucks for the handful of people who have to work with it, so be it. For every LSP developer that suffers there are tens of thousands of downstream users who benefit from better language support in their favorite editor!

46m agoHN ↗

we'd still have editor that only support one language properly

Emacs supported zillions of languages before LSP.

Zoom out.

23m agoHN ↗

As someone that got introduced to it in 1996, and was a fan of XEmacs variant, still remembers enough keybindings and Elisp, supported beyond plain syntax highlighting was very much hit and miss, even nowadays.

1h agoHN ↗

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.

1h agoHN ↗

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.

1h agoHN ↗

I've not written a language server but have written a language plugin for IntelliJ.

I started with writing a correct recursive descent parser. I then extended it to detect, report, and recover from common syntax errors as I encountered them so that the parser is robust. And adding a parser test case for each of these (e.g. one test for each branch through an EBNF construction).

Some examples are:

1. missing keywords when the keyword can be detected from the current context (e.g. missing semicolon at the end of a statement);

2. using the wrong token (e.g. `:` instead of `::` in a C++ namespace qualified name);

3. detecting and ignoring whitespace in a whitespace-sensitive qualification (e.g. in XML QNames);

4. keeping in the prolog state (where functions are defined) when there are errors so that functions after the error don't get lost;

5. lexing incomplete literals like `10e` so they can be handled as integers in the parser and emitting an error for them.

21m agoHN ↗

recover from common syntax errors

It's a dead-end. Sure, it can work in simple cases, but there will be always a case where such syntax recovery isn't possible. That's why relying only on syntax recovery isn't an option.

Because of that I use a different approach. I do parse on each document editing, but such parsing is guaranteed to produce valid results only up to the point with broken syntax, where editing usually takes place. Such parsing is enough to reconstruct location of the point where editing takes place (namespace/class/function) and to reconstruct local context (local variables declared prior to editing place). This allows to perform almost perfect autocompletion by suggesting global and local names available at the editing point. In order to provide proper suggestion of non-local names declared after the editing point, I do keep a structure for the most recent document state with valid syntax.

With features like "go to definition" I do the same. I store a hash-table with location to definition point mapping, but it's updated only from time to time and only if document syntax is valid. In order to be usable for cases with edits made after building such hash-table I just perform text-based position mapping using accumulated edit events.