Repository navigation
Description
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:
- Notebook controller affinity Peng Lyu (@rebornix)
- Find history within an editor Peng Lyu (@rebornix)
- Source control commit message history João Moreno (@joaomoreno)
- Pending comments Alex Ross (@alexr00)
- Text search history Andrea Mah (@andreamah)
- Breakpoints roblourens Connor Peet (@connor4312)
- Open editors Benjamin Pasero (@bpasero)
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
roblourens commentedon May 25, 2023
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 startupbpasero commentedon May 26, 2023
You need to listen for
onDidChangeValuebecause 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.
alexr00 commentedon May 26, 2023
Can this be a June item? I will not get to it today.
32 remaining items
joaomoreno commentedon Sep 13, 2023
Joyce Er (@joyceerhl), looked into tackling this for SCM history and need some guidance.
Today, we store SCM history in
StorageScope.APPLICATIONandStorageTarget.MACHINE.StorageScope.APPLICATIONsince 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 differentrepoworkspace.StorageTarget.MACHINEsince 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.WORKSPACEandStorageTarget.USER, I see no other viable storage key than something all-encompassing likescm.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?If that's the case, will those
repositoryRootURIs be properly migrated, when roaming? Note that we get those URIs from source control providers.Thanks for your help!
joyceerhl commentedon Sep 13, 2023
Yes this is all correct João Moreno (@joaomoreno) and the
repositoryRootURIs should be properly migrated as part of the roaming transition.Adopt `StorageScope.WORKSPACE` in comments
Adopt `StorageScope.WORKSPACE` in comments (#193098)
joaomoreno commentedon Sep 15, 2023
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.
debug: adopt external changes (microsoft#190602)