Skip to content

Revisit code-workspace format - #33097

Merged
Benjamin Pasero (bpasero) merged 17 commits into
masterfrom
ben/mrformat
Aug 25, 2017
Merged

Benjamin Pasero (bpasero) merged 17 commits into
masterfrom
ben/mrformat

Conversation

@bpasero

@bpasero Benjamin Pasero (bpasero) commented Aug 24, 2017 •

Copy link
Copy Markdown
Contributor

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:

  • we no longer have a workspace ID in the file
  • we make the root folders a real object so that additional meta data can be added and we simplify the property to path and just allow absolute and relative paths

Motivations for removing workspace ID:

  • it was odd to have it in the file when you share this file or even when you edit it
  • copying the workspace file you were not able to open the workspace in a separate window

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:

  • UI state
  • hot exit data (this just means that dirty files will open in an empty window - no data loss)
  • extension storage

@Tyriar

Copy link
Copy Markdown
Contributor

we make the root folders a real object so that additional meta data can be added

Any ideas on the type of metadata you want to store?

copying the workspace file you were not able to open the workspace in a separate window

Maybe this could be resolved in a different way to give us the best of both worlds?

  • Store the state using the ID from the code-workspace but allow opening based on ID+workspace path?
  • If the a code-workspace ID is being opened that is already opened but from a different path, change the ID of the new code-workspace and resume as that means it was copied, not moved?

@bpasero

Copy link
Copy Markdown
Contributor Author

Daniel Imms (@Tyriar)

Any ideas on the type of metadata you want to store?

Yeah, one request was to assign a name to a root in case multiple root folders have the same name.

Maybe this could be resolved in a different way to give us the best of both worlds?

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?

@Tyriar

Copy link
Copy Markdown
Contributor

The only downside is that renaming or moving the workspace file means to loose the following workspace ID associated things

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:

  • Move the workspace file around freely while still retaining workspace state, because we still have an ID
  • Copy the workspace file, as the ID conflict would be resolved when both are opened at once

@bpasero

Copy link
Copy Markdown
Contributor Author

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)

image

Atom/Sublime: no workspace ID within project file

What is associated with the workspace ID?

  • UI state (everything of local storage, e.g. opened editors, visibility of panel, sidebar etc.)
  • Hot-Exit backups (helps us restoring dirty files to the correct workspace on restart)
  • Extension Storage (physical location on disk where extensions can save files)

What would be an alternative?

Use the path of the .code-workspace file on disk as ID

Advantages of Workspace ID

  • Renaming/moving .code-workspace file does not break association with UI state, hot-exit and extension storage

Disadvantage of Workspace ID

  • A user can change the workspace ID by simply editing the ID value within the file
  • You cannot make a copy of a .code-workspace file and use it e.g. for multi-window setup without changing the workspace ID
  • What does the workspace ID in the file mean for sharing this file with other people?
  • We have an action "Save Workspace As..." to copy the workspace file, but should we then also change the ID within? Today we keep it...

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
as ID, we would behave the same when moving/renaming the workspace file

@Tyriar

Copy link
Copy Markdown
Contributor

Sublime: no workspace ID within project 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 🙂

@bpasero

Copy link
Copy Markdown
Contributor Author

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.

@bpasero

Benjamin Pasero (bpasero) commented Aug 24, 2017 •

Copy link
Copy Markdown
Contributor Author

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?

@bpasero

Copy link
Copy Markdown
Contributor Author

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.

@Tyriar

Copy link
Copy Markdown
Contributor

We could also be smarter with the ID we associate for hot exit: e.g. we could also use a hash of the contents of the file and try that as a "secondary id" if the first one does not match?

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()) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sandeep Somavarapu (@sandy081) fyi new format for folders

this.baseConfigurationService = this._register(new GlobalConfigurationService(environmentService));
}

saveWorkspace(location: URI): TPromise<void> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:///'
{

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'] || [];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bpasero

Copy link
Copy Markdown
Contributor Author

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:

  • maybe the ctime of the file/folder? have to check if it is preserved somehow
  • a hash over the folders of the workspace
  • some other metadata that we could maybe associate with the file (file metadata?)

Anyway it looks like we can merge this in given your approval 👍

@sandy081

Copy link
Copy Markdown
Member

LGTM

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

Labels

workbench-multiroot Multi-root (multiple folders) issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants