Tree-Sitter

Tree-Sitter

January 24, 2024 | seedling, permanent

tags :

Summary #

Tree-sitter is a parser generator tool and an incremental parsing library. It can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited. Tree-sitter aims to be:

General enough to parse any programming language Fast enough to parse on every keystroke in a text editor Robust enough to provide useful results even in the presence of syntax errors Dependency-free so that the runtime library (which is written in pure C) can be embedded in any application

URL

An incremental parsing system for programming tools github

Lot better than re based syntax parsing.

Emacs #

https://emacs-tree-sitter.github.io/ from 29.1 tree-sitter is part of emacs.

customizations

Tree-Sitter vs LSP #

  • You can think of LSP as something that works on the “large”.

  • Tree sitter works on the “small”. LSP is like a smart index of your entire project to power goto-definition and auto completion.

  • Tree-sitter just makes a tree of objects representing the text in your buffer.

  • There can be a some overlap in the features they power but that’s coincidental.

  • Tree-sitter by it’s nature is better suited to power syntax highlighting. And better suited to power structural edits (barf, slurp, transmogrify).

As far as overlap, one case would be highlighting all instances of the variable your pointers is on. This might be possible with LSP but it would be super overkill to send a JSON message to an external server just to highlight a few local references on the screen. Tree sitter would be best for this. But if searching the entire project for variable references LSP would make sense as that’s the “large”. reddit


Go to random page

Previous Next