Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable switching workspace storage in web #252

Merged

Conversation

CompuIves
Copy link
Collaborator

This is a more... controversial PR. In CodeSandbox I want to add the ability to seamless switch between workspaces, without refreshing. To enable this, I need to call switch on the StorageService, but workspace switching was never implemented for the web storage service! I implemented it in VSCode, and I verified that this works really well, but I also realise that this will make upgrades in the future harder.

The first approach I tried was copying all the code from the existing storage service in our code base, and making the changes there, but not enough services/utilities are exposed to do this. I'm happy to discuss other approaches.

@CompuIves CompuIves force-pushed the feat/enable-workspace-storage-switch branch 2 times, most recently from d2f71dc to 02d493a Compare November 18, 2023 14:22
@CompuIves
Copy link
Collaborator Author

Perhaps I could even try opening a PR to VSCode to support this 😂

@CompuIves
Copy link
Collaborator Author

Let's see 😇

microsoft/vscode#198594

@CGNonofr
Copy link
Contributor

How do you use it in your code?

@CompuIves
Copy link
Collaborator Author

Whenever a user switch between a project, we don't reload the window. That's because we allow people to already type in the editor, and in the background we create the new project and then apply those changes. Purely UX reasoning.

We do want the new workspace storage to apply to the new project though, so whenever the project changes, we do this:

  runWithLatestMonacoConfig(async (config) => {
    return config.pitcher.onInstanceChanged(({ instanceId }) => {
      const workspaceIdentifier = monacoConfigToWorkspaceIdentifier(
        config,
        instanceId,
      );

      const storageService = StandaloneServices.get(IStorageService);
      storageService.switch(workspaceIdentifier, true).then(() => {
        reinitializeWorkspace(workspaceIdentifier);
      });
    });
  });

@CGNonofr
Copy link
Contributor

Whenever a user switch between a project, we don't reload the window. That's because we allow people to already type in the editor, and in the background we create the new project and then apply those changes. Purely UX reasoning.

We do want the new workspace storage to apply to the new project though, so whenever the project changes, we do this:

  runWithLatestMonacoConfig(async (config) => {
    return config.pitcher.onInstanceChanged(({ instanceId }) => {
      const workspaceIdentifier = monacoConfigToWorkspaceIdentifier(
        config,
        instanceId,
      );

      const storageService = StandaloneServices.get(IStorageService);
      storageService.switch(workspaceIdentifier, true).then(() => {
        reinitializeWorkspace(workspaceIdentifier);
      });
    });
  });

How do you update the workspace in the workspace/configuration service?

@CGNonofr
Copy link
Contributor

In the meantime, instead of changing the vscode impl, what about extending it into a SwitchableBrowserStorageService?

@CompuIves
Copy link
Collaborator Author

In the meantime, instead of changing the vscode impl, what about extending it into a SwitchableBrowserStorageService?

So I would extend the original BrowserStorageService and expose that? I think that's what I tried initially, but I need to change some fields of the class it's extending from, and that's not possible.

How do you update the workspace in the workspace/configuration service?

That's what reinitializeWorkspace does, or at least I was assuming that this would do this as it removes the current workspace directory and adds a new one in its place.

@CGNonofr
Copy link
Contributor

Ok it seems harmless anyway, please resolve the conflicts and let's merge it!

We really need a better way to handle that vscode patch though, separating each change with an explanation. I'm not sure that's the best solution...

@CompuIves CompuIves force-pushed the feat/enable-workspace-storage-switch branch from 02d493a to 021a73c Compare November 24, 2023 09:54
@CompuIves CompuIves force-pushed the feat/enable-workspace-storage-switch branch from 021a73c to 320e92d Compare November 24, 2023 09:54
@CompuIves
Copy link
Collaborator Author

We really need a better way to handle that vscode patch though, separating each change with an explanation. I'm not sure that's the best solution...

Yeah, I was thinking about this as well. Maybe we can do something like this? I love that they say per patch why the patch is there.

@CompuIves
Copy link
Collaborator Author

Rebased!

@CGNonofr
Copy link
Contributor

We really need a better way to handle that vscode patch though, separating each change with an explanation. I'm not sure that's the best solution...

Yeah, I was thinking about this as well. Maybe we can do something like this? I love that they say per patch why the patch is there.

How do they manage it?

@CGNonofr CGNonofr self-requested a review November 24, 2023 11:33
@CGNonofr CGNonofr merged commit c2e0f81 into CodinGame:main Nov 24, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants