From 2f4d2cb27a7bbf1112745b80c0f163b8da577991 Mon Sep 17 00:00:00 2001 From: yinxue <2643126914@qq.com> Date: Fri, 5 Dec 2025 14:11:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=8E=89remote-container.ts?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E8=B0=83=E8=AF=95=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/remote-container.ts | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/src/remote-container.ts b/src/remote-container.ts index 11de8cf..1357edf 100644 --- a/src/remote-container.ts +++ b/src/remote-container.ts @@ -252,11 +252,6 @@ export default class RemoteContainer { */ private async createSSHPortForward(hostname: string, sshPort: number, containerPort: number, localPort: number): Promise { return new Promise((resolve, reject) => { - // 添加调试信息 - console.log(`[DEBUG] 当前环境: ${vscode.env.remoteName || '本地'}`); - console.log(`[DEBUG] 当前工作目录: ${process.cwd()}`); - console.log(`[DEBUG] SSH 命令: ssh -N -L ${localPort}:localhost:${containerPort} -p ${sshPort} root@${hostname}`); - const sshArgs = [ '-N', '-L', @@ -278,7 +273,6 @@ export default class RemoteContainer { sshProcess.unref(); sshProcess.on('error', (error: Error) => { - console.error(`[ERROR] SSH 进程启动失败:`, error); reject(error); }); @@ -291,23 +285,11 @@ export default class RemoteContainer { // console.error(`[SSH stderr] ${data.toString()}`); // }); - // 监听进程退出(detached 进程可能不会触发此事件) - sshProcess.on('exit', (code: number | null) => { - console.log(`[DEBUG] SSH 进程退出,代码: ${code}`); - }); - // 注意:由于进程已 detached 和 unref,不再需要保存到 sshProcesses Map // 因为我们无法也不需要控制这些独立进程的生命周期 - // if (!this.sshProcesses) { - // this.sshProcesses = new Map(); - // } - // const key = `${hostname}:${sshPort}:${containerPort}`; - // this.sshProcesses.set(key, sshProcess); // 等待 SSH 连接建立 setTimeout(() => { - console.log(`[DEBUG] 端口映射完成: ${containerPort} -> ${localPort} (进程已独立运行)`); - console.log(`[DEBUG] SSH 进程 PID: ${sshProcess.pid}`); resolve(); }, 2000); }); @@ -379,42 +361,28 @@ export default class RemoteContainer { * local env */ async openRemoteFolder(host: string, port: number, _username: string, path: string, context: vscode.ExtensionContext): Promise { - console.log(`[openRemoteFolder] 开始执行`); - console.log(`[openRemoteFolder] 当前环境: ${vscode.env.remoteName || '本地'}`); - console.log(`[openRemoteFolder] 参数: host=${host}, port=${port}, path=${path}`); - try { const sshConfig = await this.getSSHConfig(host); - console.log(`[openRemoteFolder] SSH配置:`, sshConfig); if (sshConfig) { try { - console.log(`[openRemoteFolder] 准备建立端口映射...`); // 调用 setupPortForwardingFromGlobalState 方法 await this.setupPortForwardingFromGlobalState(sshConfig.hostname, port, context); - console.log(`[openRemoteFolder] 端口映射设置完成`); } catch (portError) { - console.error(`[openRemoteFolder] 端口映射失败:`, portError); vscode.window.showWarningMessage('端口映射设置失败,但容器连接已建立'); } - } else { - console.log(`[openRemoteFolder] 未找到SSH配置,跳过端口映射`); } - console.log(`[openRemoteFolder] 准备打开远程文件夹...`); let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`); terminal.show(true); const command = `code --remote ssh-remote+root@${host}:${port} ${path} --reuse-window`; - console.log(`[openRemoteFolder] 执行命令: ${command}`); terminal.sendText(command); - console.log(`[openRemoteFolder] 命令已发送到终端`); } catch (error) { const errorMessage = error instanceof Error ? error.message : '未知错误'; - console.error(`[openRemoteFolder] 发生错误:`, error); vscode.window.showErrorMessage(`打开远程文件夹失败: ${errorMessage}`); } }