https://toitlang.org/ logo
Zed language extension
# general
j
Hi! I wasn't sure where to post this so here we go. I'm using Zed as my code editor and would like to have Toit language server integrated into it to be able to have syntax highlighting other features that LSP provides. I'm willing to give developing it a go myself. Is it something you (authors of Toit) want to have or are willing to support? Or should it be created as a community extension?
f
Hi Jesse. A language extension for Zed would be great. I just had a short look, and it seems like Zed extensions are based on treesitter and LSP. For the LSP part we should have you covered. (There are still some LSP features that could be added to our server, but that's an independent feature request). The harder part will be the syntax highlighting (treesitter). The Toit grammar isn't very similar to other languages and writing the treesitter rules might be difficult. That said, a treesitter grammar would be really nice. In fact, we are willing to modify the language if that helps writing the rules. Obviously we are not going to completely redo the language, but if there are edge cases or rarely used corner cases we can discuss changing those. As for the support: I would be happy to maintain it in our ide-tools repository.
j
I did the same findings about syntax highlighting being based on treesitter. Initially I wrongly assumed that syntax highlighting is responsibility of language server. Developing treesitter parser will definitely be some amount of work. I didn't find any suitable compatibility layers or conversion tools between treesitter parsers (used by Zed) and textmate languages (used by VSCode). That kind of solution would have been nice to not have to maintain syntax / parsers in multiple different formats.
Now I'm wondering what different syntax highlighting solutions are there for different editors, what would be good for Toitlang to support, and if they can somehow be combined
f
The LSP can be used for syntax highlighting, but Zed seems to prefer treesitter, and the syntax highlighting part of Toit's LSP isn't complete yet.
From my experience it's always a start from scratch.
There is the question of how good the subtract highlighter is. Sometimes even just having keywords highlighted is a good start. Others have a full parser to be able to support definitions vs calls.
j
There's some work being done to support for semantic tokens from language servers to Zed: https://github.com/zed-industries/zed/pull/39539
f
That would help. I could look into our LSP server to improve semantic tokens.
j
If I understand correctly, VSCode also supports LSP semantic tokens. So maybe a good approach would be good to use semantic tokens for both of those editors eventually?
I can try to help with the language server, if you give me pointers on it. If you want my help on it of course 😄
f
Even if there are semantic tokens you still need a regular syntax highlighter first. Similar to Zed, semantic tokens augment the existing highlighter
j
Right..
f
I don't know enough about treesitter yet to know whether one can write minimal rules (a bit like just highlighting keywords). If yes, that could be a start. I will try to have a look this weekend.
Even if I don't manage to finish it, there should then be something to work on and help.
I worked on this for several hours yesterday and today, but so far no real progress. Tree-sitter is really not well suited for indentation-based languages like Toit, and I still haven't figured out how to correctly do this. I have started to ask on the tree-sitter Discord, and hope that I will get some good suggestions. For now, I have no idea of how this should (or even could) be implemented.
d
at https://github.com/davidg238/tree-sitter-toit there is a wip. Currently only pass/fail 105/39 of the files in toitlang/toit/lib
f
Nice.