|
| 1 | +import * as vscode from "vscode" |
| 2 | + |
| 3 | +/** |
| 4 | + * Migrates old subtasks setting to new subtaskCreation and subtaskCompletion settings. |
| 5 | + * |
| 6 | + * TODO: Remove this migration code in September 2025 (6 months after implementation) |
| 7 | + */ |
| 8 | +export async function migrateSubtasksSettings( |
| 9 | + context: vscode.ExtensionContext, |
| 10 | + outputChannel: vscode.OutputChannel, |
| 11 | +): Promise<void> { |
| 12 | + // Old and new setting keys |
| 13 | + const subtasksKey = "alwaysAllowSubtasks" |
| 14 | + const subtaskCreationKey = "alwaysAllowSubtaskCreation" |
| 15 | + const subtaskCompletionKey = "alwaysAllowSubtaskCompletion" |
| 16 | + |
| 17 | + try { |
| 18 | + // Get old value |
| 19 | + const oldValue = await context.globalState.get(subtasksKey) |
| 20 | + console.log(`old subtasks value: ${oldValue}`) |
| 21 | + |
| 22 | + if (oldValue !== undefined && typeof oldValue === "boolean") { |
| 23 | + // Update new settings |
| 24 | + await Promise.all([ |
| 25 | + context.globalState.update(subtaskCreationKey, oldValue), |
| 26 | + context.globalState.update(subtaskCompletionKey, oldValue), |
| 27 | + ]) |
| 28 | + |
| 29 | + const creationValue = await context.globalState.get(subtaskCreationKey) |
| 30 | + const completionValue = await context.globalState.get(subtaskCompletionKey) |
| 31 | + console.log(`new subtask creation value value: ${creationValue}`) |
| 32 | + console.log(`new subtask completion value value: ${completionValue}`) |
| 33 | + |
| 34 | + // Schedule cleanup |
| 35 | + setTimeout(async () => { |
| 36 | + try { |
| 37 | + await context.globalState.update(subtasksKey, undefined) |
| 38 | + outputChannel.appendLine("Migrated subtasks settings") |
| 39 | + } catch (error) { |
| 40 | + outputChannel.appendLine(`Failed to delete old subtasks setting: ${error}`) |
| 41 | + } |
| 42 | + }, 0) |
| 43 | + } |
| 44 | + } catch (error) { |
| 45 | + outputChannel.appendLine(`Migrating subtasks settings failed: ${error}`) |
| 46 | + } |
| 47 | +} |
0 commit comments