feat :rephrasing the extension logging messages to run the explore command when there are no extensions installed (#13740)

This commit is contained in:
JAYADITYA
2025-11-24 21:24:15 +05:30
committed by GitHub
parent 7350399a50
commit 569c6f1dd0
2 changed files with 87 additions and 6 deletions

View File

@@ -134,6 +134,21 @@ describe('extensionsCommand', () => {
expect.any(Number),
);
});
it('should show a message if no extensions are installed', async () => {
mockGetExtensions.mockReturnValue([]);
const command = extensionsCommand();
if (!command.action) throw new Error('Action not defined');
await command.action(mockContext, '');
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
{
type: MessageType.INFO,
text: 'No extensions installed. Run `/extensions explore` to check out the gallery.',
},
expect.any(Number),
);
});
});
describe('completeExtensions', () => {
@@ -216,6 +231,19 @@ describe('extensionsCommand', () => {
);
});
it('should show a message if no extensions are installed', async () => {
mockGetExtensions.mockReturnValue([]);
await updateAction(mockContext, 'ext-one');
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
{
type: MessageType.INFO,
text: 'No extensions installed. Run `/extensions explore` to check out the gallery.',
},
expect.any(Number),
);
});
it('should inform user if there are no extensions to update with --all', async () => {
mockDispatchExtensionState.mockImplementationOnce(
(action: ExtensionUpdateAction) => {
@@ -607,6 +635,25 @@ describe('extensionsCommand', () => {
mockContext.invocation!.name = 'restart';
});
it('should show a message if no extensions are installed', async () => {
mockContext.services.config!.getExtensionLoader = vi
.fn()
.mockImplementation(() => ({
getExtensions: () => [],
restartExtension: mockRestartExtension,
}));
await restartAction!(mockContext, '--all');
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
{
type: MessageType.INFO,
text: 'No extensions installed. Run `/extensions explore` to check out the gallery.',
},
expect.any(Number),
);
});
it('restarts all active extensions when --all is provided', async () => {
const mockExtensions = [
{ name: 'ext1', isActive: true },

View File

@@ -24,12 +24,35 @@ import { ExtensionManager } from '../../config/extension-manager.js';
import { SettingScope } from '../../config/settings.js';
import { theme } from '../semantic-colors.js';
function showMessageIfNoExtensions(
context: CommandContext,
extensions: unknown[],
): boolean {
if (extensions.length === 0) {
context.ui.addItem(
{
type: MessageType.INFO,
text: 'No extensions installed. Run `/extensions explore` to check out the gallery.',
},
Date.now(),
);
return true;
}
return false;
}
async function listAction(context: CommandContext) {
const extensions = context.services.config
? listExtensions(context.services.config)
: [];
if (showMessageIfNoExtensions(context, extensions)) {
return;
}
const historyItem: HistoryItemExtensionsList = {
type: MessageType.EXTENSIONS_LIST,
extensions: context.services.config
? listExtensions(context.services.config)
: [],
extensions,
};
context.ui.addItem(historyItem, Date.now());
@@ -56,11 +79,17 @@ function updateAction(context: CommandContext, args: string): Promise<void> {
(resolve) => (resolveUpdateComplete = resolve),
);
const extensions = context.services.config
? listExtensions(context.services.config)
: [];
if (showMessageIfNoExtensions(context, extensions)) {
return Promise.resolve();
}
const historyItem: HistoryItemExtensionsList = {
type: MessageType.EXTENSIONS_LIST,
extensions: context.services.config
? listExtensions(context.services.config)
: [],
extensions,
};
updateComplete.then((updateInfos) => {
@@ -138,6 +167,11 @@ async function restartAction(
return;
}
const extensions = extensionLoader.getExtensions();
if (showMessageIfNoExtensions(context, extensions)) {
return;
}
const restartArgs = args.split(' ').filter((value) => value.length > 0);
const all = restartArgs.length === 1 && restartArgs[0] === '--all';
const names = all ? null : restartArgs;