删除掉remote-container.ts中的调试语句
This commit is contained in:
@@ -252,11 +252,6 @@ export default class RemoteContainer {
|
|||||||
*/
|
*/
|
||||||
private async createSSHPortForward(hostname: string, sshPort: number, containerPort: number, localPort: number): Promise<void> {
|
private async createSSHPortForward(hostname: string, sshPort: number, containerPort: number, localPort: number): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
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 = [
|
const sshArgs = [
|
||||||
'-N',
|
'-N',
|
||||||
'-L',
|
'-L',
|
||||||
@@ -278,7 +273,6 @@ export default class RemoteContainer {
|
|||||||
sshProcess.unref();
|
sshProcess.unref();
|
||||||
|
|
||||||
sshProcess.on('error', (error: Error) => {
|
sshProcess.on('error', (error: Error) => {
|
||||||
console.error(`[ERROR] SSH 进程启动失败:`, error);
|
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -291,23 +285,11 @@ export default class RemoteContainer {
|
|||||||
// console.error(`[SSH stderr] ${data.toString()}`);
|
// console.error(`[SSH stderr] ${data.toString()}`);
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// 监听进程退出(detached 进程可能不会触发此事件)
|
|
||||||
sshProcess.on('exit', (code: number | null) => {
|
|
||||||
console.log(`[DEBUG] SSH 进程退出,代码: ${code}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 注意:由于进程已 detached 和 unref,不再需要保存到 sshProcesses Map
|
// 注意:由于进程已 detached 和 unref,不再需要保存到 sshProcesses Map
|
||||||
// 因为我们无法也不需要控制这些独立进程的生命周期
|
// 因为我们无法也不需要控制这些独立进程的生命周期
|
||||||
// if (!this.sshProcesses) {
|
|
||||||
// this.sshProcesses = new Map();
|
|
||||||
// }
|
|
||||||
// const key = `${hostname}:${sshPort}:${containerPort}`;
|
|
||||||
// this.sshProcesses.set(key, sshProcess);
|
|
||||||
|
|
||||||
// 等待 SSH 连接建立
|
// 等待 SSH 连接建立
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log(`[DEBUG] 端口映射完成: ${containerPort} -> ${localPort} (进程已独立运行)`);
|
|
||||||
console.log(`[DEBUG] SSH 进程 PID: ${sshProcess.pid}`);
|
|
||||||
resolve();
|
resolve();
|
||||||
}, 2000);
|
}, 2000);
|
||||||
});
|
});
|
||||||
@@ -379,42 +361,28 @@ export default class RemoteContainer {
|
|||||||
* local env
|
* local env
|
||||||
*/
|
*/
|
||||||
async openRemoteFolder(host: string, port: number, _username: string, path: string, context: vscode.ExtensionContext): Promise<void> {
|
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 {
|
try {
|
||||||
const sshConfig = await this.getSSHConfig(host);
|
const sshConfig = await this.getSSHConfig(host);
|
||||||
console.log(`[openRemoteFolder] SSH配置:`, sshConfig);
|
|
||||||
|
|
||||||
if (sshConfig) {
|
if (sshConfig) {
|
||||||
try {
|
try {
|
||||||
console.log(`[openRemoteFolder] 准备建立端口映射...`);
|
|
||||||
// 调用 setupPortForwardingFromGlobalState 方法
|
// 调用 setupPortForwardingFromGlobalState 方法
|
||||||
await this.setupPortForwardingFromGlobalState(sshConfig.hostname, port, context);
|
await this.setupPortForwardingFromGlobalState(sshConfig.hostname, port, context);
|
||||||
console.log(`[openRemoteFolder] 端口映射设置完成`);
|
|
||||||
|
|
||||||
} catch (portError) {
|
} catch (portError) {
|
||||||
console.error(`[openRemoteFolder] 端口映射失败:`, portError);
|
|
||||||
vscode.window.showWarningMessage('端口映射设置失败,但容器连接已建立');
|
vscode.window.showWarningMessage('端口映射设置失败,但容器连接已建立');
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
console.log(`[openRemoteFolder] 未找到SSH配置,跳过端口映射`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[openRemoteFolder] 准备打开远程文件夹...`);
|
|
||||||
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
|
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
|
||||||
terminal.show(true);
|
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} --reuse-window`;
|
||||||
console.log(`[openRemoteFolder] 执行命令: ${command}`);
|
|
||||||
|
|
||||||
terminal.sendText(command);
|
terminal.sendText(command);
|
||||||
console.log(`[openRemoteFolder] 命令已发送到终端`);
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage = error instanceof Error ? error.message : '未知错误';
|
const errorMessage = error instanceof Error ? error.message : '未知错误';
|
||||||
console.error(`[openRemoteFolder] 发生错误:`, error);
|
|
||||||
vscode.window.showErrorMessage(`打开远程文件夹失败: ${errorMessage}`);
|
vscode.window.showErrorMessage(`打开远程文件夹失败: ${errorMessage}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user