Skip to content
BENIBIX Learn

Language Server Protocol (LSP)

Development🕸️ Code IntelligenceCode Navigation

Also known as Language Server, LSP Server

A shared way for any code editor to get help with a language. One server serves all.

Think of it like

It is like a plug that fits each socket. One helper works in any editor.

Example

Emma's editor asks the Python server where a name on line 12 of app.py is defined. The answer is line 40 of utils.py.

Why it matters

Before it, each editor had to build help for each language. Now each language is built once.

Definition

The Language Server Protocol is a shared way for code editors to ask a helper program about a language. The helper is called a language server, and it runs on its own. The editor sends questions, such as where is this defined. The server sends answers. They talk in JSON, in a format called JSON-RPC. So one server for a language works in every editor that speaks LSP.

Example code

json
{"jsonrpc": "2.0", "id": 1, "method": "textDocument/definition",
 "params": {"textDocument": {"uri": "file:///app.py"},
            "position": {"line": 11, "character": 8}}}
The editor asks where the name at line 12 is defined. Lines count from 0.
Three editors, one language server, one shared way to ask.

Common mistake

Blaming the editor when hints go wrong. The answers come from the language server, so that is what to update or fix.

Key takeaways

  1. 1
    One server per language. Shared by every editor.
  2. 2
    Ask and answer. Editors send questions in JSON.
  3. 3
    Runs apart. The server is its own program.

Compare