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