Skip to content
BENIBIX Learn

Tree-sitter vs Language Server

People think Tree-sitter and a language server do the same job in an editor, and they do not. Tree-sitter reads the shape of one file, fast, and it is used to colour and fold code. A language server knows what names mean across the whole project. It powers go to definition, rename and error hints. Most editors use both, side by side.

Development🕸️ Code Intelligence

Tree-sitter

A fast tool that turns code into a tree of parts. It keeps up as you type.

Tree-sitter is a free tool that turns source code into a syntax tree, fast. It can build parsers for many languages from a grammar file. When you edit a file, it updates only the part of the tree that changed. It still gives a useful tree when the code has errors in it. Editors use it for colouring code, and code intelligence tools use it to find symbols.

Example
An editor uses Tree-sitter to colour a Python file. Each key Lucy presses updates the tree at once.
Why it matters
One parser library covers hundreds of languages. Tools can read code in all of them the same way.
Full entry
Development🕸️ Code Intelligence

Language Server Protocol (LSP)

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

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
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.
Full entry

In one line

Tree-sitter
A fast tool that turns code into a tree of parts. It keeps up as you type.
Language Server Protocol (LSP)
A shared way for any code editor to get help with a language. One server serves all.