Skip to content

Commit d5e2eea

Browse files
committed
Consolidates resets into a single menu
Adds ability to reset more stored data
1 parent 08467d2 commit d5e2eea

File tree

10 files changed

+273
-103
lines changed

10 files changed

+273
-103
lines changed

package.json

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5467,6 +5467,11 @@
54675467
"title": "Generate Commit Message (GitLens)...",
54685468
"category": "GitLens"
54695469
},
5470+
{
5471+
"command": "gitlens.reset",
5472+
"title": "Reset Stored Data...",
5473+
"category": "GitLens"
5474+
},
54705475
{
54715476
"command": "gitlens.resetAIKey",
54725477
"title": "Reset Stored AI Keys...",
@@ -5522,16 +5527,6 @@
55225527
"title": "Restore Pro Features",
55235528
"category": "GitLens"
55245529
},
5525-
{
5526-
"command": "gitlens.plus.reset",
5527-
"title": "Reset",
5528-
"category": "GitLens"
5529-
},
5530-
{
5531-
"command": "gitlens.plus.resetRepositoryAccess",
5532-
"title": "Reset Repository Access Cache",
5533-
"category": "GitLens"
5534-
},
55355530
{
55365531
"command": "gitlens.plus.refreshRepositoryAccess",
55375532
"title": "Refresh Repository Access",
@@ -6766,21 +6761,6 @@
67666761
"title": "Open All Changes (difftool)",
67676762
"category": "GitLens"
67686763
},
6769-
{
6770-
"command": "gitlens.resetAvatarCache",
6771-
"title": "Reset Avatar Cache",
6772-
"category": "GitLens"
6773-
},
6774-
{
6775-
"command": "gitlens.resetSuppressedWarnings",
6776-
"title": "Reset Suppressed Warnings",
6777-
"category": "GitLens"
6778-
},
6779-
{
6780-
"command": "gitlens.resetTrackedUsage",
6781-
"title": "Reset Tracked Usage",
6782-
"category": "GitLens"
6783-
},
67846764
{
67856765
"command": "gitlens.inviteToLiveShare",
67866766
"title": "Invite to Live Share",
@@ -9581,14 +9561,6 @@
95819561
"command": "gitlens.plus.restore",
95829562
"when": "!config.gitlens.plusFeatures.enabled"
95839563
},
9584-
{
9585-
"command": "gitlens.plus.reset",
9586-
"when": "gitlens:debugging"
9587-
},
9588-
{
9589-
"command": "gitlens.plus.resetRepositoryAccess",
9590-
"when": "gitlens:enabled"
9591-
},
95929564
{
95939565
"command": "gitlens.plus.refreshRepositoryAccess",
95949566
"when": "gitlens:enabled"
@@ -10453,18 +10425,6 @@
1045310425
"command": "gitlens.stashSaveFiles",
1045410426
"when": "false"
1045510427
},
10456-
{
10457-
"command": "gitlens.resetAvatarCache",
10458-
"when": "gitlens:enabled"
10459-
},
10460-
{
10461-
"command": "gitlens.resetSuppressedWarnings",
10462-
"when": "gitlens:enabled"
10463-
},
10464-
{
10465-
"command": "gitlens.resetTrackedUsage",
10466-
"when": "gitlens:enabled"
10467-
},
1046810428
{
1046910429
"command": "gitlens.inviteToLiveShare",
1047010430
"when": "false"

src/ai/aiProviderService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export class AIProviderService implements Disposable {
355355
});
356356
}
357357

358-
async reset() {
358+
async reset(all?: boolean) {
359359
let { _provider: provider } = this;
360360
if (provider == null) {
361361
// If we have no provider, try to get the current model (which will load the provider)
@@ -368,7 +368,9 @@ export class AIProviderService implements Disposable {
368368
const cancel: MessageItem = { title: 'Cancel', isCloseAffordance: true };
369369

370370
let result;
371-
if (provider == null) {
371+
if (all) {
372+
result = resetAll;
373+
} else if (provider == null) {
372374
result = await window.showInformationMessage(
373375
`Do you want to reset all of the stored AI keys?`,
374376
{ modal: true },

src/commands/resets.ts

Lines changed: 179 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,205 @@
1-
import { ConfigurationTarget } from 'vscode';
1+
import type { MessageItem } from 'vscode';
2+
import { ConfigurationTarget, window } from 'vscode';
23
import { resetAvatarCache } from '../avatars';
34
import { Commands } from '../constants';
45
import type { Container } from '../container';
6+
import type { QuickPickItemOfT } from '../quickpicks/items/common';
7+
import { createQuickPickSeparator } from '../quickpicks/items/common';
58
import { command } from '../system/command';
69
import { configuration } from '../system/configuration';
710
import { Command } from './base';
811

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+
924
@command()
10-
export class ResetAIKeyCommand extends Command {
25+
export class ResetCommand extends Command {
1126
constructor(private readonly container: Container) {
12-
super(Commands.ResetAIKey);
27+
super(Commands.Reset);
1328
}
14-
1529
async execute() {
16-
await (await this.container.ai)?.reset();
17-
}
18-
}
30+
type ResetQuickPickItem = QuickPickItemOfT<ResetType>;
1931

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+
];
2576

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+
}
3089

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);
35149
}
36150

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+
}
39193
}
40194
}
41195

42196
@command()
43-
export class ResetTrackedUsageCommand extends Command {
197+
export class ResetAIKeyCommand extends Command {
44198
constructor(private readonly container: Container) {
45-
super(Commands.ResetTrackedUsage);
199+
super(Commands.ResetAIKey);
46200
}
47201

48202
async execute() {
49-
await this.container.usage.reset();
203+
await (await this.container.ai)?.reset();
50204
}
51205
}

src/constants.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,8 @@ export const enum Commands {
294294
RefreshLaunchpad = 'gitlens.launchpad.refresh',
295295
RefreshGraph = 'gitlens.graph.refresh',
296296
RefreshHover = 'gitlens.refreshHover',
297-
ResetAvatarCache = 'gitlens.resetAvatarCache',
297+
Reset = 'gitlens.reset',
298298
ResetAIKey = 'gitlens.resetAIKey',
299-
ResetSuppressedWarnings = 'gitlens.resetSuppressedWarnings',
300-
ResetTrackedUsage = 'gitlens.resetTrackedUsage',
301299
ResetViewsLayout = 'gitlens.resetViewsLayout',
302300
RevealCommitInView = 'gitlens.revealCommitInView',
303301
ShareAsCloudPatch = 'gitlens.shareAsCloudPatch',

0 commit comments

Comments
 (0)