Key-value storage for Extensions

Hi,

I stumbled upon this video while looking for a solution to store a few parameters for my extensions:

It led me to VSCode API ExtensionContext which I think has just recently been implemented in Theia:

However I’m not sure how to implement the activate() method in order to get the instance of ExtensionContext.

Could anyone provide me with any pointers?

Thanks!

@vincent you can use the following test plugin as a reference which was used to verify the ExtensionContext pull-request (https://github.com/eclipse-theia/theia/pull/9276):

1 Like

Thank you Vincent.

Forgive my noobness but I’m not used to building VSCode extensions, and the vscode-test-extension repo does not follow the Theia extension generator convention:

export function activate(context: vscode.ExtensionContext) {}

Where would be the correct place to declare that method in a typical Theia extension?

Another question: is the API already available in @theia/core:next?

@vincent @theia extensions cannot use the exported vscode plugin API (they are ultimately completely different concepts).

Oh, sorry for the misunderstanding then. I thought ExtensionContext and PluginContext refered resp. to extensions and plugins in a Theia context :frowning:

In your opinion, what would be a decent way to store a very simple boolean flag used by a Theia extension, that should be persisted across sessions?

In your opinion, what would be a decent way to store a very simple boolean flag used by a Theia extension, that should be persisted across sessions?

Do you want to persist the flag for all workspaces across sessions, or for a given workspace?

The framework currently uses local-storage to store values, but this is per workspace.
Alternatively, you can use IndexedDB, or even store the value as a preference (which is persisted on the filesystem).

It depends on your use-case :slight_smile:

1 Like

I think LocalStorageService could do just fine. I’ll try that. Thank you!