top | item 39415746

(no title)

sergiogdr | 2 years ago

How does TS compare to using semantic highlighting in LSP?

discuss

order

semiquaver|2 years ago

A large number of LSP servers and related software use tree-sitter as a backend.

ReleaseCandidat|2 years ago

That's not possible, as Treesitter doesn't do for example type-checking (unification). It can be used as the parser to generate the AST with which you're actually doing the work.

thworp|2 years ago

It's slightly worse but a lot faster and better at dealing with spelling/syntax errors. Also, the LSP can render inline error messages and line markers on top of TS highlighting so not much information is lost by just using TS highlighting everywhere.

cybrexalpha|2 years ago

Having tried both with Neovim, I ended up going with just LSPs instead of using tree-sitter.

ReleaseCandidat|2 years ago

With Treesitter you have another parser which is redundant at best and inconsistent with the LSP at worst.

pedrovhb|2 years ago

Not sure I understand your point.

LSP is a protocol and tree-sitter is a parser generator. They're kind of orthogonal concepts; a tree-sitter parser couldn't ever be used directly in place of an LSP server, but an LSP server may well make use of tree-sitter as a first step for extracting information from the code and keeping it in sync. If it doesn't it'll have to come up with some other way of parsing the code in any case, so I don't see how it could be said to be redundant or inconsistent.

Of course, tree-sitter's thing is how universal it is. There's parsers for tons of languages, and you can work with them all using the same API, though you're on your own for attributing semantic meaning. Most popular languages have language-specific tools (e.g. `libcst`) which are usually more powerful for that specific language, so they'd probably be better starting points for building a language-specific LSP server which I imagine is the common case.