Skip to content

Commit 93cdb0f

Browse files
feat(amazonq): Command to clear extension cache
We need a way to clear globalState since it looks like some users are getting in to a bad corrputed state where things stop working. Uninstall the extension does not clear state, it is intentionally designed that way by vscode, as we don't want to wipe states on extension updates. Solution: This creates a new command "Amazon Q: Clear extension cache" which clears the cache and reloads the window. Signed-off-by: nkomonen-amazon <[email protected]>
1 parent 344bdb6 commit 93cdb0f

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

packages/amazonq/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,11 @@
804804
{
805805
"command": "aws.amazonq.walkthrough.show",
806806
"title": "%AWS.amazonq.welcomeWalkthrough%"
807+
},
808+
{
809+
"command": "aws.amazonq.clearCache",
810+
"title": "%AWS.amazonq.clearCache%",
811+
"category": "%AWS.amazonq.title%"
807812
}
808813
],
809814
"keybindings": [

packages/amazonq/src/commands.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
import * as vscode from 'vscode'
1010
import { Auth } from 'aws-core-vscode/auth'
1111
import { Commands } from 'aws-core-vscode/shared'
12+
import { clearCacheDeclaration } from './util/clearCache'
1213

1314
export function registerCommands(context: vscode.ExtensionContext) {
14-
context.subscriptions.push(Commands.register('_aws.amazonq.auth.autoConnect', Auth.instance.tryAutoConnect))
15+
context.subscriptions.push(
16+
Commands.register('_aws.amazonq.auth.autoConnect', Auth.instance.tryAutoConnect),
17+
clearCacheDeclaration.register()
18+
)
1519
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
await AuthUtil.instance.logout()
37+
38+
await globals.globalState.clear()
39+
40+
// Make the IDE reload so all new changes take effect
41+
void vscode.commands.executeCommand('workbench.action.reloadWindow')
42+
}
43+
export const clearCacheDeclaration = Commands.declare({ id: 'aws.amazonq.clearCache' }, () => clearCache)

packages/core/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@
328328
"AWS.amazonq.title": "Amazon Q",
329329
"AWS.amazonq.chat": "Chat",
330330
"AWS.amazonq.openChat": "Open Chat",
331+
"AWS.amazonq.clearCache": "Clear extension cache",
331332
"AWS.amazonq.context.folders.title": "Folders",
332333
"AWS.amazonq.context.folders.description": "Add all files in a folder to context",
333334
"AWS.amazonq.context.files.title": "Files",

0 commit comments

Comments
 (0)