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
All checks were successful
CI/CD Pipeline for DevStar Extension / build (pull_request) Successful in 6m31s
This commit is contained in:
@@ -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 {
|
try {
|
||||||
const sshConfig = await this.getSSHConfig(host);
|
const sshConfig = await this.getSSHConfig(host);
|
||||||
if (sshConfig) {
|
if (sshConfig) {
|
||||||
@@ -365,12 +365,18 @@ export default class RemoteContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
|
// 使用 VSCode Extension API 打开远程连接
|
||||||
terminal.show(true);
|
// 使用 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`;
|
// 尝试使用 vscode.openFolder 命令
|
||||||
|
await vscode.commands.executeCommand('vscode.openFolder', remoteUri, {
|
||||||
terminal.sendText(command);
|
forceNewWindow: false
|
||||||
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage = error instanceof Error ? error.message : '未知错误';
|
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> {
|
export async function openProjectWithoutLogging(host: string, _port: number, _username: string, path: string, _cmd: string = 'code'): Promise<void> {
|
||||||
const command = `${cmd} --remote ssh-remote+${username}@${hostname}:${port} ${path} --reuse-window`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
|
// 使用 VSCode Extension API 打开远程连接
|
||||||
terminal.show(true);
|
// 使用 SSH config 中的 Host 别名,让 SSH config 的用户配置生效
|
||||||
terminal.sendText(command);
|
// 格式: 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) {
|
} catch (error) {
|
||||||
const errorMessage = error instanceof Error ? error.message : '未知错误';
|
const errorMessage = error instanceof Error ? error.message : '未知错误';
|
||||||
vscode.window.showErrorMessage(`无登录打开项目失败: ${errorMessage}`);
|
vscode.window.showErrorMessage(`无登录打开项目失败: ${errorMessage}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user