Repository navigation
Revisit code-workspace format - #33097
Conversation
Any ideas on the type of metadata you want to store?
Maybe this could be resolved in a different way to give us the best of both worlds?
|
Yeah, one request was to assign a
How would that work though, how do we know that another workspace already exists with the same ID? It could be in local storage, it could be in hot-exit it could have extension storage. I am trying to say that the workspace might not be open in any window. If I understand you correctly, you want to keep the ID inside the file? |
This was the whole reason for the ID and it would be good to keep if we can. Couldn't the main process before opening the window check what workspace IDs are open in other windows? If this situation is detected, that a workspace file has been copied, at that point we "fork" the workspace by regenerating a new ID for the newly opened workspace. If I'm thinking this through correctly we would then be able to:
|
|
Daniel Imms (@Tyriar) to be clear, I am not thinking that we should remove the ID only because of the limitation of opening the same workspace ID in multiple windows, I agree that this one can probably be tackled independently. Here is a more verbose list: Today VS Code: workspace ID property within workspace file is just a number (timestamp + random) Atom/Sublime: no workspace ID within project file What is associated with the workspace ID?
What would be an alternative? Use the path of the .code-workspace file on disk as ID Advantages of Workspace ID
Disadvantage of Workspace ID
Notes Renaming a folder today means loosing all associated UI state, hot-exit data and extension storage. if we would use the path of the workspace file |
This is the case as they have a .sublime-workspace file as a sibling to the project instead of storing it behind the scenes like us. I think you can freely move the project around (with the workspace) and still retain state just fine. I do like the simplicity of leaving the ID out. Potentially losing hot exit state is my main concern though as that could very well result in an unintentional loss of data for the user. If you have other ideas on how to tackle that it would help alleviate my concerns 🙂 |
|
Daniel Imms (@Tyriar) I would not necessarily say that sublimes concept of a workspace file is good either. You suddenly get a second file next to your project file and when you move or rename the project file, you still loose all your UI state (you have to keep both in sync to keep the UI state). I find that model not nice either. As for hot-exit: yeah it is not so nice, however I do not think you would ever loose data because we always open an empty window with the dirty files for you. Same happens in ST, not surprisingly. |
|
One thing we could always do is instead of opening an empty window with the dirty files, just open them in the instance that gets opened by the user. If the user moved the workspace file and then opens it, the dirty files would restore properly. We could also be smarter with the ID we associate for hot exit: e.g. we could use a hash of the contents of the workspace file and try that as a "secondary id" if the first one does not match? |
|
Not to forget that we have the same issue today already if you rename or move a folder with associated hot-exit. We have #26533 for that. |
Similar to my idea of setting a new ID, as long as falling back to this secondary id will not conflict with the original one after copying and pasting a code-workspace (since the contents will be identical but we want them to be different). |
| } | ||
|
|
||
| private migrateConfiguration(toWorkspaceId: IWorkspaceIdentifier): TPromise<void> { | ||
| if (!this.contextService.hasFolderWorkspace()) { |
There was a problem hiding this comment.
Sandeep Somavarapu (@sandy081) fyi I changed this code to only run when we are in a folder workspace. The reason for that is that with the format changes I will run the migration not only when going from 1 folder to a workspace but also when saving a workspace to another location on disk.
There was a problem hiding this comment.
Benjamin Pasero (@bpasero) Code looks like migration does not run only when we are in folder workspace?
| // Apply to config | ||
| if (newWorkspaceRoots.length) { | ||
| return this.jsonEditingService.write(workspace.configuration, { key: 'folders', value: newWorkspaceRoots }, true); | ||
| const value: IStoredWorkspaceFolder[] = newWorkspaceRoots.map(newWorkspaceRoot => ({ uri: newWorkspaceRoot })); |
There was a problem hiding this comment.
Sandeep Somavarapu (@sandy081) fyi new format for folders
| this.baseConfigurationService = this._register(new GlobalConfigurationService(environmentService)); | ||
| } | ||
|
|
||
| saveWorkspace(location: URI): TPromise<void> { |
There was a problem hiding this comment.
Sandeep Somavarapu (@sandy081) fyi saveWorkspace is no longer possible from the renderer but always has to go to the main side because the ID changes and we need to reopen the workspace from the saved location
| private onWorkspaceChange(configPath: URI): TPromise<void> { | ||
| let workspaceName = this.workspace.name; | ||
| this.workspaceConfigPath = configPath; | ||
| // TODO@Sandeep use again once we can change workspace without window reload |
There was a problem hiding this comment.
Sandeep Somavarapu (@sandy081) fyi I commented out this code because we no longer have a workspace-change without window reload. I left the code in however because once we can support a workspace change without window reload, this could be used again possibly.
| id: 'SOME_UNIQUE_ID', | ||
| folders: [ | ||
| 'file:///' | ||
| { |
There was a problem hiding this comment.
Sandeep Somavarapu (@sandy081) fyi new workspace format JSON schema
| private parseFolders(): URI[] { | ||
| const folders: string[] = this._raw['folders'] || []; | ||
| return distinct(folders.map(folder => URI.parse(folder)) | ||
| const folders: IStoredWorkspaceFolder[] = this._raw['folders'] || []; |
There was a problem hiding this comment.
Sandeep Somavarapu (@sandy081) fyi new workspace format
| if (isWorkspaceIdentifier(workspace) && !this.contextService.hasMultiFolderWorkspace()) { | ||
| // We are transitioning into a workspace from an empty workspace or workspace, and | ||
| // as such we want to migrate UI state from the current workspace to the new one. | ||
| if (isWorkspaceIdentifier(workspace)) { |
There was a problem hiding this comment.
Sandeep Somavarapu (@sandy081) fyi the migration will now also run when going from one workspace to another, we need this to support a smooth transition when saving a workspace.
|
Daniel Imms (@Tyriar) there must be a better way of correlating hot-exit data with a workspace or folder. I still like the idea of having a secondary ID that can be used as fallback. This would work at least in those cases where a user renames a folder or workspace and then opens it with VS Code (it would not work if you would simply restart). A secondary ID could be:
Anyway it looks like we can merge this in given your approval 👍 |
|
LGTM |

Refs: #32946
Would like to modify the contents of the code-workspace file.
Today:
{ "id": "1500007676869", "folders": [ "file:///Users/bpasero/Development/Microsoft/monaco", "file:///Users/bpasero/Development/Microsoft/vscode-distro", "file:///Users/bpasero/Development/Microsoft/vscode-docs", "file:///Users/bpasero/Development/Microsoft/vscode-extension-sdk" ] }Proposed:
{ "folders": [ { "path": "/Users/bpasero/Development/Microsoft/monaco" }, { "path": "/Users/bpasero/Development/Microsoft/vscode-distro" }, { "path": "/Users/bpasero/Development/Microsoft/vscode-docs" }, { "path": "/Users/bpasero/Development/Microsoft/vscode-extension-sdk " } ] }There are two changes involved:
pathand just allow absolute and relative pathsMotivations for removing workspace ID:
Idea is to use the path of the workspace file as ID for the workspace. The only downside is that renaming or moving the workspace file means to loose the following workspace ID associated things: