4 ms·
The problem is that a good editor-compatible tool for parsing and syntax highlighting is at cross-purposes with what you want from a compiler. A good overview
by troupo 3y ago
The problem is that a good editor-compatible tool for parsing and syntax highlighting is at cross-purposes with what you want from a compiler.
A good overview here: https://matklad.github.io/2022/04/25/why-lsp.html https://matklad.github.io/2022/04/25/why-lsp.html
- aidos 3y agoInterestingly, treesitter is designed for this space (parsing invalid structures with a time component) but it’s still not used as a base for LSPs. I once asked why on HN and people that know more than me said it wasn’t suitable.
- vkazanov 3y agotree-sitter definitely can be used as a incremental parser for an LSP. But the original purpose was and still is to provide a standard format for an editor-agnostic way to parse languages. As somebody who wrote a tree-sitter grammar recently I can confirm that the library definitely has its share of... Interesting choices. But there's nothing else like it as most parser generators are non-incremental, don't do generalized parsing and don't provide decent error recovery.
- bch 3y ago> has its share of… Interesting choices Curious to hear more.
- vkazanov 3y agoWell, nothing truly horrible but here are things I find inconvenient (but working nevertheless) when using the sdk. 1. NodeJS-based utilities. The tooling around js doesn't lean itself well to integration with with the dev's environment. 2. The sdk itself is a mix of Rust, javascript and C. I'd say that this is at least one language too many - makes it harder to contribute. Ideally such fundamental projects should be as simple and homogeneous as possible. 3. I keep wondering if generating languages other than C should be supported. The core idea of the library is brilliant either way so it sort of compensates all of the above.
- tuukkah 3y agoInsightful article. Key point: > Fourth, Microsoft itself doesn’t try to take advantage of M + N. There’s no universal LSP implementation in VS Code. Instead, each language is required to have a dedicated plugin with physically independent implementations of LSP. There's no (official) LSP implementation for Typescript either. Instead of using LSP, Microsoft maintains tsserver which uses a custom protocol for better integration. Take-home message: don't try to write a universal tool that solves everything, as it will be lowest common denominator. Create building blocks such as Tree-sitter, which make specific (M×N) integrations easier and more powerful.
- nerdponx 3y agoBut Tree Sitter is an M+N tool. Also LSP was never going to completely eliminate the need for language-specific plugins. But it does significantly reduce the amount of work needed to build each one, providing a consistent baseline.
- tuukkah 3y agoIn my classification, Tree-sitter is a building block (a parser), not a tool (compiler, editor, highlighter etc.) And as seen in this HN submission about implementing HTML support for Emacs, it's used in M×N integrations. I didn't know tree-sitter-highlight exists though. It seems to provide M+N highlighting and includes a CLI tool. https://tree-sitter.github.io/tree-sitter/syntax-highlighting https://tree-sitter.github.io/tree-sitter/syntax-highlightin... Similarly, tree-sitter tags seems to provide M+N code indexing: https://tree-sitter.github.io/tree-sitter/code-navigation-systems https://tree-sitter.github.io/tree-sitter/code-navigation-sy...
- nerdponx 3y agoIt's an M+N tool in my opinion because it parses M languages with a uniform interface, for use in N higher-level tools. I can use the same Python grammar/parser with any tool that's based on Tree Sitter.