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

Commit

Permalink
Interpret preference strings as JSON values
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Mäder <tmader@redhat.com>
  • Loading branch information
tsmaeder committed Sep 24, 2020
1 parent dae92d1 commit 017f72c
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,20 @@ 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.uri)) {
continue;
try {
this.setPreferenceValue(key, JSON.parse(value));
} catch (error) {
console.warn('could not parse value for prefernece key %s, using string value: %o', key, error);
this.setPreferenceValue(key, value);
}
await this.preferenceService.set(key, value, PreferenceScope.Workspace, workspace.uri);
}
}

// 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 017f72c

Please sign in to comment.