HOCON Colorizer - A VSCode Extension for HOCON

Introduction

HOCON Colorizer is a VSCode Extension for HOCON, which is frequently used in Sponge.

VSCode (https://code.visualstudio.com/) is a powerful text editor developed by Microsoft.

Download Link

This extension is available on the official website: HOCON Colorizer - Visual Studio Marketplace.

You can also search HOCON or HOCON Colorizer in the extension tab to install it by VSCode itself.

Features

HOCON Colorizer now supports:

  • Primitive values such as nulls, booleans, numbers, time units, etc.
  • Strings (including quoted, unquoted, and multi-line strings)
  • Comments starting with a hash (#) or two slashes (//)
  • Objects ({ key1: value1, key2: value2, ... })
  • Lists ([value1, value2, value3, value4, ...])
  • Value concatenations for strings, lists, and objects
  • Path expressions (like key1.key2.key3)
  • Substitutions (${path}, or ${?path})
  • Inclusions (include "file.conf")

HOCON Colorizer now provides:

  • Syntax highlighting
  • Folding based on indentation
  • Code parsing through a built-in parser
  • Code formatting by pressing Ctrl+Shift+I

Future Plans

The features which HOCON Colorizer plans to be implemented in the future:

  • Locating the definition referred to by substitution (similar to Find Usages in IDEs)
  • Support for inclusions (like include 'file.conf') supported since v0.2.1
  • Error message with more readability supported since v0.2.2
  • Code formatting supported since v0.2.3

… and all the valuable suggestions in the replies below.

Source Code and License

HOCON Colorizer is open source (ustc-zzzz/hocon-colorizer), and is mostly written in Scala (compiled to JavaScript by Scala.js). The source code is under MIT License, which is based on a Scala library named fastparse (lihaoyi/fastparse, also licensed under MIT).

8 Likes

What Scala.js library did you write that was nicely compatible with Hocon? I’ve been looking for something in Scala.Js that I could use to create essentially an online config editor, with support for known Data formats (that were also coded in Scala as opposed to Java)

Awesome work, would love to see the javascript code editor embedded in an online site as well, (I know it’s possible given the editor they use, amount of work I don’t know) But not sure if it’s possible with the extension architecture.

All the parsers (based on fastparse) are written by myself: hocon-colorizer/src/main/scala/com/github/ustc_zzzz/hocon/HoconParsers.scala at master · ustc-zzzz/hocon-colorizer · GitHub

Writing an editor starting from scratch is much more difficult than writing an extension only. Writing an extension only needs to consider parsing, syntax highlighting, text completing, etc. which are based on the language itself. However, writing an editor should also consider user interface, file management, and lots of trivial things which have no relationship with the language.

Absolutely. But I don’t know enough about the internals of VSCode and how close to the ‘metal’ of Monaco the extensions sit.

Is the editor that VSCode is based on, and can be easily embedded in browsers, as VSCode itself is an electron app.

@ryantheleach I think that I need to spend some time to figure out if it’s easy to migrate to this online editor. But at present, I think the most worthwhile thing to do is to improve experience based on VSCode itself.

Anyway, it is also a good starting point. Thank you for your suggestion.

1 Like