Use slash command instead of context drawer to display open files in editor to reduce flickering in the UI (#5858)

This commit is contained in:
Shreya Keshive
2025-08-08 17:26:11 -04:00
committed by GitHub
parent 60bde58f29
commit 344ee29f77
5 changed files with 90 additions and 160 deletions

View File

@@ -11,7 +11,10 @@ import {
getIdeDisplayName,
getIdeInstaller,
IdeClient,
type File,
ideContext,
} from '@google/gemini-cli-core';
import path from 'node:path';
import {
CommandContext,
SlashCommand,
@@ -49,6 +52,70 @@ function getIdeStatusMessage(ideClient: IdeClient): {
}
}
function formatFileList(openFiles: File[]): string {
const basenameCounts = new Map<string, number>();
for (const file of openFiles) {
const basename = path.basename(file.path);
basenameCounts.set(basename, (basenameCounts.get(basename) || 0) + 1);
}
const fileList = openFiles
.map((file: File) => {
const basename = path.basename(file.path);
const isDuplicate = (basenameCounts.get(basename) || 0) > 1;
const parentDir = path.basename(path.dirname(file.path));
const displayName = isDuplicate
? `${basename} (/${parentDir})`
: basename;
return ` - ${displayName}${file.isActive ? ' (active)' : ''}`;
})
.join('\n');
return `\n\nOpen files:\n${fileList}`;
}
async function getIdeStatusMessageWithFiles(ideClient: IdeClient): Promise<{
messageType: 'info' | 'error';
content: string;
}> {
const connection = ideClient.getConnectionStatus();
switch (connection.status) {
case IDEConnectionStatus.Connected: {
let content = `🟢 Connected to ${ideClient.getDetectedIdeDisplayName()}`;
try {
const context = await ideContext.getIdeContext();
const openFiles = context?.workspaceState?.openFiles;
if (openFiles && openFiles.length > 0) {
content += formatFileList(openFiles);
}
} catch (_e) {
// Ignore
}
return {
messageType: 'info',
content,
};
}
case IDEConnectionStatus.Connecting:
return {
messageType: 'info',
content: `🟡 Connecting...`,
};
default: {
let content = `🔴 Disconnected`;
if (connection?.details) {
content += `: ${connection.details}`;
}
return {
messageType: 'error',
content,
};
}
}
}
export const ideCommand = (config: Config | null): SlashCommand | null => {
if (!config || !config.getIdeModeFeature()) {
return null;
@@ -66,8 +133,7 @@ export const ideCommand = (config: Config | null): SlashCommand | null => {
messageType: 'error',
content: `IDE integration is not supported in your current environment. To use this feature, run Gemini CLI in one of these supported IDEs: ${Object.values(
DetectedIde,
)
.map((ide) => getIdeDisplayName(ide))
).map((ide) => getIdeDisplayName(ide))}
.join(', ')}`,
}) as const,
};
@@ -84,8 +150,9 @@ export const ideCommand = (config: Config | null): SlashCommand | null => {
name: 'status',
description: 'check status of IDE integration',
kind: CommandKind.BUILT_IN,
action: (): SlashCommandActionReturn => {
const { messageType, content } = getIdeStatusMessage(ideClient);
action: async (): Promise<SlashCommandActionReturn> => {
const { messageType, content } =
await getIdeStatusMessageWithFiles(ideClient);
return {
type: 'message',
messageType,