| 26 | const requiredSettings = require("./settings.jsonc"); |
| 27 | |
| 28 | export async function configSettings() { |
| 29 | // Remove legacy settings |
| 30 | for (const [legacyKey, legacyValue] of Object.entries(legacySettings)) { |
| 31 | const sections = legacyKey.split("."); |
| 32 | const sectionName = sections.pop()!; |
| 33 | const configName = sections.join("."); |
| 34 | |
| 35 | const config = workspace.getConfiguration(configName); |
| 36 | const configValue = config.inspect(sectionName)?.globalValue; |
| 37 | |
| 38 | let updatedValue: any = undefined; // Default to remove the legacy key |
| 39 | if (Array.isArray(legacyValue) && Array.isArray(configValue)) { |
| 40 | updatedValue = [...configValue]; |
| 41 | for (const item of legacyValue) { |
| 42 | remove(updatedValue, (i) => isEqual(i, item)); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | await config.update( |
| 47 | sectionName, |
| 48 | updatedValue, |
| 49 | ConfigurationTarget.Global |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | // Update the required settings |
| 54 | for (const [requiredKey, requiredValue] of Object.entries( |
| 55 | requiredSettings |
| 56 | )) { |
| 57 | const sections = requiredKey.split("."); |
| 58 | const sectionName = sections.pop()!; |
| 59 | const configName = sections.join("."); |
| 60 | |
| 61 | const config = workspace.getConfiguration(configName); |
| 62 | const configValue = config.inspect(sectionName)?.globalValue; |
| 63 | |
| 64 | let updatedValue: any = requiredValue; |
| 65 | if (Array.isArray(requiredValue) && Array.isArray(configValue)) { |
| 66 | updatedValue = [...configValue]; |
| 67 | for (const item of requiredValue) { |
| 68 | if (!configValue.find((i) => isEqual(i, item))) { |
| 69 | updatedValue.push(item); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | await config.update( |
| 75 | sectionName, |
| 76 | updatedValue, |
| 77 | ConfigurationTarget.Global |
| 78 | ); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | export async function configKeyBindings() { |
| 83 | await commands.executeCommand("workbench.action.openGlobalKeybindingsFile"); |