|
1 |
| -import { ConfigurationTarget } from 'vscode'; |
| 1 | +import type { MessageItem } from 'vscode'; |
| 2 | +import { ConfigurationTarget, window } from 'vscode'; |
2 | 3 | import { resetAvatarCache } from '../avatars';
|
3 | 4 | import { Commands } from '../constants';
|
4 | 5 | import type { Container } from '../container';
|
| 6 | +import type { QuickPickItemOfT } from '../quickpicks/items/common'; |
| 7 | +import { createQuickPickSeparator } from '../quickpicks/items/common'; |
5 | 8 | import { command } from '../system/command';
|
6 | 9 | import { configuration } from '../system/configuration';
|
7 | 10 | import { Command } from './base';
|
8 | 11 |
|
| 12 | +const resetTypes = [ |
| 13 | + 'ai', |
| 14 | + 'avatars', |
| 15 | + 'integrations', |
| 16 | + 'plus', |
| 17 | + 'repositoryAccess', |
| 18 | + 'suppressedWarnings', |
| 19 | + 'usageTracking', |
| 20 | + 'workspace', |
| 21 | +] as const; |
| 22 | +type ResetType = 'all' | (typeof resetTypes)[number]; |
| 23 | + |
9 | 24 | @command()
|
10 |
| -export class ResetAIKeyCommand extends Command { |
| 25 | +export class ResetCommand extends Command { |
11 | 26 | constructor(private readonly container: Container) {
|
12 |
| - super(Commands.ResetAIKey); |
| 27 | + super(Commands.Reset); |
13 | 28 | }
|
14 |
| - |
15 | 29 | async execute() {
|
16 |
| - await (await this.container.ai)?.reset(); |
17 |
| - } |
18 |
| -} |
| 30 | + type ResetQuickPickItem = QuickPickItemOfT<ResetType>; |
19 | 31 |
|
20 |
| -@command() |
21 |
| -export class ResetAvatarCacheCommand extends Command { |
22 |
| - constructor(private readonly container: Container) { |
23 |
| - super(Commands.ResetAvatarCache); |
24 |
| - } |
| 32 | + const items: ResetQuickPickItem[] = [ |
| 33 | + { |
| 34 | + label: 'AI Keys...', |
| 35 | + detail: 'Clears any locally stored AI keys', |
| 36 | + item: 'ai', |
| 37 | + }, |
| 38 | + { |
| 39 | + label: 'Avatars...', |
| 40 | + detail: 'Clears the stored avatar cache', |
| 41 | + item: 'avatars', |
| 42 | + }, |
| 43 | + { |
| 44 | + label: 'Integrations (Authentication)...', |
| 45 | + detail: 'Clears any locally stored authentication for integrations', |
| 46 | + item: 'integrations', |
| 47 | + }, |
| 48 | + { |
| 49 | + label: 'Repository Access...', |
| 50 | + detail: 'Clears the stored repository access cache', |
| 51 | + item: 'repositoryAccess', |
| 52 | + }, |
| 53 | + { |
| 54 | + label: 'Suppressed Warnings...', |
| 55 | + detail: 'Clears any suppressed warnings, e.g. messages with "Don\'t Show Again" options', |
| 56 | + item: 'suppressedWarnings', |
| 57 | + }, |
| 58 | + { |
| 59 | + label: 'Usage Tracking...', |
| 60 | + detail: 'Clears any locally tracked usage, typically used for first time experience', |
| 61 | + item: 'usageTracking', |
| 62 | + }, |
| 63 | + { |
| 64 | + label: 'Workspace Storage...', |
| 65 | + detail: 'Clears stored data associated with the current workspace', |
| 66 | + item: 'workspace', |
| 67 | + }, |
| 68 | + createQuickPickSeparator(), |
| 69 | + { |
| 70 | + label: 'Everything...', |
| 71 | + description: ' — \u00a0be very careful with this!', |
| 72 | + detail: 'Clears ALL locally stored data; ALL GitLens state will be LOST', |
| 73 | + item: 'all', |
| 74 | + }, |
| 75 | + ]; |
25 | 76 |
|
26 |
| - execute() { |
27 |
| - resetAvatarCache('all'); |
28 |
| - } |
29 |
| -} |
| 77 | + if (this.container.debugging) { |
| 78 | + items.splice( |
| 79 | + 0, |
| 80 | + 0, |
| 81 | + { |
| 82 | + label: 'Subscription Reset', |
| 83 | + detail: 'Resets the stored subscription', |
| 84 | + item: 'plus', |
| 85 | + }, |
| 86 | + createQuickPickSeparator(), |
| 87 | + ); |
| 88 | + } |
30 | 89 |
|
31 |
| -@command() |
32 |
| -export class ResetSuppressedWarningsCommand extends Command { |
33 |
| - constructor(private readonly container: Container) { |
34 |
| - super(Commands.ResetSuppressedWarnings); |
| 90 | + // create a quick pick with options to clear all the different resets that GitLens supports |
| 91 | + const pick = await window.showQuickPick<ResetQuickPickItem>(items, { |
| 92 | + title: 'Reset Stored Data', |
| 93 | + placeHolder: 'Choose which data to reset, will be prompted to confirm', |
| 94 | + }); |
| 95 | + |
| 96 | + if (pick?.item == null) return; |
| 97 | + if (pick.item === 'plus' && !this.container.debugging) return; |
| 98 | + |
| 99 | + const confirm: MessageItem = { title: 'Reset' }; |
| 100 | + const cancel: MessageItem = { title: 'Cancel', isCloseAffordance: true }; |
| 101 | + |
| 102 | + let confirmationMessage: string | undefined; |
| 103 | + switch (pick?.item) { |
| 104 | + case 'all': |
| 105 | + confirmationMessage = 'Are you sure you want to reset EVERYTHING?'; |
| 106 | + confirm.title = 'Reset Everything'; |
| 107 | + break; |
| 108 | + case 'ai': |
| 109 | + confirmationMessage = 'Are you sure you want to reset all of the stored AI keys?'; |
| 110 | + confirm.title = 'Reset AI Keys'; |
| 111 | + break; |
| 112 | + case 'avatars': |
| 113 | + confirmationMessage = 'Are you sure you want to reset the avatar cache?'; |
| 114 | + confirm.title = 'Reset Avatars'; |
| 115 | + break; |
| 116 | + case 'integrations': |
| 117 | + confirmationMessage = 'Are you sure you want to reset all of the stored integrations?'; |
| 118 | + confirm.title = 'Reset Integrations'; |
| 119 | + break; |
| 120 | + case 'repositoryAccess': |
| 121 | + confirmationMessage = 'Are you sure you want to reset the repository access cache?'; |
| 122 | + confirm.title = 'Reset Repository Access'; |
| 123 | + break; |
| 124 | + case 'suppressedWarnings': |
| 125 | + confirmationMessage = 'Are you sure you want to reset all of the suppressed warnings?'; |
| 126 | + confirm.title = 'Reset Suppressed Warnings'; |
| 127 | + break; |
| 128 | + case 'usageTracking': |
| 129 | + confirmationMessage = 'Are you sure you want to reset all of the usage tracking?'; |
| 130 | + confirm.title = 'Reset Usage Tracking'; |
| 131 | + break; |
| 132 | + case 'workspace': |
| 133 | + confirmationMessage = 'Are you sure you want to reset the stored data for the current workspace?'; |
| 134 | + confirm.title = 'Reset Workspace Storage'; |
| 135 | + break; |
| 136 | + } |
| 137 | + |
| 138 | + if (confirmationMessage != null) { |
| 139 | + const result = await window.showWarningMessage( |
| 140 | + `This is IRREVERSIBLE!\n${confirmationMessage}`, |
| 141 | + { modal: true }, |
| 142 | + confirm, |
| 143 | + cancel, |
| 144 | + ); |
| 145 | + if (result !== confirm) return; |
| 146 | + } |
| 147 | + |
| 148 | + await this.reset(pick.item); |
35 | 149 | }
|
36 | 150 |
|
37 |
| - async execute() { |
38 |
| - await configuration.update('advanced.messages', undefined, ConfigurationTarget.Global); |
| 151 | + private async reset(reset: ResetType) { |
| 152 | + switch (reset) { |
| 153 | + case 'all': |
| 154 | + for (const r of resetTypes) { |
| 155 | + await this.reset(r); |
| 156 | + } |
| 157 | + |
| 158 | + await this.container.storage.reset(); |
| 159 | + break; |
| 160 | + |
| 161 | + case 'ai': |
| 162 | + await (await this.container.ai)?.reset(true); |
| 163 | + break; |
| 164 | + |
| 165 | + case 'avatars': |
| 166 | + resetAvatarCache('all'); |
| 167 | + break; |
| 168 | + |
| 169 | + case 'integrations': |
| 170 | + await this.container.integrations.reset(); |
| 171 | + break; |
| 172 | + |
| 173 | + case 'plus': |
| 174 | + await this.container.subscription.logout(true, undefined); |
| 175 | + break; |
| 176 | + |
| 177 | + case 'repositoryAccess': |
| 178 | + await this.container.git.clearAllRepoVisibilityCaches(); |
| 179 | + break; |
| 180 | + |
| 181 | + case 'suppressedWarnings': |
| 182 | + await configuration.update('advanced.messages', undefined, ConfigurationTarget.Global); |
| 183 | + break; |
| 184 | + |
| 185 | + case 'usageTracking': |
| 186 | + await this.container.usage.reset(); |
| 187 | + break; |
| 188 | + |
| 189 | + case 'workspace': |
| 190 | + await this.container.storage.resetWorkspace(); |
| 191 | + break; |
| 192 | + } |
39 | 193 | }
|
40 | 194 | }
|
41 | 195 |
|
42 | 196 | @command()
|
43 |
| -export class ResetTrackedUsageCommand extends Command { |
| 197 | +export class ResetAIKeyCommand extends Command { |
44 | 198 | constructor(private readonly container: Container) {
|
45 |
| - super(Commands.ResetTrackedUsage); |
| 199 | + super(Commands.ResetAIKey); |
46 | 200 | }
|
47 | 201 |
|
48 | 202 | async execute() {
|
49 |
| - await this.container.usage.reset(); |
| 203 | + await (await this.container.ai)?.reset(); |
50 | 204 | }
|
51 | 205 | }
|
0 commit comments