AnWeber / vscode-httpyac

Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=anweber.vscode-httpyac
MIT License
237 stars 20 forks source link

automatically set default env in a project without manually selecting #192

Closed domeniczz closed 1 year ago

domeniczz commented 1 year ago

there could be a feature that set the env to default if there's only one env config.

for example in the config http-client.env.json below, there is only one env defined, so the plugin can be smart enough to set dev as default env

{
  "dev": {
    // ...
  }
}
AnWeber commented 1 year ago

I do not find the feature useful. No environment is a valid environment for me (my default with local settings). Another point is that I want to minimize resource usage. I would have provided different alternatives that also achieve your desired behavior.

module.exports = {
    configureHooks: function (api) {
        api.hooks.parseEnd.addHook('set_env', function (context) {
            if (!context.httpFile.activeEnvironment || context.httpFile.activeEnvironment.length === 0) {
                context.httpFile.activeEnvironment = ['dev']
            }
        });
    }
}