A first draft for simple syntax highlighting
This adds syntax highlighting for git commit and rebase messages. Support for other languages is on hold until I finished writing a proper VM for executing the highlighting instructions.
Closes #18
looking forward to the other languages. they seemed to work well enough in https://github.com/microsoft/edit/tree/4f36e2afe2a84ed339829ea6c63242fb9f4b7de3 (well, really long Here Strings made the rest of the file red, but ones with a reasonable length were fine)
PR awaiting 2 pending checks still.
Working on this feature? In the current economy?! (I'll try...)
Thanks for your work on this. I've played around with this branch a bit and want to share my thoughts on the current implementation.
I tried to hack together basic C highlighting and noticed there is some state missing for "constants" (convention with all-uppercase variables usually defined with #define or part of some enum, not usual variables defined with const). Those are neither a Keyword nor a Variable.
Could the regexes be loaded from a file in the future? It might save some work to implement the basic functionality now by parsing a hardcoded string rather than defining everything in build/lsh/definitions.rs in rust code. Then it just needs the decision of what file(s) and from where to load + implement the actual file loading at a later point.
Another thing I wondered about is why the HighlightKind enum contains any colors, I have a feeling that those should be translated by themes from states like Comment or String.
Edit:
Some more feedback: support for Look::WordAscii (\b) and/or Look::WordStartAscii (\<) + Look::WordEndAscii (\>) would be very useful. Currently I can differentiate between break and breakage but not between break and unbreak. I've tried to implement it myself in build/lsh/compiler.rs but I am not familiar enough with rust and the regex-syntax crate.
FYI I've continued development in the https://github.com/microsoft/edit/tree/dev/lhecker/syntax-highlighting-alt branch where I've since written a custom language with proper compiler. It even has rudimentary support for variables. It's fairly time consuming to develop so it's taking a while. It's also certainly not done yet, but please feel free to check it out already. You can find the definition files under crates/lsh/definitions.
nice to have PS highlighting back! quick comparison with highlighting as it was in the version I linked above
unrelated to highlighting: mousescroll worked in file dialog in the old one, scrolls edit window instead in the current syntax-highlighting-alt
Why not tree-sitter integration for syntax highlighting and text objects ? You basically get for "free" countless languages. (implementation not considered)
Why not tree-sitter
FWIW, this has been hashed out over in #18. In fact, the justification for having a simple syntax highlighter that is expressly not tree-sitter is described in the issue body of #18.
TL;DR (and it really is not much longer than this comment here): tree-sitter is huge. Edit is 250KiB. We don't want edit to become much larger than it already is.