|
| 1 | +/*! |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import { AuthUtil } from 'aws-core-vscode/codewhisperer' |
| 7 | +import { Commands, globals } from 'aws-core-vscode/shared' |
| 8 | +import vscode from 'vscode' |
| 9 | + |
| 10 | +/** |
| 11 | + * The purpose of this module is to provide a util to clear all extension cache so that it has a clean state |
| 12 | + */ |
| 13 | + |
| 14 | +/** |
| 15 | + * Clears "all" cache of the extension, effectively putting the user in a "net new" state. |
| 16 | + * |
| 17 | + * NOTE: This is a best attempt. There may be state like a file in the filesystem which is not deleted. |
| 18 | + * We should aim to add all state clearing in to this method. |
| 19 | + */ |
| 20 | +async function clearCache() { |
| 21 | + // Check a final time if they want to clear their cache |
| 22 | + const doContinue = await vscode.window |
| 23 | + .showInformationMessage( |
| 24 | + 'This will wipe your Amazon Q extension state, then reload your VS Code window. This operation is not dangerous. ', |
| 25 | + { modal: true }, |
| 26 | + 'Continue' |
| 27 | + ) |
| 28 | + .then((value) => { |
| 29 | + return value === 'Continue' |
| 30 | + }) |
| 31 | + if (!doContinue) { |
| 32 | + return |
| 33 | + } |
| 34 | + |
| 35 | + // SSO cache persists on disk, this should indirectly delete it |
| 36 | + const conn = AuthUtil.instance.conn |
| 37 | + if (conn) { |
| 38 | + await AuthUtil.instance.auth.deleteConnection(conn) |
| 39 | + } |
| 40 | + |
| 41 | + await globals.globalState.clear() |
| 42 | + |
| 43 | + // Make the IDE reload so all new changes take effect |
| 44 | + void vscode.commands.executeCommand('workbench.action.reloadWindow') |
| 45 | +} |
| 46 | +export const clearCacheDeclaration = Commands.declare({ id: 'aws.amazonq.clearCache' }, () => clearCache) |
0 commit comments