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: add overridable storage service #154

Merged

Conversation

nihonium-cfx
Copy link

@nihonium-cfx nihonium-cfx commented Jul 27, 2023

A followup for #153 (comment)

With this new override one can provide monaco with data for it's storage service, which is, among others, responsible for storing cached theme data. This allows for monaco to restore theme colors without flickering through default theme first, if you supply the storage data it asked you store before, of course.

Example usage:

// The settings.json file needs to be written ASAP
registerServiceInitializeParticipant(async (accessor) => {
  // import { writeFile } from 'vscode/monaco'
  await writeFile(URI.from({ schema: 'user', path: '/settings.json' }), `
  {
    "workbench.colorTheme": "Monokai",
  }
  `);
});

await initialize({
  ...getStorageServiceOverride({
    read(scope) {
      try {
        const data = JSON.parse(localStorage[`__STORAGE__${scope}__`]);

        return new Map(data);
      } catch (e) {
        return new Map();
      }
    },
    async write(scope, data) {
      localStorage[`__STORAGE__${scope}__`] = JSON.stringify(Array.from(data));
    }
  }),
});

@CGNonofr CGNonofr self-requested a review August 4, 2023 08:54
@nihonium-cfx nihonium-cfx force-pushed the feat/storage-service-override branch 2 times, most recently from 3784f37 to 529e3c0 Compare August 4, 2023 13:08
@nihonium-cfx
Copy link
Author

I think it's better to address init sequence concerns in another PR

src/service-override/storage.ts Outdated Show resolved Hide resolved
src/service-override/storage.ts Outdated Show resolved Hide resolved
@CGNonofr CGNonofr merged commit 925933d into CodinGame:main Aug 8, 2023
1 check passed
@nihonium-cfx nihonium-cfx deleted the feat/storage-service-override branch August 8, 2023 08:28
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