Skip to content

Cleanup ExtensionContext.workspaceState when a workspace no longer exists #32461

Open

Description

No description provided.

Activity

  1. added
    feature-request
    on Aug 14, 2017
  2. bpasero commented on Aug 15, 2017

    @bpasero
    Contributor

    Dirk Bäumer (@dbaeumer) how do we know that a workspace no longer exists? Imho just checking for existence of the path is not enough, there may be many users that work via a remote network drive or even a mounted disk where the connection is not always there. Just going by fs.exists imho can result in bad user experience for these users.

  3. dbaeumer commented on Aug 15, 2017

    @dbaeumer
    MemberAuthor

    Benjamin Pasero (@bpasero) the network drive case is an interesting case I never thought about. We could do the following: if it is a UNC path \...\ and it doesn't exist we leave the workspace storage. Same for a drive letter that doesn't exist. We could prompt the user with a list so that he could clean them manually.

  4. bpasero commented on Aug 15, 2017

    @bpasero
    Contributor

    Dirk Bäumer (@dbaeumer) not sure it is that easy, for example VMs can map a folder into my macOS and this folder is not there if the VM is not started. The path itself does not indicate if it is from a VM/remote or not.

  5. dbaeumer commented on Aug 16, 2017

    @dbaeumer
    MemberAuthor

    Benjamin Pasero (@bpasero) I am not sure I fully understand that example. How would the storagePath and the workspace folder be layout in that case. Would the storagePath be inside the VM and the workspace folder location mounted into the VM?

  6. bpasero commented on Aug 16, 2017

    @bpasero
    Contributor

    Dirk Bäumer (@dbaeumer) no, the extension storage will always be on the disk where VS Code is installed (e.g. %APPDATA%). I was trying to comment on your statement:

    We could do the following: if it is a UNC path ...\ and it doesn't exist we leave the workspace storage. Same for a drive letter that doesn't exist.

    On Linux and macOS there are no UNC paths and there are no drive letters. Paths can come and go depending on mounts (e.g. a parallels VM started or stopped), so by just looking at the path you will not be able to find out if the path was deleted or not mounted.

  7. dbaeumer commented on Aug 24, 2017

    @dbaeumer
    MemberAuthor

    After taking Benjamin Pasero (@bpasero) input into consideration it is clear that we can't simply delete workspace storage folders. So we need some UI affordance that point to large workspace storage folders and ask the user whether we should clean it up or not

    //cc Erich Gamma (@egamma) Kai Maetzel (@kieferrm)

  8. added
    extensions
    on Nov 11, 2017
  9. neerolyte commented on Apr 9, 2018

    @neerolyte

    I'd appreciate some options to choose clean up strategies, checking if it exists is fine if you don't use network paths (maybe you could detect if it's a network mount when creating the workspace files in the first place?). If it is a network mount, perhaps just cleaning up LRU (Least Recently Used) would be fine?

    I just noticed this directory is 35GB on my laptop, with some of the oldest workspaces being nearly a year old and most of them no longer existing (I tend to a roll out a new workspace per feature branch on one project I work on).

  10. woshichengxinxin commented on Aug 30, 2018

    @woshichengxinxin

    cpptools takes 8GB space on my poor C disk.

  11. bmewburn commented on Jan 25, 2019

    @bmewburn

    Could ExtensionContext provide a list of an extension's storagePaths? For my use case I could clean up old data by looking at modtime on extension activation.

  12. 18 remaining items

  13. pdfowler commented on Mar 29, 2022

    @pdfowler

    After another desperate search to clear up some space on my laptop, I stumbled on a 36GB workspaceStorage directory which led me here. While I think that the idea of moving this data to the workplace folder makes sense in some regards, I think there is one other aspect of this to consider: the CPP-Tools extension is not relevant to 99% of my dev work, so why is it creating a 1GB file every time I open a new workspace?

    Concern

    If the proposal to move this data to individual workspace folders was implemented, I worry that it would be less obvious that a rogue extension was eating all my storage. In this case, I would now have 36GB of data scattered about 36 different folders. When considering standalone workspaces setup for each package in our monorepo, and repos spread between my work directory, projects directory, tinkering, etc., I would be hard to see the scale of the problem. Say what you will about having repos in so many different places, but if I were sweeping my HD to clear up space, 1GB wouldn't raise flags (that's entirely normal for node_modules), but 36GB in one folder absolutely does.

    Context

    I do almost exclusively JS/TS/React programming. Last summer I added PlatformIO and some other extensions to compile firmware for a 3d Printer. I have not touched a CPP file since then, and had largely forgotten about those extensions. When finding these files, my first thought was "I never installed this extension" since IIRC it was installed as a part of the PlatformIO setup process. After deleting the CPP-Tools folders, my workspaceStorage directory (going back to July 2016) is only 20.2MB.

    Proposal

    Would it not be better to provide some mechanism for controlling whether an extension will be initialized at all for a given workspace? CPP-Tools seems to be an egregious offender (~1GB per workspace), but might a better solution be to enable Extension Developers to register specific file types which would activate their extension?

    Example

    A toolkit for Extension Developers would work something like this:

    1. Extensions can set a default enabledFiletypes property in the extension registry
    2. When opening a workspace, any extensions with the enabledFiletypes property would be cross checked with the filetypes present in the project
    3. If there is an intersection, enable the extension, otherwise disable it by default.

    Considerations

    1. The logic would need to handle module folders (eg: node_modules) so that a matching file does not activate the extension. This could integrate with the existing Search: Exclude and Files: Exclude settings.
    2. The behavior must be overridable at the user and workspace configuration levels, to both "always enable" and to override the enabledFiletypes
    3. There is merit in the idea of a warning, or automated sweep of old workspace caches; which would be much more easily implemented if this data stays centralized.
  14. hinell commented on Aug 17, 2022

    @hinell

    Patrick Fowler (@pdfowler) I think it should be reasonable to fill an issue in cpptools to ask them to move cache data closer to a project instead of relying on vscode. Global storage was probably worst idea ever. If ones renames a project folder and reopens it in a vscode the wasted storage is going to multiply significantly.

  15. hinell commented on Oct 26, 2022

    @hinell

    There is a bunch of related issue concerning moving workspaceStorage databases to local-to-project .vscode/. The devs said they won't fix it cause the vscode-cpptools extension shares workspaces across project.

    It's probably good idea to consider other C/C++ tooling llike clangd.

  16. removed
    extensions
    on Dec 6, 2022
  17. ThirtySomething commented on Dec 15, 2022

    @ThirtySomething

    I've had the same problem and started to develop an extension to solve this problem. Unfortunately I'm not so familiar with the VSCode API (Visualization page, user requests, unit tests, ...), deploying to the marketplace and so. Because of this the development get stucked. Maybe someone else will continue with this as base? The idea of Ryan (@slugmuffin) to present more information to the user and to ask for deletion is much better than my simple implementation. This could be a list with with the information and a check box (to delete or not delete, that's the question) for each workspace closed by common buttons for delete marked and abort.

  18. starball5 commented on Mar 7, 2023

    @starball5
  19. karl-lunarg commented on Mar 15, 2023

    @karl-lunarg

    Jochen Paul (@ThirtySomething) There's already an extension that does what you want. (https://marketplace.visualstudio.com/items?itemName=mehyaa.workspace-storage-cleanup) It puts up a list of all the workspaces and provides toggles that select/deselect workspaces based on whether or not they point to non-existent files. There's also a separate toggle for remote workspaces because the check for non-existent files doesn't work the same way. And you can select workspaces manually for deletion.
    I just installed and ran it and it worked great!

    Edit: I missed that starball5 mentioned the same extension. Sorry for the duplication.

  20. ThirtySomething commented on Mar 16, 2023

    @ThirtySomething

    starball (@starball5) and also Karl Schultz (@karl-lunarg) thanks for hinting this extension. Didn't know that and haven't found this while I was searching for a solution to this problem. Does exactly what I've planned for my own extension. Great!

  21. d-damien commented on Oct 18, 2023

    @d-damien

    Cache cleaning tools should be available as CLI since bloated caches can sometimes prevent starting the GUI.

  22. anibalsanchez commented on Jan 22, 2024

    @anibalsanchez

    After restoring a full backup, I realized that the vscode extensions folder consumes 5.6GB. How can it be optimized? Why is it storing all old versions?

  23. cspence001 commented on May 22, 2024

    @cspence001

    FYI, under linux (and I suppose would work in OSX too) I'm cleaning up the workspace folders pointing non-existing locations with this inline script:

    for i in ~/.config/Code/User/workspaceStorage/*; do if [ -f $i/workspace.json ]; then folder="$(python3 -c "import sys, json; print(json.load(open(sys.argv[1], 'r'))['folder'])" $i/workspace.json 2>/dev/null | sed 's#^file://##;s/+/ /g;s/%\(..\)/\\x\1/g;')"; if [ -n "$folder" ] && [ ! -d "$folder" ]; then echo "Removing workspace $(basename $i) for deleted folder $folder of size $(du -sh $i|cut -f1)"; rm -rfv "$i"; fi; fi; done

    You can find it somewhat more readable in this gist.

    For macOS users replace:
    ~/.config/Code/User/workspaceStorage/*
    with:
    ~/Library/Application\ Support/Code/User/workspaceStorage/*

  24. hinell commented on May 23, 2024

    @hinell

    Haven't been using VS Code for years now and can tell you: the problem went away like a charm! Just drop it boys and switch to a brighter side: Neovim. Cheers.

  25. woj-tek commented on Jan 24, 2025

    @woj-tek

    I just found out that my workspaceStorage takes 6G... honestly, even "bloated IDEA" uses less space… why this hasn't been resolved yet?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-requestworkbench-state

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions