|
| 1 | +import * as vscode from 'vscode' |
| 2 | +import { Logger } from '../utils/logger' |
| 3 | + |
| 4 | +const MIGRATION_ID = |
| 5 | + 'presets-to-chat-presets-for-edit-context-migration-20250714' |
| 6 | +const OLD_SETTING_KEY = 'codeWebChat.presets' |
| 7 | +const NEW_SETTING_KEY = 'codeWebChat.chatPresetsForEditContext' |
| 8 | + |
| 9 | +/** |
| 10 | + * Migration to rename presets to chatPresetsForEditContext. |
| 11 | + * This migration runs only once per extension installation. |
| 12 | + */ |
| 13 | +export async function migrate_presets_to_chat_presets_for_edit_context( |
| 14 | + context: vscode.ExtensionContext |
| 15 | +): Promise<void> { |
| 16 | + try { |
| 17 | + if (context.globalState.get(MIGRATION_ID)) { |
| 18 | + return |
| 19 | + } |
| 20 | + |
| 21 | + const config = vscode.workspace.getConfiguration() |
| 22 | + const inspect = config.inspect(OLD_SETTING_KEY) |
| 23 | + |
| 24 | + if (inspect?.globalValue !== undefined) { |
| 25 | + await config.update( |
| 26 | + NEW_SETTING_KEY, |
| 27 | + inspect.globalValue, |
| 28 | + vscode.ConfigurationTarget.Global |
| 29 | + ) |
| 30 | + await config.update( |
| 31 | + OLD_SETTING_KEY, |
| 32 | + undefined, |
| 33 | + vscode.ConfigurationTarget.Global |
| 34 | + ) |
| 35 | + } |
| 36 | + |
| 37 | + if (inspect?.workspaceValue !== undefined) { |
| 38 | + await config.update( |
| 39 | + NEW_SETTING_KEY, |
| 40 | + inspect.workspaceValue, |
| 41 | + vscode.ConfigurationTarget.Workspace |
| 42 | + ) |
| 43 | + await config.update( |
| 44 | + OLD_SETTING_KEY, |
| 45 | + undefined, |
| 46 | + vscode.ConfigurationTarget.Workspace |
| 47 | + ) |
| 48 | + } |
| 49 | + |
| 50 | + await context.globalState.update(MIGRATION_ID, true) |
| 51 | + Logger.log({ |
| 52 | + function_name: 'migrate_presets_to_chat_presets_for_edit_context', |
| 53 | + message: 'Migration for presets to chatPresetsForEditContext completed.' |
| 54 | + }) |
| 55 | + } catch (error) { |
| 56 | + Logger.error({ |
| 57 | + function_name: 'migrate_presets_to_chat_presets_for_edit_context', |
| 58 | + message: 'Error migrating presets to chatPresetsForEditContext', |
| 59 | + data: error instanceof Error ? error.message : String(error) |
| 60 | + }) |
| 61 | + } |
| 62 | +} |
0 commit comments