> It is possible to use the language server for syntax highlighting. I am not aware of any particularly strong reasons why one would want to (or not want to) do this. The language server can be a more complicated program and so could surface particularly detailed information about the syntax; it might also be slower than tree-sitter.

We (TypeScript) used to do this for Visual Studio prior to tmLanguage. It was nice because we didn't have to write a second parser. Our parser was already error-tolerant and incremental, and syntax highlighting just involved descending into the syntax tree's tokens. So there was no room for divergence bugs in parsers, and there was also no need to figure out how to encode oddities and ambiguity-breaking logic in limited formats like tmLanguage.

This all predated TSServer (which predated LSP, though that's coming in TypeScript 7). The latency for syntax highlighting over JSON was too much, and other editors often didn't make syntax highlighting available outside of tmLanguage anyway. Eventually semantic highlighting became a thing, which is more latency-tolerant, and overlays colors on top of a syntactic highlighter in VS Code.

The other issue with this approach was that we still needed a dedicated thread just for fast syntax highlighting. That thread was a separate instance of the JS language service without anything shared, so that was a decent amount of memory overhead just for syntax highlighting.

Hey there! Thanks for reading my article, and thanks for sharing something cool about TS!

------

Real quick: I'm a PhD student and I'm looking for an internship this summer. I've done a little work with gradual typing—working with TypeScript would be super cool! I don't see a good way to contact you on your profile, hence this reply; if you've got an opening for an intern on your team, I would be very interested in applying. My email is on my blog.

Thanks again for reading my post!

Yep, we do the same in-LSP-highlighting in a game programming language I help develop. We have a lot of really niche rules, and nobody's gotten around to making a full separate tree-sitter spec for our small language.