| 153 | |
| 154 | // This is a recursive function which unpacks a WorkspaceConfiguration into our settings. |
| 155 | function getSetting<TSetting>( |
| 156 | key: string | undefined, |
| 157 | value: TSetting, |
| 158 | configuration: vscode.WorkspaceConfiguration, |
| 159 | ): TSetting { |
| 160 | // Base case where we're looking at a primitive type (or our special record). |
| 161 | if (key !== undefined && !(value instanceof PartialSettings)) { |
| 162 | return configuration.get<TSetting>(key, value); |
| 163 | } |
| 164 | |
| 165 | // Otherwise we're looking at one of our interfaces and need to extract. |
| 166 | for (const property in value) { |
| 167 | const subKey = key !== undefined ? `${key}.${property}` : property; |
| 168 | value[property] = getSetting(subKey, value[property], configuration); |
| 169 | } |
| 170 | |
| 171 | return value; |
| 172 | } |
| 173 | |
| 174 | export function getSettings(): Settings { |
| 175 | const configuration: vscode.WorkspaceConfiguration = |