diff --git a/src/remote-container.ts b/src/remote-container.ts index 01553ef..f6377a9 100644 --- a/src/remote-container.ts +++ b/src/remote-container.ts @@ -379,13 +379,19 @@ export default class RemoteContainer { } } + // 添加延迟确保 SSH 隧道完全建立 + await new Promise(resolve => setTimeout(resolve, 3000)); + + // 使用 --new-window 而不是 --reuse-window,避免当前窗口被切换 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`; + const command = `code --remote ssh-remote+root@${host}:${port} ${path} --new-window`; terminal.sendText(command); + vscode.window.showInformationMessage('端口映射已在本地窗口建立,新窗口将打开远程环境'); + } catch (error) { const errorMessage = error instanceof Error ? error.message : '未知错误'; vscode.window.showErrorMessage(`打开远程文件夹失败: ${errorMessage}`);