fix: use VSCode Extension API for remote SSH connection to support Trae IDE
All checks were successful
CI/CD Pipeline for DevStar Extension / build (pull_request) Successful in 6m31s

This commit is contained in:
2025-12-30 22:00:23 +08:00
parent 629a9b4bf7
commit 6cdf60ced1

View File

@@ -350,9 +350,9 @@ export default class RemoteContainer {
}
/**
* local env
* local env - 使用 Extension API 打开远程文件夹
*/
async openRemoteFolder(host: string, port: number, _username: string, path: string, context: vscode.ExtensionContext, cmd: string = 'code'): Promise<void> {
async openRemoteFolder(host: string, port: number, _username: string, path: string, context: vscode.ExtensionContext, _cmd: string = 'code'): Promise<void> {
try {
const sshConfig = await this.getSSHConfig(host);
if (sshConfig) {
@@ -365,12 +365,18 @@ export default class RemoteContainer {
}
}
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
terminal.show(true);
// 使用 VSCode Extension API 打开远程连接
// 使用 SSH config 中的 Host 别名,让 SSH config 的用户配置生效
// 格式: vscode-remote://ssh-remote+host/path
// 注意:不在 URI 中指定用户名,让 SSH config 中的 User root 配置生效
const remoteUri = vscode.Uri.parse(
`vscode-remote://ssh-remote+${host}${path}`
);
const command = `${cmd} --remote ssh-remote+root@${host}:${port} ${path} --reuse-window`;
terminal.sendText(command);
// 尝试使用 vscode.openFolder 命令
await vscode.commands.executeCommand('vscode.openFolder', remoteUri, {
forceNewWindow: false
});
} catch (error) {
const errorMessage = error instanceof Error ? error.message : '未知错误';
@@ -459,15 +465,22 @@ export default class RemoteContainer {
}
/**
* 打开项目(无须插件登录)
* 打开项目(无须插件登录)- 使用 Extension API
*/
export async function openProjectWithoutLogging(hostname: string, port: number, username: string, path: string, cmd: string = 'code'): Promise<void> {
const command = `${cmd} --remote ssh-remote+${username}@${hostname}:${port} ${path} --reuse-window`;
export async function openProjectWithoutLogging(host: string, _port: number, _username: string, path: string, _cmd: string = 'code'): Promise<void> {
try {
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
terminal.show(true);
terminal.sendText(command);
// 使用 VSCode Extension API 打开远程连接
// 使用 SSH config 中的 Host 别名,让 SSH config 的用户配置生效
// 格式: vscode-remote://ssh-remote+host/path
const remoteUri = vscode.Uri.parse(
`vscode-remote://ssh-remote+${host}${path}`
);
// 使用 vscode.openFolder 命令
await vscode.commands.executeCommand('vscode.openFolder', remoteUri, {
forceNewWindow: false
});
} catch (error) {
const errorMessage = error instanceof Error ? error.message : '未知错误';
vscode.window.showErrorMessage(`无登录打开项目失败: ${errorMessage}`);