VS Code Swift Colorizer

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.

  1. There are basically three different ways to create colorization:
    1. With a TextMate syntax file
    2. With a "Monarch" syntax declaration; I can only assume this is a VS Code specific declaration
    3. 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.


  1. After all, it's just a JavaScript app.
  2. All of that code is minimized as it's not ready for mainstream consumption.
  3. As far as I know, there are no TextMate Swift colorizers that actually work for the entirety of the language.
VS Code Swift Colorizer