coder / code-server

VS Code in the browser
https://coder.com
MIT License
68.56k stars 5.62k forks source link

Ability to load global-state from a file #7011

Closed davidfirst closed 1 month ago

davidfirst commented 1 month ago

What is your suggestion?

Changes like icons order in the activity-bar are saved into "global state". Locally, vscode saves them in a sqlite db at ~/Library/Application\ Support/Code/User/globalStorage/state.vscdb. Code-server seems to save them in the browser IndexedDb into vscode-web-state-db-global. My suggestion it to have a file on the file-system as a starting-point to be able to load the state from there first. (it'd be great to have only this location and never use the browser, but not sure if this is feasible).

Why do you want this feature?

I'm providing my users with a pre-configured vscode instance in the docker container. I can customize the settings, but I can't customize the state. Meaning, I can't for example provide a code-server instance where the Search button is on top of the Explorer button in the activity-bar.

Are there any workarounds to get this functionality today?

I was trying many approaches, e.g. changing the state from an extension, but it seems to be impossible. vscode extension API doesn't provide access to the global-state.

Are you interested in submitting a PR for this?

I wish I could :)

code-asher commented 1 month ago

Thanks for the input! Yeah this would be really great. I think this is a duplicate of https://github.com/coder/code-server/issues/4212 so I will close it, please follow the other issue for updates! Although I think no one is working on it at the moment.

davidfirst commented 1 month ago

@code-asher , thanks for the reference, I understand now the issue better. So yeah, moving from browser storage to the filesystem is not easy, but this one is more about a one-time state load. Only the first time vscode is loaded. If you think about the "profiles" vscode feature, you can export a profile, which also includes the global-state. Then you can import it on another machine and keep the same state. so something similar to this import-profile, but have it done before vscode is fully loaded, so the state is respected. From a quick test I have done, I exported a profile in one code-server instance, made sure the global-state is there. Then, imported to another instance. Sadly, the global-state wasn't imported. I guess this is due to the same issue, which is global-state is saved in the browser storage.

code-asher commented 1 month ago

Ohh I actually did not know there was a profile import/export feature in VS Code. Does it work in Codespaces? Wondering if we can leverage that to report it upstream, because if they have an import feature and it is not including the state when it should, that sounds like a pretty clear bug.

code-asher commented 1 month ago

But, if the ask is to implement a one-time load completely separate from the profiles feature, my instinct is that this is actually more work than #4212, so if the implementation described in that ticket is sufficient we should go with that.

davidfirst commented 1 month ago

I tried again after upgrading code-server to the latest. The profiles feature works well. Same as codespaces. I can export the current profile from one browser, go to another browser, import the profile, apply it, and immediately it changed the icons order according to the original browser. It showed a message to reload to apply the changes, but seems like the state changes were applied immediately without the need to reload.

So we know it's possible to load the global-state from a file. The missing part is how to instruct code-server to load from that file when it starts.