Skip to content

Commit

Permalink
fix(vscode): Get git remote for explain code. (TabbyML#2254)
Browse files Browse the repository at this point in the history
* fix(vscode): Get git remote for explain code.

* fix: fix filepath when git url provided.
  • Loading branch information
icycodes authored May 28, 2024
1 parent 867e50a commit 3f83d44
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions clients/vscode/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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 {
Expand Down

0 comments on commit 3f83d44

Please sign in to comment.