oooh thank you! i wonder if a port to zed would be too hard; i can take a look at that soon
Zed uses tree-sitter which is the SOTA tool for parsing programming languages. VSCode is working on tree-sitter support too, it’s the “real solution”.
Try pasting this into zed
{
hello-script = # bash
''
#!${pkgs.bash}/bin/bash
set -euo pipefail
echo "Hello, world!"
echo "Current directory: $(pwd)"
'';
}
(AI slop example, but try removing # bash and it should change colors in Zed)
Good work to author though, I’ll use this while waiting for tree-sitter 
1 Like
oh sweet! i didn’t realize zed did it that way; moved all my scripts to their own files and started home.fileing because the syntax was annoying me when I used vscode and never thought to check again when i switched.
Nailed it
, thanks for answering that for me. The tree sitter is so good it’s practically cheating haha. Ive been trying to get VS code to switch for half a decade. That said, I’m not sure how editors like Zed handle nested languages. I didnt know about that # bash trick in Zed, thats fantastic
And on that note, I should mention it is provably impossible to parse nix correctly with the TextMate parser. I have to use a ton of cheats to make it look correct, and there are going to be bugs I just can’t fix. For example, the textmate parser can’t “go back” to a previous line. So if I see a {\n I don’t know if its an attr-set or the start of a function.
1 Like
My understanding is that TextMate is inadequate for most parsing. The # bash trick is called “language injection” and is defined here: tree-sitter-nix/queries/injections.scm at ea1d87f7996be1329ef6555dcacfa63a69bd55c6 · nix-community/tree-sitter-nix · GitHub but I don’t speak tree-sitter, i just know it works in Nix 
There’s also tree-sitter-vscode - Visual Studio Marketplace but it requires you to build tree-sitter parsers as wasm which I couldn’t figure out in nixpkgs when I looked at it.
Edit: I think Zed is developed by the people who wrote tree-sitter, which are the same people who worked on the Github Atom editor 
2 Likes