refactor(vscode-ide-companion): translate Chinese comments to English

- Translate all Chinese comments in TypeScript files to English for better code readability
- Update documentation comments to be in English
- Maintain code functionality while improving internationalization

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
yiliang114
2025-11-25 23:41:24 +08:00
parent d5ede56e62
commit 3c09ad46ca
15 changed files with 216 additions and 214 deletions

View File

@@ -52,11 +52,11 @@ export class AcpConnection {
private nextRequestId = { value: 0 };
private backend: AcpBackend | null = null;
// 模块实例
// Module instances
private messageHandler: AcpMessageHandler;
private sessionManager: AcpSessionManager;
// 回调函数
// Callback functions
onSessionUpdate: (data: AcpSessionUpdate) => void = () => {};
onPermissionRequest: (data: AcpPermissionRequest) => Promise<{
optionId: string;
@@ -200,7 +200,7 @@ export class AcpConnection {
}
});
// 初始化协议
// Initialize protocol
const res = await this.sessionManager.initialize(
this.child,
this.pendingRequests,
@@ -249,7 +249,7 @@ export class AcpConnection {
}
});
} else {
// 响应
// Response
this.messageHandler.handleMessage(
message,
this.pendingRequests,

View File

@@ -5,29 +5,29 @@
*/
/**
* ACP文件操作处理器
* ACP File Operation Handler
*
* 负责处理ACP协议中的文件读写操作
* Responsible for handling file read and write operations in the ACP protocol
*/
import { promises as fs } from 'fs';
import * as path from 'path';
/**
* ACP文件操作处理器类
* 提供文件读写功能符合ACP协议规范
* ACP File Operation Handler Class
* Provides file read and write functionality according to ACP protocol specifications
*/
export class AcpFileHandler {
/**
* 处理读取文本文件请求
* Handle read text file request
*
* @param params - 文件读取参数
* @param params.path - 文件路径
* @param params.sessionId - 会话ID
* @param params.line - 起始行号(可选)
* @param params.limit - 读取行数限制(可选)
* @returns 文件内容
* @throws 当文件读取失败时抛出错误
* @param params - File read parameters
* @param params.path - File path
* @param params.sessionId - Session ID
* @param params.line - Starting line number (optional)
* @param params.limit - Read line limit (optional)
* @returns File content
* @throws Error when file reading fails
*/
async handleReadTextFile(params: {
path: string;
@@ -48,7 +48,7 @@ export class AcpFileHandler {
`[ACP] Successfully read file: ${params.path} (${content.length} bytes)`,
);
// 处理行偏移和限制
// Handle line offset and limit
if (params.line !== null || params.limit !== null) {
const lines = content.split('\n');
const startLine = params.line || 0;
@@ -71,14 +71,14 @@ export class AcpFileHandler {
}
/**
* 处理写入文本文件请求
* Handle write text file request
*
* @param params - 文件写入参数
* @param params.path - 文件路径
* @param params.content - 文件内容
* @param params.sessionId - 会话ID
* @returns null表示成功
* @throws 当文件写入失败时抛出错误
* @param params - File write parameters
* @param params.path - File path
* @param params.content - File content
* @param params.sessionId - Session ID
* @returns null indicates success
* @throws Error when file writing fails
*/
async handleWriteTextFile(params: {
path: string;
@@ -91,12 +91,12 @@ export class AcpFileHandler {
console.log(`[ACP] Content size: ${params.content.length} bytes`);
try {
// 确保目录存在
// Ensure directory exists
const dirName = path.dirname(params.path);
console.log(`[ACP] Ensuring directory exists: ${dirName}`);
await fs.mkdir(dirName, { recursive: true });
// 写入文件
// Write file
await fs.writeFile(params.path, params.content, 'utf-8');
console.log(`[ACP] Successfully wrote file: ${params.path}`);

View File

@@ -5,9 +5,9 @@
*/
/**
* ACP消息处理器
* ACP Message Handler
*
* 负责处理ACP协议中的消息接收、解析和分发
* Responsible for receiving, parsing, and distributing messages in the ACP protocol
*/
import type {
@@ -27,8 +27,8 @@ import { AcpFileHandler } from './acpFileHandler.js';
import type { ChildProcess } from 'child_process';
/**
* ACP消息处理器类
* 负责消息的接收、解析和处理
* ACP Message Handler Class
* Responsible for receiving, parsing, and processing messages
*/
export class AcpMessageHandler {
private fileHandler: AcpFileHandler;
@@ -38,10 +38,10 @@ export class AcpMessageHandler {
}
/**
* 发送响应消息到子进程
* Send response message to child process
*
* @param child - 子进程实例
* @param response - 响应消息
* @param child - Child process instance
* @param response - Response message
*/
sendResponseMessage(child: ChildProcess | null, response: AcpResponse): void {
if (child?.stdin) {
@@ -52,11 +52,11 @@ export class AcpMessageHandler {
}
/**
* 处理接收到的消息
* Handle received messages
*
* @param message - ACP消息
* @param pendingRequests - 待处理请求映射表
* @param callbacks - 回调函数集合
* @param message - ACP message
* @param pendingRequests - Pending requests map
* @param callbacks - Callback functions collection
*/
handleMessage(
message: AcpMessage,
@@ -65,14 +65,14 @@ export class AcpMessageHandler {
): void {
try {
if ('method' in message) {
// 请求或通知
// Request or notification
this.handleIncomingRequest(message, callbacks).catch(() => {});
} else if (
'id' in message &&
typeof message.id === 'number' &&
pendingRequests.has(message.id)
) {
// 响应
// Response
this.handleResponse(message, pendingRequests, callbacks);
}
} catch (error) {
@@ -81,11 +81,11 @@ export class AcpMessageHandler {
}
/**
* 处理响应消息
* Handle response message
*
* @param message - 响应消息
* @param pendingRequests - 待处理请求映射表
* @param callbacks - 回调函数集合
* @param message - Response message
* @param pendingRequests - Pending requests map
* @param callbacks - Callback functions collection
*/
private handleResponse(
message: AcpMessage,
@@ -138,11 +138,11 @@ export class AcpMessageHandler {
}
/**
* 处理进入的请求
* Handle incoming requests
*
* @param message - 请求或通知消息
* @param callbacks - 回调函数集合
* @returns 请求处理结果
* @param message - Request or notification message
* @param callbacks - Callback functions collection
* @returns Request processing result
*/
async handleIncomingRequest(
message: AcpRequest | AcpNotification,
@@ -190,11 +190,11 @@ export class AcpMessageHandler {
}
/**
* 处理权限请求
* Handle permission requests
*
* @param params - 权限请求参数
* @param callbacks - 回调函数集合
* @returns 权限请求结果
* @param params - Permission request parameters
* @param callbacks - Callback functions collection
* @returns Permission request result
*/
private async handlePermissionRequest(
params: AcpPermissionRequest,
@@ -206,7 +206,7 @@ export class AcpMessageHandler {
const response = await callbacks.onPermissionRequest(params);
const optionId = response.optionId;
// 处理取消、拒绝或允许
// Handle cancel, deny, or allow
let outcome: string;
if (optionId.includes('reject') || optionId === 'cancel') {
outcome = 'rejected';

View File

@@ -5,9 +5,9 @@
*/
/**
* ACP会话管理器
* ACP Session Manager
*
* 负责管理ACP协议的会话操作包括初始化、认证、会话创建和切换等
* Responsible for managing ACP protocol session operations, including initialization, authentication, session creation, and switching
*/
import { JSONRPC_VERSION } from '../shared/acpTypes.js';
@@ -21,22 +21,22 @@ import type { PendingRequest } from './connectionTypes.js';
import type { ChildProcess } from 'child_process';
/**
* ACP会话管理器类
* 提供会话的初始化、认证、创建、加载和切换功能
* ACP Session Manager Class
* Provides session initialization, authentication, creation, loading, and switching functionality
*/
export class AcpSessionManager {
private sessionId: string | null = null;
private isInitialized = false;
/**
* 发送请求到ACP服务器
* Send request to ACP server
*
* @param method - 请求方法名
* @param params - 请求参数
* @param child - 子进程实例
* @param pendingRequests - 待处理请求映射表
* @param nextRequestId - 请求ID计数器
* @returns 请求响应
* @param method - Request method name
* @param params - Request parameters
* @param child - Child process instance
* @param pendingRequests - Pending requests map
* @param nextRequestId - Request ID counter
* @returns Request response
*/
private sendRequest<T = unknown>(
method: string,
@@ -81,10 +81,10 @@ export class AcpSessionManager {
}
/**
* 发送消息到子进程
* Send message to child process
*
* @param message - 请求或通知消息
* @param child - 子进程实例
* @param message - Request or notification message
* @param child - Child process instance
*/
private sendMessage(
message: AcpRequest | AcpNotification,
@@ -98,12 +98,12 @@ export class AcpSessionManager {
}
/**
* 初始化ACP协议连接
* Initialize ACP protocol connection
*
* @param child - 子进程实例
* @param pendingRequests - 待处理请求映射表
* @param nextRequestId - 请求ID计数器
* @returns 初始化响应
* @param child - Child process instance
* @param pendingRequests - Pending requests map
* @param nextRequestId - Request ID counter
* @returns Initialization response
*/
async initialize(
child: ChildProcess | null,
@@ -135,13 +135,13 @@ export class AcpSessionManager {
}
/**
* 进行认证
* Perform authentication
*
* @param methodId - 认证方法ID
* @param child - 子进程实例
* @param pendingRequests - 待处理请求映射表
* @param nextRequestId - 请求ID计数器
* @returns 认证响应
* @param methodId - Authentication method ID
* @param child - Child process instance
* @param pendingRequests - Pending requests map
* @param nextRequestId - Request ID counter
* @returns Authentication response
*/
async authenticate(
methodId: string | undefined,
@@ -168,13 +168,13 @@ export class AcpSessionManager {
}
/**
* 创建新会话
* Create new session
*
* @param cwd - 工作目录
* @param child - 子进程实例
* @param pendingRequests - 待处理请求映射表
* @param nextRequestId - 请求ID计数器
* @returns 新会话响应
* @param cwd - Working directory
* @param child - Child process instance
* @param pendingRequests - Pending requests map
* @param nextRequestId - Request ID counter
* @returns New session response
*/
async newSession(
cwd: string,
@@ -202,14 +202,14 @@ export class AcpSessionManager {
}
/**
* 发送提示消息
* Send prompt message
*
* @param prompt - 提示内容
* @param child - 子进程实例
* @param pendingRequests - 待处理请求映射表
* @param nextRequestId - 请求ID计数器
* @returns 响应
* @throws 当没有活动会话时抛出错误
* @param prompt - Prompt content
* @param child - Child process instance
* @param pendingRequests - Pending requests map
* @param nextRequestId - Request ID counter
* @returns Response
* @throws Error when there is no active session
*/
async sendPrompt(
prompt: string,
@@ -234,13 +234,13 @@ export class AcpSessionManager {
}
/**
* 加载已有会话
* Load existing session
*
* @param sessionId - 会话ID
* @param child - 子进程实例
* @param pendingRequests - 待处理请求映射表
* @param nextRequestId - 请求ID计数器
* @returns 加载响应
* @param sessionId - Session ID
* @param child - Child process instance
* @param pendingRequests - Pending requests map
* @param nextRequestId - Request ID counter
* @returns Load response
*/
async loadSession(
sessionId: string,
@@ -291,12 +291,12 @@ export class AcpSessionManager {
}
/**
* 获取会话列表
* Get session list
*
* @param child - 子进程实例
* @param pendingRequests - 待处理请求映射表
* @param nextRequestId - 请求ID计数器
* @returns 会话列表响应
* @param child - Child process instance
* @param pendingRequests - Pending requests map
* @param nextRequestId - Request ID counter
* @returns Session list response
*/
async listSessions(
child: ChildProcess | null,
@@ -324,11 +324,11 @@ export class AcpSessionManager {
}
/**
* 切换到指定会话
* Switch to specified session
*
* @param sessionId - 会话ID
* @param nextRequestId - 请求ID计数器
* @returns 切换响应
* @param sessionId - Session ID
* @param nextRequestId - Request ID counter
* @returns Switch response
*/
async switchSession(
sessionId: string,
@@ -349,9 +349,9 @@ export class AcpSessionManager {
}
/**
* 取消当前会话的提示生成
* Cancel prompt generation for current session
*
* @param child - 子进程实例
* @param child - Child process instance
*/
async cancelSession(child: ChildProcess | null): Promise<void> {
if (!this.sessionId) {
@@ -376,13 +376,13 @@ export class AcpSessionManager {
}
/**
* 保存当前会话
* Save current session
*
* @param tag - 保存标签
* @param child - 子进程实例
* @param pendingRequests - 待处理请求映射表
* @param nextRequestId - 请求ID计数器
* @returns 保存响应
* @param tag - Save tag
* @param child - Child process instance
* @param pendingRequests - Pending requests map
* @param nextRequestId - Request ID counter
* @returns Save response
*/
async saveSession(
tag: string,
@@ -410,7 +410,7 @@ export class AcpSessionManager {
}
/**
* 重置会话管理器状态
* Reset session manager state
*/
reset(): void {
this.sessionId = null;
@@ -418,14 +418,14 @@ export class AcpSessionManager {
}
/**
* 获取当前会话ID
* Get current session ID
*/
getCurrentSessionId(): string | null {
return this.sessionId;
}
/**
* 检查是否已初始化
* Check if initialized
*/
getIsInitialized(): boolean {
return this.isInitialized;

View File

@@ -5,9 +5,9 @@
*/
/**
* ACP连接类型定义
* ACP Connection Type Definitions
*
* 包含了ACP连接所需的所有类型和接口定义
* Contains all types and interface definitions required for ACP connection
*/
import type { ChildProcess } from 'child_process';
@@ -17,47 +17,47 @@ import type {
} from '../shared/acpTypes.js';
/**
* 待处理的请求信息
* Pending Request Information
*/
export interface PendingRequest<T = unknown> {
/** 成功回调 */
/** Success callback */
resolve: (value: T) => void;
/** 失败回调 */
/** Failure callback */
reject: (error: Error) => void;
/** 超时定时器ID */
/** Timeout timer ID */
timeoutId?: NodeJS.Timeout;
/** 请求方法名 */
/** Request method name */
method: string;
}
/**
* ACP连接回调函数类型
* ACP Connection Callback Function Types
*/
export interface AcpConnectionCallbacks {
/** 会话更新回调 */
/** Session update callback */
onSessionUpdate: (data: AcpSessionUpdate) => void;
/** 权限请求回调 */
/** Permission request callback */
onPermissionRequest: (data: AcpPermissionRequest) => Promise<{
optionId: string;
}>;
/** 回合结束回调 */
/** Turn end callback */
onEndTurn: () => void;
}
/**
* ACP连接状态
* ACP Connection State
*/
export interface AcpConnectionState {
/** 子进程实例 */
/** Child process instance */
child: ChildProcess | null;
/** 待处理的请求映射表 */
/** Pending requests map */
pendingRequests: Map<number, PendingRequest<unknown>>;
/** 下一个请求ID */
/** Next request ID */
nextRequestId: number;
/** 当前会话ID */
/** Current session ID */
sessionId: string | null;
/** 是否已初始化 */
/** Whether initialized */
isInitialized: boolean;
/** 后端类型 */
/** Backend type */
backend: string | null;
}