删除掉remote-container.ts中的调试语句

This commit is contained in:
2025-12-05 14:11:46 +08:00
parent b33ca163a1
commit 2f4d2cb27a

View File

@@ -252,11 +252,6 @@ export default class RemoteContainer {
*/
private async createSSHPortForward(hostname: string, sshPort: number, containerPort: number, localPort: number): Promise<void> {
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<void> {
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}`);
}
}