fix: use VSCode Extension API for remote SSH connection to support Trae IDE
Some checks failed
CI/CD Pipeline for DevStar Extension / build (pull_request) Has been cancelled
Some checks failed
CI/CD Pipeline for DevStar Extension / build (pull_request) Has been cancelled
This commit is contained in:
@@ -358,7 +358,7 @@ export default class RemoteContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* local env
|
* local env - 使用 Extension API 打开远程文件夹
|
||||||
*/
|
*/
|
||||||
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> {
|
||||||
try {
|
try {
|
||||||
@@ -374,12 +374,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 = `code --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 : '未知错误';
|
||||||
@@ -468,15 +474,22 @@ export default class RemoteContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打开项目(无须插件登录)
|
* 打开项目(无须插件登录)- 使用 Extension API
|
||||||
*/
|
*/
|
||||||
export async function openProjectWithoutLogging(hostname: string, port: number, username: string, path: string): Promise<void> {
|
export async function openProjectWithoutLogging(host: string, _port: number, _username: string, path: string): Promise<void> {
|
||||||
const command = `code --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