vs-script-commands icon indicating copy to clipboard operation
vs-script-commands copied to clipboard

Improvement: script autoloading

Open sagebind opened this issue 5 years ago • 0 comments

This is a great extension just for making VSCode more extensible and customizable. Would it be possible to auto-load scripts on startup? In addition to getting a list of scripts, also auto-load any scripts in a given directory.

An example of what that might look like in settings.json:

{
    "script.commands.autoloadPaths": [
         "/home/me/.vscode/scripts"
    ]
}

A sane default set of paths would be in $HOME/.vscode/scripts and ${workspaceFolder}/.vscode/scripts. Those paths would satisfy me, and it would not even have to be customizable to start.

Basically you would list all files in each directory configured to be autoloaded and look for *.js files. Then you would load the file with require() a little earlier so that you could access a command export that mirrors the one in the settings.

Short example:

// Inside ${workspaceFolder}/.vscode/scripts/example.js
exports.command = {
    id: "my.command.id",
    displayName: "Example script command"
};

exports.execute = function (args) {
    args.log("Hello world!");
};

Organizing scripts in this way would be much easier to manage, and could be supported simultaneously with the existing method.

sagebind avatar Jul 26 '18 19:07 sagebind