Skip to content

Adopt StorageScope.WORKSPACE and StorageTarget.USER #183449

Closed

Description

@joyceerhl

We now support transferring additional workspace-specific state beyond uncommitted changes in a Continue Working On transition, e.g. from web to a local clone but for the same repository like microsoft/vscode (ref #179898). This allows us to provide continuity when a user needs to work on the same repo while transitioning across different development environments.

Ask: We generally want to transfer any state that is user-generated and ephemeral, such as user queries and drafted changes. Not all state needs to be transferred, and I've compiled an initial list that could make sense to adopt this for below. If I missed any or if you have any questions, please reach out.

Area owners:

Details: Your component can opt into this by using the IStorageService under the StorageScope.WORKSPACE and StorageTarget.USER combination to store and retrieve state based on onWillSaveState and onDidChangeValue, e.g.

// in environment A e.g. github.dev
this.storageService.onWillSaveState(() => {
    // no need to serialize objects before storing
    const myObj = { resourceUri };
    this.storageService.store('myKey', myObj, StorageScope.WORKSPACE, StorageTarget.USER);
})

// in environment B e.g. desktop clone of repo
this.storageService.onDidChangeValue((v) => {
    if (v.key === 'myKey') {
        const restoredObj = this.storageService.getObject('myKey', StorageScope.WORKSPACE);
        // apply restored state for your component
    }
});

Any URIs in your stored object values that originated in another instance of VS Code but for the same workspace, e.g. vscode-vfs to file, will be automatically converted for you (if a conversion is possible) before onDidChangeValue is emitted.

Note: The key that you use to retrieve your state should not include non-portable data like URI paths or serialized URIs, since keys will not be automatically converted.

If you have any state already in the workspace and the restored state might step on it, as much as possible your component should try to merge that state (e.g. append new history to existing history) without showing the user a confirmation UI, since the goal is to provide a seamless transition. Again please reach out if this is infeasible.

Activity

  1. added
    feature-request
    on May 25, 2023
  2. added this to the May 2023 milestone on May 25, 2023
  3. roblourens commented on May 25, 2023

    @roblourens
    Member

    So in this scenario, environment B might be already open, and that's why we should listen to onDidChangeValue, right? Currently I only read stored data on startup

  4. bpasero commented on May 26, 2023

    @bpasero
    Contributor

    You need to listen for onDidChangeValue because the edit session is applied after the window has opened, possibly after the restored phase. Similar to settings sync, these changes are applied while you are already inside the workbench and thus require the event from being used.

    We had to do this kind of adoption for global state already back when settings sync got introduced.

  5. alexr00 commented on May 26, 2023

    @alexr00
    Member

    Can this be a June item? I will not get to it today.

  6. 32 remaining items

  7. joaomoreno commented on Sep 13, 2023

    @joaomoreno
    Contributor

    Joyce Er (@joyceerhl), looked into tackling this for SCM history and need some guidance.

    Today, we store SCM history in StorageScope.APPLICATION and StorageTarget.MACHINE.

    • We chose StorageScope.APPLICATION since SCM history belongs to a repository, which can appear in multiple workspaces; a repository's history should be preserved even if that repository appears in a different repo workspace.
    • We chose StorageTarget.MACHINE since we store URIs that do not translate well between machines. Until now, that is.

    I believe we have to drop the repo history preserves across workspaces feature under this new model. Is this a fair assumption? I don't mind if so, I suspect most users won't either.

    Also, looking at this from the desired state perspective, and considering that we need to use StorageScope.WORKSPACE and StorageTarget.USER, I see no other viable storage key than something all-encompassing like scm.history, holding one single object with all histories of all repositories within a workspace. If so, would such a schema be reasonable for the stored object?

    type SCMHistory = { repositoryRoot: URI, history: string[] }[];

    If that's the case, will those repositoryRoot URIs be properly migrated, when roaming? Note that we get those URIs from source control providers.

    Thanks for your help!

  8. joyceerhl commented on Sep 13, 2023

    @joyceerhl
    ContributorAuthor

    Yes this is all correct João Moreno (@joaomoreno) and the repositoryRoot URIs should be properly migrated as part of the roaming transition.

  9. removed their assignment
    on Sep 14, 2023
  10. joaomoreno commented on Sep 15, 2023

    @joaomoreno
    Contributor

    SCM commit history done: #193142

    Most work was in figuring out what the storage format would end up being and then writing the migration code.

  11. locked and limited conversation to collaborators on Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-requeston-testplan

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions