feature-open-with-vscode #4
@@ -252,6 +252,11 @@ 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',
|
||||
@@ -266,13 +271,21 @@ export default class RemoteContainer {
|
||||
const sshProcess = spawn('ssh', sshArgs);
|
||||
|
||||
sshProcess.on('error', (error: Error) => {
|
||||
console.error(`[ERROR] SSH 进程启动失败:`, error);
|
||||
reject(error);
|
||||
});
|
||||
|
||||
sshProcess.stdout.on('data', (_data: Buffer) => {
|
||||
sshProcess.stdout.on('data', (data: Buffer) => {
|
||||
console.log(`[SSH stdout] ${data.toString()}`);
|
||||
});
|
||||
|
||||
sshProcess.stderr.on('data', (_data: Buffer) => {
|
||||
sshProcess.stderr.on('data', (data: Buffer) => {
|
||||
console.error(`[SSH stderr] ${data.toString()}`);
|
||||
});
|
||||
|
||||
// 监听进程退出
|
||||
sshProcess.on('exit', (code: number) => {
|
||||
console.log(`[DEBUG] SSH 进程退出,代码: ${code}`);
|
||||
});
|
||||
|
||||
if (!this.sshProcesses) {
|
||||
@@ -282,6 +295,7 @@ export default class RemoteContainer {
|
||||
this.sshProcesses.set(key, sshProcess);
|
||||
|
||||
setTimeout(() => {
|
||||
console.log(`[DEBUG] 端口映射完成: ${containerPort} -> ${localPort}`);
|
||||
resolve();
|
||||
}, 2000);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user