1 import type { Memento, WorkspaceConfiguration } from "vscode";
2 import { workspace } from "vscode";
4 export enum SettingsKey {
6 envSuffix = "envSuffix",
7 picoSDKPath = "sdkPath",
8 toolchainPath = "toolchainPath",
9 cmakePath = "cmakePath",
10 python3Path = "python3Path",
11 ninjaPath = "ninjaPath",
12 cmakeAutoConfigure = "cmakeAutoConfigure",
15 export type Setting = string | boolean | string[] | null | undefined;
17 export interface PackageJSON {
22 export default class Settings {
23 private config: WorkspaceConfiguration;
24 public context: Memento;
25 private pkg: PackageJSON;
27 constructor(context: Memento, packageJSON: PackageJSON) {
28 this.context = context;
29 this.pkg = packageJSON;
31 this.config = workspace.getConfiguration(packageJSON.name);
34 public get(key: SettingsKey): Setting {
35 return this.config.get(key);
38 public getIt<T>(key: SettingsKey): T | undefined {
39 const value = this.config.get(key);
40 // TODO: typeof value !== T does currently not work in TypeScript
41 // but if it could be a good backend for getString, getBoolean and so on
42 if (value === undefined) {
49 public getString(key: SettingsKey): string | undefined {
50 const value = this.get(key);
52 return typeof value === "string" ? value : undefined;
55 public getBoolean(key: SettingsKey): boolean | undefined {
56 const value = this.get(key);
58 return typeof value === "boolean" ? value : undefined;
61 public getArray(key: SettingsKey): string[] | undefined {
62 const value = this.get(key);
64 return Array.isArray(value) ? value : undefined;
67 public update<T>(key: SettingsKey, value: T): Thenable<void> {
68 return this.config.update(key, value, false);
71 public updateGlobal<T>(key: SettingsKey, value: T): Thenable<void> {
72 return this.config.update(key, value, true);
76 public getExtensionName(): string {
80 public getExtensionId(): string {
81 return [this.pkg.publisher, this.pkg.name].join(".");