Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
17481 general preference objects (#866)
Browse files Browse the repository at this point in the history
* Interpret preference strings as JSON values

Signed-off-by: Thomas Mäder <tmader@redhat.com>
  • Loading branch information
tsmaeder authored Oct 1, 2020
1 parent dc99f19 commit a305797
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,21 @@ export class PreferencesProvider implements FrontendApplicationContribution {

private async setPluginProperties(props: [string, string][]): Promise<void> {
await this.workspaceService.roots;
const workspace = this.workspaceService.workspace;
if (!workspace) {
throw new Error('Failed to get Theia workspace.');
}
for (const [key, value] of props) {
if (this.preferenceService.has(key, workspace.resource.toString())) {
continue;

try {
this.setPreferenceValue(key, JSON.parse(value));
} catch (error) {
console.warn('could not parse value for preference key %s, using string value: %o', key, error);
this.setPreferenceValue(key, value);
}
await this.preferenceService.set(key, value, PreferenceScope.Workspace, workspace.resource.toString());
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private async setPreferenceValue(key: string, value: any): Promise<void> {
if (!this.preferenceService.has(key)) {
await this.preferenceService.set(key, value, PreferenceScope.Workspace);
}
}

Expand Down

0 comments on commit a305797

Please sign in to comment.