Hacker News new | ask | show | jobs
by mikesickler 977 days ago
Sorry if dumb question, but is LSP similar to what Steve Yegge talked about years ago, I think on a StackOverflow podcast, whereby a language would declare its capabilities to tooling?
3 comments

I haven't listened to the podcast you mention, but the answer to your question is yes. Quoting the langserver.org homepage[0]:

> The Language Server protocol is used between a tool (the client) and a language smartness provider (the server) to integrate features like auto complete, go to definition, find all references and alike into the tool

In LSP terms, these are called "capabilities". The relevant section in the LSP spec is here [1].

There's some variation across editors in exactly how the config works - or, at least, part of it. Some config is done in native files that form part of the plugin. Those are largely editor-specific. The protocol itself defines messages for the server to indicate which facilities it supports. Those are (mostly) editor neutral from my experience thus far (mostly VSCode, a little Emacs).

--

EDIT: added link to capabilities section in the LSP spec.

[0]: https://langserver.org/

[1]: https://microsoft.github.io/language-server-protocol/specifi...

Yes, the genius of LSP is that it doesn't attempt to define common semantic operations across languages, which would be (and has been) an endless impossible task to get right. It operates at the level of editor UI. So you don’t ask LSP “what are the members of this struct”, you ask it “what are the autocompletions of this code fragment”. It leaves the decisions about what would be appropriate in the language to the language server written by the experts in the language.
Sort of, except not really. It’s largely the other way around: LSP gives the editor a way to declare its capabilities to the language.

The key insight with LSP is that languages are _way_ too different to have that notion of language capabilities. Instead, the LSP defines functionality that the editor wants to use (syntax highlighting, refactoring, autocomplete, etc) and the language server tells the editor what to display.

When you trigger autocomplete in VSCode, the editor has no clue whether it’s autocompleting a method, a class name, or a variable. It’s just telling the language server “hey the user asked for autocomplete in file X, offset Y” and the language server tells the editor what completion options to offer.

> The key insight with LSP is that languages are _way_ too different to have that notion of language capabilities.

And yet the very opposite of this is the source of JetBrains success.

Haven’t seen the podcast Lsp doesn’t declare language capability, the editor asks it what the editor should do and the LSP responds