mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
chore: sync gemini-cli v0.1.19
This commit is contained in:
@@ -8,10 +8,13 @@ import {
|
||||
Config,
|
||||
DetectedIde,
|
||||
IDEConnectionStatus,
|
||||
IdeClient,
|
||||
getIdeDisplayName,
|
||||
getIdeInstaller,
|
||||
IdeClient,
|
||||
type File,
|
||||
ideContext,
|
||||
} from '@qwen-code/qwen-code-core';
|
||||
import path from 'node:path';
|
||||
import {
|
||||
CommandContext,
|
||||
SlashCommand,
|
||||
@@ -49,6 +52,68 @@ 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');
|
||||
|
||||
const infoMessage = `
|
||||
(Note: The file list is limited to a number of recently accessed files within your workspace and only includes local files on disk)`;
|
||||
|
||||
return `\n\nOpen files:\n${fileList}\n${infoMessage}`;
|
||||
}
|
||||
|
||||
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()}`;
|
||||
const context = ideContext.getIdeContext();
|
||||
const openFiles = context?.workspaceState?.openFiles;
|
||||
if (openFiles && openFiles.length > 0) {
|
||||
content += formatFileList(openFiles);
|
||||
}
|
||||
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;
|
||||
@@ -84,8 +149,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,
|
||||
|
||||
Reference in New Issue
Block a user