Add a way to seed config item values

It would be great if configuration item options had a new seed option, that allows the extension author to define a value that pre-populates only once when the extension is first installed.

Sometimes you need to provide the user with sensible defaults, that they can delete if they so choose. If you use the config item option default, the user won’t be able to delete the default value.

My current use case for this new seed option is that I want to store a whitelist of allowed hosts in a config item with type stringArray, and have it pre-populated with hosts widely considered trustworthy. Over time at the right moments, the user is prompted to add more hosts to the whitelist. At any time though, the user should be able to delete the seeded hosts if they so choose, even if they haven’t added their first hosts to whitelist yet.

Side note, but the stringArray config item type doesn’t accept a default option, so it’s not even available for use in this situation (that needs to be fixed separately to this feature request, perhaps it’s a bug?).

In the meantime, I’m considering manually seeding config item values with this dirty hack:

exports.activate = () => {
  // On the first activation, seed the extension config. Unlike default values,
  // prep-populated values can be deleted by the user. Also, some Nova config
  // field types such as `stringArray` don't support default values.
  if (!nova.config.get(`${extensionId}.seeded`, 'boolean')) {
    // Pre-populate trustworthy module hosts known to support import
    // IntelliSense.
    nova.config.set(
      `${extensionId}.config.suggest-imports-hosts-enabled`,
      ["https://deno.land"]
    );

    // This config entry is purposefully not user visible or editable, by not
    // defining it in the `extension.json` under `config` or `workspaceConfig`.
    nova.config.set(`${extensionId}.seeded`, true);
  }
1 Like