What Is LSP?

What Is LSP?

The problem it solved

Before LSP, every editor needed its own plugin for every language: N editors × M languages worth of duplicated work. The Language Server Protocol (originally from VS Code) splits the problem: a language server is a separate program that deeply understands one language, and any editor that speaks the protocol gets its intelligence for free.

What a server gives you

Once a server is attached to a buffer you get, among others:

  • Diagnostics — errors and warnings as you type, in the gutter and inline.
  • Go to definition — jump to where a symbol is defined (gd).
  • References — every usage of the symbol under the cursor (grr).
  • Hover docs — signature and documentation in a float (K).
  • Rename — project-wide, syntax-aware renaming (grn).
  • Completion — the candidates your language actually allows here.

The moving pieces in Neovim

Three things must exist:

  1. The server binary — e.g. lua-language-server, basedpyright-langserver. Mason installs these.
  2. A client configuration — the command to launch, which filetypes it owns, how to find the project root. nvim-lspconfig ships these definitions; Neovim 0.11+ activates them natively with vim.lsp.enable().
  3. Keymaps and UI — modern Neovim ships good defaults (grn, grr, gra, K, [d/]d); you add taste on top.

Check what is attached to the current buffer at any time:

:LspInfo