Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vscode): introduce API to read git repositories in workspace #3593

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion clients/vscode/src/chat/WebviewHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
commands,
Location,
LocationLink,
workspace,
} from "vscode";
import type {
ServerApi,
Expand All @@ -23,6 +24,7 @@ import type {
LookupSymbolHint,
SymbolInfo,
FileLocation,
GitRepository,
} from "tabby-chat-panel";
import { TABBY_CHAT_PANEL_API_VERSION } from "tabby-chat-panel";
import hashObject from "object-hash";
Expand All @@ -33,7 +35,7 @@ import { GitProvider } from "../git/GitProvider";
import { createClient } from "./chatPanel";
import { Client as LspClient } from "../lsp/Client";
import { isBrowser } from "../env";
import { getFileContextFromSelection, showFileContext, openTextDocument } from "./fileContext";
import { getFileContextFromSelection, showFileContext, openTextDocument, buildFilePathParams } from "./fileContext";
import {
localUriToChatPanelFilepath,
chatPanelFilepathToLocalUri,
Expand Down Expand Up @@ -698,6 +700,34 @@ export class WebviewHelper {
return false;
}
},
readWorkspaceGitRepositories: async (): Promise<GitRepository[]> => {
const activeTextEditor = window.activeTextEditor;
const infoList: GitRepository[] = [];
let activeGitUrl: string | undefined;
if (activeTextEditor) {
const pathParams = await buildFilePathParams(activeTextEditor.document.uri, this.gitProvider);
if (pathParams.gitRemoteUrl) {
activeGitUrl = pathParams.gitRemoteUrl;
infoList.push({
url: activeGitUrl,
});
}
}

const workspaceFolder = workspace.workspaceFolders || [];
for (const folder of workspaceFolder) {
const repo = this.gitProvider.getRepository(folder.uri);
if (repo) {
const gitRemoteUrl = this.gitProvider.getDefaultRemoteUrl(repo);
if (gitRemoteUrl && gitRemoteUrl !== activeGitUrl) {
infoList.push({
url: gitRemoteUrl,
});
}
}
}
return infoList;
},
});
}
}
1 change: 1 addition & 0 deletions clients/vscode/src/chat/chatPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function createClient(webview: Webview, api: ClientApiMethods): ServerApi
onKeyboardEvent: api.onKeyboardEvent,
lookupSymbol: api.lookupSymbol,
openInEditor: api.openInEditor,
readWorkspaceGitRepositories: api.readWorkspaceGitRepositories,
},
});
}
Loading