Skip to content

Commit 081bcb5

Browse files
JayadityaGitmboshernitsan
authored andcommitted
feat :rephrasing the extension logging messages to run the explore command when there are no extensions installed (#13740)
1 parent 8a9ca9e commit 081bcb5

File tree

2 files changed

+87
-6
lines changed

2 files changed

+87
-6
lines changed

packages/cli/src/ui/commands/extensionsCommand.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ describe('extensionsCommand', () => {
134134
expect.any(Number),
135135
);
136136
});
137+
138+
it('should show a message if no extensions are installed', async () => {
139+
mockGetExtensions.mockReturnValue([]);
140+
const command = extensionsCommand();
141+
if (!command.action) throw new Error('Action not defined');
142+
await command.action(mockContext, '');
143+
144+
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
145+
{
146+
type: MessageType.INFO,
147+
text: 'No extensions installed. Run `/extensions explore` to check out the gallery.',
148+
},
149+
expect.any(Number),
150+
);
151+
});
137152
});
138153

139154
describe('completeExtensions', () => {
@@ -216,6 +231,19 @@ describe('extensionsCommand', () => {
216231
);
217232
});
218233

234+
it('should show a message if no extensions are installed', async () => {
235+
mockGetExtensions.mockReturnValue([]);
236+
await updateAction(mockContext, 'ext-one');
237+
238+
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
239+
{
240+
type: MessageType.INFO,
241+
text: 'No extensions installed. Run `/extensions explore` to check out the gallery.',
242+
},
243+
expect.any(Number),
244+
);
245+
});
246+
219247
it('should inform user if there are no extensions to update with --all', async () => {
220248
mockDispatchExtensionState.mockImplementationOnce(
221249
(action: ExtensionUpdateAction) => {
@@ -607,6 +635,25 @@ describe('extensionsCommand', () => {
607635
mockContext.invocation!.name = 'restart';
608636
});
609637

638+
it('should show a message if no extensions are installed', async () => {
639+
mockContext.services.config!.getExtensionLoader = vi
640+
.fn()
641+
.mockImplementation(() => ({
642+
getExtensions: () => [],
643+
restartExtension: mockRestartExtension,
644+
}));
645+
646+
await restartAction!(mockContext, '--all');
647+
648+
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
649+
{
650+
type: MessageType.INFO,
651+
text: 'No extensions installed. Run `/extensions explore` to check out the gallery.',
652+
},
653+
expect.any(Number),
654+
);
655+
});
656+
610657
it('restarts all active extensions when --all is provided', async () => {
611658
const mockExtensions = [
612659
{ name: 'ext1', isActive: true },

packages/cli/src/ui/commands/extensionsCommand.ts

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,35 @@ import { ExtensionManager } from '../../config/extension-manager.js';
2424
import { SettingScope } from '../../config/settings.js';
2525
import { theme } from '../semantic-colors.js';
2626

27+
function showMessageIfNoExtensions(
28+
context: CommandContext,
29+
extensions: unknown[],
30+
): boolean {
31+
if (extensions.length === 0) {
32+
context.ui.addItem(
33+
{
34+
type: MessageType.INFO,
35+
text: 'No extensions installed. Run `/extensions explore` to check out the gallery.',
36+
},
37+
Date.now(),
38+
);
39+
return true;
40+
}
41+
return false;
42+
}
43+
2744
async function listAction(context: CommandContext) {
45+
const extensions = context.services.config
46+
? listExtensions(context.services.config)
47+
: [];
48+
49+
if (showMessageIfNoExtensions(context, extensions)) {
50+
return;
51+
}
52+
2853
const historyItem: HistoryItemExtensionsList = {
2954
type: MessageType.EXTENSIONS_LIST,
30-
extensions: context.services.config
31-
? listExtensions(context.services.config)
32-
: [],
55+
extensions,
3356
};
3457

3558
context.ui.addItem(historyItem, Date.now());
@@ -56,11 +79,17 @@ function updateAction(context: CommandContext, args: string): Promise<void> {
5679
(resolve) => (resolveUpdateComplete = resolve),
5780
);
5881

82+
const extensions = context.services.config
83+
? listExtensions(context.services.config)
84+
: [];
85+
86+
if (showMessageIfNoExtensions(context, extensions)) {
87+
return Promise.resolve();
88+
}
89+
5990
const historyItem: HistoryItemExtensionsList = {
6091
type: MessageType.EXTENSIONS_LIST,
61-
extensions: context.services.config
62-
? listExtensions(context.services.config)
63-
: [],
92+
extensions,
6493
};
6594

6695
updateComplete.then((updateInfos) => {
@@ -138,6 +167,11 @@ async function restartAction(
138167
return;
139168
}
140169

170+
const extensions = extensionLoader.getExtensions();
171+
if (showMessageIfNoExtensions(context, extensions)) {
172+
return;
173+
}
174+
141175
const restartArgs = args.split(' ').filter((value) => value.length > 0);
142176
const all = restartArgs.length === 1 && restartArgs[0] === '--all';
143177
const names = all ? null : restartArgs;

0 commit comments

Comments
 (0)