-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide access to VS Code API in extension uninstall lifecycle hook #45474
Comments
Well, for now, I’m gonna put the settings as global and remove them after plugin uninstall thanks to this: https://stackoverflow.com/questions/49205613/how-to-execute-code-when-user-uninstalls-your-vscode-extension/49211345#49211345 |
I couldn't get it to work after extensions uninstall because the package "vscode" cannot be found when the uninstall hook executes my JS file with node. I read that this is the normal behavior, i cannot use the vscode api in the uninstall hook then... |
@GabrielBB Can you return the promise during deactivate and try? export function deactivate(context: vscode.ExtensionContext) {
return vscode.workspace.getConfiguration().update('test', '', ConfigurationTarget.Workspace);
} |
@sandy081 Just tried it, doesn't work. What i noticed debugging is that VS Code is not even waiting for the event code to fully execute. When i put a breakpoint in the return, it only lasts like 2 seconds, then the thread is getting killed or something. So for now, we cannot clean settings in deactivation nor in uninstall (#35006 (comment)). |
@alexandrudima Are you aware of this? |
@sandy081 @alexandrudima I forgot to tell that this is happening while changing workspaces or closing VS Code. I don’t know about other deactivation scenarios, like when closing a file with an extension that was activated when that file was opened |
This is as designed. The |
@alexandrudima Understood. Well, i don't have options then since the uninstall hook can't access the vscode api, basically developers can add settings but can't clean them (at least they clean it when a specfic file is closed) For now i'm manually going to the user settings json in your file system and editing it when the extension is uninstalled like this: https://github.com/GabrielBB/vscode-lombok/blob/master/src/uninstall.ts (Dirty solution lol) I will open a feature-request for vscodeapi in uninstall hook |
@GabrielBB Makes sense. Please update the current issue to support for such api in uninstall hook. |
This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines. Happy Coding! |
An alternative is to declaratively mark settings which are meant to be deleted from the user settings file on uninstall. |
Throwing an idea here. How about moving the export function uninstall(context: vscode.ExtensionContext) {
// Execute uninstall code which has access to `vscode` API
} |
@JimiC This does not help to update the configuration. |
@sandy081 How come? Wouldn't the access to And to be more clear, the idea is to have the I know that this will require that |
That would be even better. That will make me delete a lot of code and testings. |
I hope you guys consider also that we are writing in the |
any updates on this? |
Any updates? |
No updates yet. |
Maybe I'm missing something, but shouldn't it be possible and fairly simple to add an uninstall hook with the exact same signature of the activate hook in the main extension file, then when a user clicks the uninstall button for the extension, simply I'm not sure users understand that when they uninstall an extension, all of their user settings, workspace settings and globalState for the extension still exists. |
The thing is that the uninstall hook works a bit unconventional. From my observations the lifecycle goes like this:
On step 3 Note: |
Right, but why not call extension.uninstall() when the user clicks uninstall to give the extension a chance to run cleanup routines, THEN mark it as obsolete and continue like it does today? |
@jdoklovic +1000 |
@jrieken: Is there currently a way to determine if an extension deactivate() is due to, or happens after, an uninstall? For Live Share I'm interested in disposing our vsls-agent.exe immediately after the uninstall Live Share extension button is clicked. I could force kill our agent process on deactivate() if I could determine it was due to an uninstall. We keep our agent alive after reload for a few seconds so this impacts proper cleanup and can cause issues if a user attempts to reinstall the extension immediately after an uninstall (in this scenario the vsls-agent.exe in the target install path would still be locked). |
afaik there is nothing to observe uninstall but a ping for @sandy081 for more insights |
|
OK seems I have a related/same issue reported here - #103688 by attempting to get some insight into debugging or logging output to understand what is going on. Current attempt is to write the process.env object to a JSON string on disk and I have noted that there are some VSCode specific ENV variables. So the uninstall code being executed is aware its being run from VSCode, with this being the case is it possible to get access to the vscode API in the uninstall script? ENV Variables available in vscode:uninstall hook
|
Steps to Reproduce: Add this events to an extension code:
When it activates it updates but on deactivation it doesn't work. Im debugging and the code is running but with no effect. I also tried with ConfigurationTarget.Global.
The text was updated successfully, but these errors were encountered: