I started working on a Swift colorizer for Visual Studio Code a few days ago. While looking through the code for VS Code1, I've come to realize a few things.
- There are basically three different ways to create colorization:
- With a TextMate syntax file
- With a "Monarch" syntax declaration; I can only assume this is a VS Code specific declaration
- A full language service 2. Customization is not really supported that well at the moment 3. Swift has a bunch of language constructs to worry about in order to properly colorize itself
I actually tried going down the path of building a proper tokenizer to give semantically correct highlighting, but without knowing how the internals of VS Code really work2 and my lack of wanting to build a full on parser for Swift, I opted to go down the "Monarch" syntax path3.
So… does the "Monarch" syntax declaration work well? Actually, it works quite well. It's basically a declarative state machine syntax so it allows some pretty nice stuff that is either extremely difficult or just impossible to do with regex. For instance, string interpolation highlighting was fairly straight-forward and you can push and pop states on the syntax highlighting stack.
Anyhow, I've updated the project here: https://github.com/owensd/vscode-swift. It's mostly working, though I do have a set of known issues and I haven't got around to implementing those yet, such as unicode operator colorizing.