From 3f83d44a6c9b41228b17541eb9de2fc72c6ed429 Mon Sep 17 00:00:00 2001 From: Zhiming Ma Date: Tue, 28 May 2024 10:42:08 +0800 Subject: [PATCH] fix(vscode): Get git remote for explain code. (#2254) * fix(vscode): Get git remote for explain code. * fix: fix filepath when git url provided. --- clients/vscode/src/Commands.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/clients/vscode/src/Commands.ts b/clients/vscode/src/Commands.ts index d44f8ae2edf4..1e98b9cb9449 100644 --- a/clients/vscode/src/Commands.ts +++ b/clients/vscode/src/Commands.ts @@ -221,12 +221,20 @@ export class Commands { const editor = window.activeTextEditor; if (editor) { + const uri = editor.document.uri; const text = editor.document.getText(editor.selection); - const workspaceFolder = workspace.workspaceFolders?.[0]?.uri.fsPath || ""; + const workspaceFolder = workspace.getWorkspaceFolder(uri); + const repo = this.gitProvider.getRepository(uri); + const remoteUrl = repo ? this.gitProvider.getDefaultRemoteUrl(repo) : undefined; + let filePath = uri.toString(); + if (repo) { + filePath = filePath.replace(repo.rootUri.toString(), ""); + } else if (workspaceFolder) { + filePath = filePath.replace(workspaceFolder.uri.toString(), ""); + } commands.executeCommand("tabby.chatView.focus"); - const filePath = editor.document.fileName.replace(workspaceFolder, ""); this.chatViewProvider.sendMessage({ message: "Explain the selected code:", selectContext: { @@ -237,7 +245,7 @@ export class Commands { end: editor.selection.end.line + 1, }, filepath: filePath.startsWith("/") ? filePath.substring(1) : filePath, - git_url: "https://github.com/tabbyML/tabby", // FIXME + git_url: remoteUrl ?? "", }, }); } else {