JSONC Attributes

March 17, 2023 ยท View on GitHub

Upload/Download

Upload

On upload, all identified blocks will be commented

So if locally, you have:

{
    // #enable(os="linux")
    "key": "foobar"
}

The following will be uploaded to the repository:

{
    // #enable(os="linux")
    // "key": "foobar"
}

Download

When downloaded, the settings.json is processed to enable/uncommented all lines/blocks when the condition are true.

Variables

VariableDescription
editorvisual studio code, vscodium, mrcode or the lowercased nameLong in product.json
editorStoragethe directory where the extensions are stored (ex: ~/.vscode)
globalStoragethe directory where the extensions are storing their global states (ex: ~/Library/ApplicationSupport/Code/User/globalStorage)
hostnamethe hostname found in settings.yml
profilethe profile used to sync
oslinux, mac or windows
userStoragethe home directory of the user
versionthe version of the editor
<ENV>all env variables are directly available, like EDITOR => #if(EDITOR="vi")

Blocks

enable

{
    // #enable(os="linux")
    // "key": "foobar"
}

If os is equal to linux, the block "key": "foobar" will be uncommented.

if/else

{
    // #if(os="mac")
    // "key": "foo"
    // #elif(os="windows", host="host1"|"host2")
    // "key": "bar"
    // #elif(version>="1.59.0")
    // "key": "qux"
    // #else
    // "key": "baz"
    // #endif
}

#elif(os="windows", host="host1"|"host2") is true when os equals windows and host equals host1 or host2.
#elif(os="windows", version>="1.59.0") is true when version is greater than or equal to 1.59.0.

ignore

The property won't be uploaded and is kept when downloading a new settings.json.

{
    // #ignore
    "key": "foobar"
}

Condition

condition = expression ("," expression)*
expression = (unary-operator identifier) | (identifier operator values)
identifier = \w+
operator = "=" | "!=" | "<" | "<=" | ">" | ">="
unary-operator = "?" | "!?"
values = value ("|" value)*

value is a double quote string.
The operators <, <=, >, >= are only working for the identifier version.