microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.61k stars 29.42k forks source link

Ability to clear/delete a variable inside EnvironmentVariableCollection when extension is disposed/restarted #234384

Open alii opened 16 hours ago

alii commented 16 hours ago

Currently when an extension is disposed, vscode (as far as I can tell) will ignore usage of EnvironmentVariableCollection.clear() or EnvironmentVariableCollection.delete(key)

context.subscriptions.push({
    dispose() {
      // Tried both clear and replace at the same time, as well as independently. Seemingly no results with any combination
      context.environmentVariableCollection.replace("MY_UNIX_SOCKET", "");
      context.environmentVariableCollection.clear();
    },
});

This is frustrating in our use case, because we have a unix socket that is created each time the extension starts - which means that if the user restarts the extension host we generate a new socket url. Existing terminals then can no longer communicate with the socket, and have to relaunch their terminal. Currently as a workaround I'm storing the socket url in context.globalState and reusing it on restart. This works and existing terminals can just keep assuming the stale URL is correct, but ideally we'd be able to create a new one.