#visual-studio-code #cli #workspace #template #generate #gen #object

app vscode-workspace-gen

Generates vscode workspace files from a template

12 releases (7 stable)

new 1.6.0 Apr 27, 2024
1.5.0 Apr 16, 2024
1.2.0 Mar 31, 2024
0.2.1 Mar 30, 2024
0.1.2 Mar 30, 2024

#36 in Command line utilities

Download history 566/week @ 2024-03-25 242/week @ 2024-04-01 5/week @ 2024-04-08 252/week @ 2024-04-15

1,065 downloads per month

MIT license

37KB
917 lines

vscode-workspace-gen

A cli tool for generating vscode workspace files from a template.

The goal is to workaround https://github.com/microsoft/vscode/issues/53557

vscode settings and workspace files suffer from huge json duplication. With this tool you can specify json objects you want to reuse and then reference them instead of duplicating.

Installation

cargo install vscode-workspace-gen

or, if you're a Qt user:

cargo install vscode-workspace-gen --features qt

Usage:

A real scenario could be factoring-out duplicated vscode launches, pretty printers and source map settings.
For the purpose of this example we'll just show some dummy JSON instead.

Add every object you want to reuse to the globals section.

{
    "gen.globals": {
        "numbers": {
            "one": 1,
            "two": 2,
            "three": 3
        }
    },
    "obj1": {
        "a": "@{numbers}",
    },
    "obj2": {
        "b": "@{numbers}",
    }
}

Run it on your template:
vscode-workspace-gen vscode.code-workspace.template

and get:

{
    "obj1": {
        "a": {
          "one": 1,
          "two": 2,
          "three": 3
        }
    },
    "obj2": {
        "b": {
          "one": 1,
          "two": 2,
          "three": 3
        }
    }
}

Syntax

gen.description

You can add descriptions in your template objects. They won't be present in the output.

"obj1": {
    "gen.description" : "Some field with some purpose"
}

inline expansion and nested expansion

Inline expansion, @@{foo} will expand the contents of foo into the parent object.
Nested expansion, @{foo} is similar, but won't discard foo's actual container, and will nest it.

For example, given "list" : [10, 20, 30]

The following template:

    "obj": {
        "somelist1" : [1, 2, 3, "@{list}"],
        "somelist2" : [1, 2, 3, "@@{list}"]
    }

results in:

    "obj": {
        "somelist1" : [1, 2, 3, [10, 20, 30]],
        "somelist2" : [1, 2, 3, 10, 20, 30]
    }

gen.os

You can make certain objects only available on specific operating systems.

 "obj": {
    "gen.os" : [ "windows, "linux" ]
 }

If run on macos, the above object won't be included in the output.

config

You can create a .vscode-workspace-gen.json file and change some settings. Currently supported settings:

{
    "json_indent": 2,
    "output_filename": "vscode.code-workspace",
    "per_os_output_filenames": {
        "linux": "linux.code-workspace",
        "windows": "windows.code-workspace",
        "macos": "macos.code-workspace"
    }
}
  • json_indent Specifies the amount of indentation for the JSON output
  • output_filename Equivalent to passing -c <output_filename>. The commandline has priority though.
  • per_os_output_filenames Allows to generate output for each operating system. Each file is potentially different, due to usage of gen.os This option is incompatible with output_filename.

Env var replacing

Since vscode won't replace ${env_var} everywhere, we support replacing env vars as well, but in a more consistent manner.\n Any occurrence of $${env_var} will be replaced with the env var's contents. This workarounds msvc launcher supporting expanding ${env} while the LLDB ones not.

Convenience for Qt

If you passed --features qt to cargo install, you have some convenience options regarding Qt. For now, it adds:

  • --download_qtnatvis Downloads the qt6.natvis, which contains pretty printers for debugging Qt.

Build
Build
Build
No Maintenance Intended

Dependencies

~4–17MB
~223K SLoC